AutoDripLite

SP-SCM1006
Error executing template "Designs/Swift/Paragraph/Swift_ProductPrice.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateVariantInfo(VariantInfoViewModelSettings settings, ViewModelPropertyFiller`1 filler, Product product, String variantId, VariantOption variantOption, Lazy`1 productImages, Lazy`1 details, Boolean isLeaf, VariantInfoViewModel parent) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 1664
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.AddVariantInfoToRootTree(VariantInfoViewModelSettings settings, ViewModelPropertyFiller`1 filler, VariantInfoViewModel root, Product product, String variantId, Lazy`1 productImages, Lazy`1 details) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 1646
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(VariantInfoViewModelSettings settings, IEnumerable`1 products, Lazy`1 details) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 838
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass15_1.<BulkCreateView>b__6() in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 123
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.CreateValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_b00c56f50ed4428699530c9c6fee9664.ExecuteAsync()
   at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.DynamicWrapperService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass23_0.<Run>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template) in /_/src/Application/Providers/Dynamicweb.Rendering.Providers.NetCore/Razor/RazorTemplateRenderingProvider.cs:line 68
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template) in C:\Users\frn\source\repos\Dynamicweb10\src\Core\Dynamicweb.Core\Rendering\TemplateRenderingService.cs:line 14
   at Dynamicweb.Rendering.Template.RenderRazorTemplate() in C:\Users\frn\source\repos\Dynamicweb10\src\Core\Dynamicweb.Core\Rendering\Template.cs:line 805

1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> @using Dynamicweb.Ecommerce.ProductCatalog @{ ProductViewModel product = null; if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) { product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; } else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) { var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); if (productList?.Products is object) { product = productList.Products[0]; } } string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); bool anonymousUser = Pageview.User == null; bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; bool productIsDiscontinued = product is object && product.Discontinued; bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; } @if (product is object && !hidePrice && !isDiscontinued) { bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; string priceFontSize = Model.Item.GetRawValueString("PriceSize", "fs-2"); string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); string layout = Model.Item.GetRawValueString("Layout", "horizontal"); string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; textAlign = horizontalAlign == "end" ? "text-end" : textAlign; horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; string order = layout == "horizontal" ? string.Empty : "order-2"; string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); contentPadding = contentPadding == "none" ? "p-0" : contentPadding; contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); string priceMin = ""; string priceMax = ""; string liveInfoClass = ""; string productInfoFeed = ""; bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); if (isLazyLoadingForProductInfoEnabled) { if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) { productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); if (!string.IsNullOrEmpty(productInfoFeed)) { productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; } } liveInfoClass = "js-live-info"; } <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> @if (showInformativePrice && product.PriceInformative.Price != 0) { <div class="opacity-50"> <span>@Translate("RRP") </span> <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> </div> } <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> @if (showPricesWithVat == "false" && !neverShowVat) { if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) { <span itemprop="price" content="" class="d-none"></span> <span class="text-decoration-line-through js-text-decoration-line-through opacity-75 me-3 text-price js-text-price d-none" data-show-if="LiveProductInfo.product.Price.Price != LiveProductInfo.product.PriceBeforeDiscount.Price"></span> } else { string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; <span itemprop="price" content="@product.Price.PriceWithoutVat" class="d-none"></span> if (product.Price.Price != product.PriceBeforeDiscount.Price) { <span class="text-decoration-line-through opacity-75 @order">@beforePrice</span> } } } else { if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) { <span itemprop="price" content="" class="d-none"></span> <span class="text-decoration-line-through js-text-decoration-line-through opacity-75 me-3 text-price js-text-price d-none" data-show-if="LiveProductInfo.product.Price.Price != LiveProductInfo.product.PriceBeforeDiscount.Price"></span> } else { string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; <span itemprop="price" content="@product.Price.Price" class="d-none"></span> if (product.Price.Price != product.PriceBeforeDiscount.Price) { <span class="text-decoration-line-through opacity-75 @order"> <span class="text-price">@beforePrice</span> </span> } } } @if (showPricesWithVat == "false" && !neverShowVat) { if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) { <span class="text-price js-text-price"> <span class="spinner-border" role="status"></span> </span> } else { string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; if (product?.VariantInfo?.VariantInfo != null) { priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; } if (priceMin != priceMax) { price = priceMin + " - " + priceMax; } <span class="@theme @contentPadding"> <span class="text-price">@price</span> </span> } } else { if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) { <span class="text-price js-text-price"> <span class="spinner-border" role="status"></span> </span> } else { string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; if (product?.VariantInfo?.VariantInfo != null) { priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; } if (priceMin != priceMax) { price = priceMin + " - " + priceMax; } <span class="@theme @contentPadding"> <span class="text-price">@price</span> </span> } } @* Stock state for Schema.org, start *@ @{ Uri url = Dynamicweb.Context.Current.Request.Url; } <link itemprop="url" href="@url"> @{ bool IsNeverOutOfStock = product.NeverOutOfstock; } @if (IsNeverOutOfStock) { <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> } else { if (product.StockLevel > 0) { <span itemprop="availability" class="d-none">InStock</span> } else { <span itemprop="availability" class="d-none">OutOfStock</span> } } @* Stock state for Schema.org, stop *@ </div> @if (showPricesWithVat == "false" && !neverShowVat) { if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) { <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> } else { string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; if (product?.VariantInfo?.VariantInfo != null) { priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; } if (priceMin != priceMax) { price = priceMin + " - " + priceMax; } <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> } } </div> } else if (Pageview.IsVisualEditorMode) { <div class="alert alert-dark m-0" role="alert"> <span>@Translate("No products available")</span> </div> }
Error executing template "Designs/Swift/Components/VariantSelector.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateVariantInfo(VariantInfoViewModelSettings settings, ViewModelPropertyFiller`1 filler, Product product, String variantId, VariantOption variantOption, Lazy`1 productImages, Lazy`1 details, Boolean isLeaf, VariantInfoViewModel parent) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 1664
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.AddVariantInfoToRootTree(VariantInfoViewModelSettings settings, ViewModelPropertyFiller`1 filler, VariantInfoViewModel root, Product product, String variantId, Lazy`1 productImages, Lazy`1 details) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 1646
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(VariantInfoViewModelSettings settings, IEnumerable`1 products, Lazy`1 details) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 838
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass15_1.<BulkCreateView>b__6() in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 123
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
--- End of stack trace from previous location ---
   at System.Lazy`1.CreateValue()
   at Dynamicweb.Ecommerce.ProductCatalog.ProductViewModelExtensions.VariantGroups(ProductViewModel productViewModel) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ProductViewModelExtensions.cs:line 56
   at CompiledRazorTemplates.Dynamic.RazorEngine_91351b06d46e492593366db936a7db0b.ExecuteAsync()
   at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.DynamicWrapperService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass23_0.<Run>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template) in /_/src/Application/Providers/Dynamicweb.Rendering.Providers.NetCore/Razor/RazorTemplateRenderingProvider.cs:line 68
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template) in C:\Users\frn\source\repos\Dynamicweb10\src\Core\Dynamicweb.Core\Rendering\TemplateRenderingService.cs:line 14
   at Dynamicweb.Rendering.Template.RenderRazorTemplate() in C:\Users\frn\source\repos\Dynamicweb10\src\Core\Dynamicweb.Core\Rendering\Template.cs:line 805

1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> @using System.Collections.Generic @using System.Linq @using Dynamicweb.Ecommerce.ProductCatalog @using Dynamicweb.Ecommerce.Variants @using Dynamicweb.Frontend @functions { //Find contrast color (white, black) public static string GetContrastColor(string hexString) { System.Drawing.Color bg = System.Drawing.ColorTranslator.FromHtml(hexString); int nThreshold = 105; int bgDelta = Convert.ToInt32((bg.R * 0.299) + (bg.G * 0.587) + (bg.B * 0.114)); string foreColor = (255 - bgDelta < nThreshold) ? "#333" : "#fff"; return foreColor; } public string GetLayoutForVariantGroup(string variantGroupId) { string showVariantGroups = Model.Item?.GetRawValueString("ShowVariantGroupOptions"); var selectedVariantGroupsList = Model.Item?.GetItems("VariantGroups") ?? new List<ItemViewModel>(); bool showAllVariantGroupsDefault = string.IsNullOrEmpty(showVariantGroups) || selectedVariantGroupsList == null || !selectedVariantGroupsList.Any(); string defaultVariantGroupLayout = Model.Item?.GetRawValueString("DefaultVariantGroupLayout"); defaultVariantGroupLayout = !string.IsNullOrEmpty(defaultVariantGroupLayout) ? defaultVariantGroupLayout : "button"; if (showAllVariantGroupsDefault) return defaultVariantGroupLayout; foreach (var selectedVariantGroupListItem in selectedVariantGroupsList) { var variantGroups = selectedVariantGroupListItem.GetList("VariantGroups").GetRawValue().OfType<string>().ToList(); if (variantGroups.Any(s => s.Equals(variantGroupId))) return selectedVariantGroupListItem.GetRawValueString("VariantGroupLayout"); } return defaultVariantGroupLayout; } //Collect all variant images public static Dictionary<string, string> GetVariantImages(List<VariantInfoViewModel> variantInfo, Dictionary<string, string> list) { foreach (var variantGroup in variantInfo) { if (variantGroup.Image?.Value != null && !list.ContainsKey(variantGroup.OptionID)) { list.Add(variantGroup.OptionID, variantGroup.Image.Value); } if (variantGroup.VariantInfo != null) { GetVariantImages(variantGroup.VariantInfo, list); } } return list; } private string GetDefaultOrVariantGroupValue(string variantGroupId, string itemField, string itemFieldDefaultValue, Dictionary<string, string> fieldValueMapping) { if (!string.IsNullOrEmpty(variantGroupId)) { string itemFieldValue = Model.Item?.GetRawValueString(itemField, itemFieldDefaultValue); string itemFieldParameter = GetViewParameterString(itemField); itemFieldValue = string.IsNullOrEmpty(itemFieldValue) && !string.IsNullOrEmpty(itemFieldParameter) ? itemFieldParameter : itemFieldValue; if (fieldValueMapping != null && !string.IsNullOrEmpty(itemFieldValue) && fieldValueMapping.Any()) { itemFieldValue = fieldValueMapping.ContainsKey(itemFieldValue) ? fieldValueMapping[itemFieldValue] : itemFieldValue; } // If no variantGroup (i.e. Visual Editor), return default value if (string.IsNullOrEmpty(variantGroupId)) return itemFieldValue; string showVariantGroups = Model.Item?.GetString("ShowVariantGroupOptions", "all"); var selectedVariantGroupsList = Model.Item?.GetItems("VariantGroups") ?? new List<ItemViewModel>(); // If no exceptions or settings are all the same, return default value if (showVariantGroups == "all" || selectedVariantGroupsList == null || !selectedVariantGroupsList.Any()) return itemFieldValue; // Get specific value for variant group foreach (var selectedVariantGroupListItem in selectedVariantGroupsList) { var variantGroups = selectedVariantGroupListItem.GetList("VariantGroups").GetRawValue().OfType<string>().ToList(); if (!variantGroups.Any(s => s.Equals(variantGroupId))) continue; itemFieldValue = selectedVariantGroupListItem.GetRawValueString(itemField, itemFieldDefaultValue); itemFieldValue = fieldValueMapping.ContainsKey(itemFieldValue) ? fieldValueMapping[itemFieldValue] : itemFieldValue; } return itemFieldValue; } else { return string.Empty; } } private bool GetDefaultOrVariantGroupValue(string variantGroupId, string itemField) { if (!string.IsNullOrEmpty(variantGroupId)) { bool itemFieldValue = Model.Item?.GetBoolean(itemField) ?? false; // If no variantGroup (i.e. Visual Editor), return default value if (string.IsNullOrEmpty(variantGroupId)) return itemFieldValue; string showVariantGroups = Model.Item?.GetString("ShowVariantGroupOptions", "all"); var selectedVariantGroupsList = Model.Item?.GetItems("VariantGroups") ?? new List<ItemViewModel>(); // If no exceptions or settings are all the same, return default value if (showVariantGroups == "all" || selectedVariantGroupsList == null || !selectedVariantGroupsList.Any()) return itemFieldValue; // Get specific value for variant group foreach (var selectedVariantGroupListItem in selectedVariantGroupsList) { var variantGroups = selectedVariantGroupListItem.GetList("VariantGroups").GetRawValue().OfType<string>().ToList(); if (!variantGroups.Any(s => s.Equals(variantGroupId))) continue; itemFieldValue = selectedVariantGroupListItem.GetBoolean(itemField); } return itemFieldValue; } else { return false; } } } @{ ProductViewModel product = null; if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) { product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; } else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) { var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); if (productList?.Products is object) { product = productList.Products[0]; } } } @if ((product is object)) { bool hideGroupHeaders = !string.IsNullOrEmpty(Model?.Item?.GetString("HideGroupHeaders")) ? Model.Item.GetBoolean("HideGroupHeaders") : false; var productVariantGroups = product.VariantGroups(); string itemId = Model?.Item?.SystemName != null ? $"item_{Model.Item.SystemName.ToLower()}" : string.Empty; bool isModalSelector = Model?.Item == null; string target = isModalSelector ? "data-response-target-element=\"DynamicModalContent\"" : string.Empty; string variantSelectorServicePageId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("VariantSelectorServicePage")) ? Dynamicweb.Context.Current.Request.Form.Get("VariantSelectorServicePage") : string.Empty; string formAction = isModalSelector ? $"action=\"/Default.aspx?ID={variantSelectorServicePageId}\"" : string.Empty; string getProductInfo = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form["getproductinfo"]) ? Dynamicweb.Context.Current.Request.Form["getproductinfo"] : string.Empty; if (productVariantGroups.Any() && product?.VariantInfo?.VariantInfo != null) { string[] variantId = product.VariantId.Split('.'); int groupNumber = 1; string baseUrl = $"Default.aspx?ID={GetPageIdByNavigationTag("Shop")}&GroupID={product.PrimaryOrDefaultGroup.Id}&ProductID={product.Id}"; string variantUrl = string.Empty; if (!string.IsNullOrEmpty(product.VariantId) && !isModalSelector) { variantUrl = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl($"Default.aspx?ID={GetPageIdByNavigationTag("Shop")}&GroupID={product.PrimaryOrDefaultGroup.Id}&ProductID={product.Id}&VariantID={product.VariantId}"); } Dictionary<string, string> variantImages = new Dictionary<string, string>(); variantImages = GetVariantImages(product.VariantInfo.VariantInfo, variantImages); <form @formAction class="d-flex flex-column gap-2 js-variant-selector @itemId" @target data-combinations="@string.Join(",", product.VariantCombinations())" data-base-url="@baseUrl" data-friendly-url="@variantUrl"> @if (isModalSelector) { <input type="hidden" name="productId" value="@product.Id"> <input type="hidden" name="variantid" value="@product.VariantId"> <input type="hidden" name="QuantitySelector" value="true"> <input type="hidden" name="VariantSelectorServicePage" value="@variantSelectorServicePageId"> <input type="hidden" name="ViewType" value="ModalContent"> if (GetViewParameter("ButtonLayout") != null) { <input type="hidden" name="ButtonLayout" value="@GetViewParameter("ButtonLayout")"> } if (GetViewParameter("ButtonAspectRatio") != null) { <input type="hidden" name="ButtonAspectRatio" value="@GetViewParameter("ButtonAspectRatio")"> } if (!string.IsNullOrEmpty(getProductInfo)) { <input type="hidden" name="getproductinfo" value="@getProductInfo"> } } @foreach (var variantGroup in productVariantGroups) { VariantGroupViewModel group = variantGroup; string variantGroupLayout = GetLayoutForVariantGroup(variantGroup.Id) ?? "button"; string horizontalAlign = GetDefaultOrVariantGroupValue(variantGroup.Id, "HorizontalAlignment", "", new Dictionary<string, string> { { "center", "justify-content-center" }, { "end", "justify-content-end" } }); string horizontalTextAlign = GetDefaultOrVariantGroupValue(variantGroup.Id, "HorizontalAlignment", "", new Dictionary<string, string> { { "center", "text-center" }, { "end", "text-end" } }); bool showSelectedOptionName = GetDefaultOrVariantGroupValue(variantGroup.Id, "ShowSelectedOptionName"); <div> @if (!hideGroupHeaders) { <h3 class="h6 @horizontalTextAlign"> @group.Name @if (showSelectedOptionName) { string selectedOptionName = group.Options.FirstOrDefault(opt => variantId.Contains(opt.Id))?.Name ?? string.Empty; <span class="fw-light px-1 swift-selected-option-name">@selectedOptionName</span> } </h3> } <div class="d-flex gap-2 @horizontalAlign flex-wrap js-variant-group" data-group-id="@groupNumber"> @if (variantGroupLayout == "button") { foreach (var option in group.Options) { string active = variantId != null && variantId.Contains(option.Id) ? "active" : string.Empty; string buttonId = $"{product.Id}_{option.Id}_{Pageview.CurrentParagraph.ID}"; string contrastColor = string.Empty; string buttonAspectRatio = GetDefaultOrVariantGroupValue(variantGroup.Id, "ButtonAspectRatio", "100%", new Dictionary<string, string> { { "100%", "--bs-aspect-ratio:100%" }, { "56%", "--bs-aspect-ratio:56%" }, { "177%", "--bs-aspect-ratio:177%" }, { "75%", "--bs-aspect-ratio:75%" }, { "133%", "--bs-aspect-ratio:133%" } }); buttonAspectRatio = buttonAspectRatio == string.Empty ? "--bs-aspect-ratio:100%" : buttonAspectRatio; string buttonLayout = GetDefaultOrVariantGroupValue(variantGroup.Id, "ButtonLayout", "rounded-circle", new Dictionary<string, string> { { "round", "rounded-circle" }, { "square", "rounded-0" }, { "square-rounded", "rounded-3" } }); string buttonTextLayout = GetDefaultOrVariantGroupValue(variantGroup.Id, "ButtonTextLayout", "", new Dictionary<string, string> { { "default", "" }, { "square", "rounded-0" }, { "square-rounded", "rounded-3" } }); var displayType = group.DisplayType; displayType = displayType == VariantGroupDisplayType.NothingSelected && !string.IsNullOrEmpty(option.Color) ? VariantGroupDisplayType.VariantColor : displayType; displayType = displayType == VariantGroupDisplayType.NothingSelected && string.IsNullOrEmpty(option.OptionImage.Value) && string.IsNullOrEmpty(option.Color) ? VariantGroupDisplayType.VariantName : displayType; displayType = displayType == VariantGroupDisplayType.NothingSelected && !string.IsNullOrEmpty(option.OptionImage.Value) ? VariantGroupDisplayType.VariantOptionImage : displayType; var btnWidth = displayType == VariantGroupDisplayType.VariantColor || displayType == VariantGroupDisplayType.VariantImage || displayType == VariantGroupDisplayType.VariantOptionImage ? $"style=\"width:64px\"" : string.Empty; var btnClasses = string.Empty; btnClasses = displayType == VariantGroupDisplayType.VariantColor ? $"overflow-hidden colorbox colorbox-auto p-0 border {buttonLayout}" : btnClasses; btnClasses = displayType == VariantGroupDisplayType.VariantImage ? $"overflow-hidden p-0 {buttonLayout}" : btnClasses; btnClasses = displayType == VariantGroupDisplayType.VariantOptionImage ? $"overflow-hidden colorbox colorbox-auto {buttonLayout} p-0" : btnClasses; btnClasses = displayType == VariantGroupDisplayType.VariantName ? $"btn-secondary {buttonTextLayout}" : btnClasses; <button type="button" class="btn @btnClasses d-inline-block variant-option js-variant-option @active" @btnWidth onclick="swift.VariantSelector.OptionClick(event)" data-variant-id="@option.Id" id="@(product.Id)_@(option.Id)_@Pageview.CurrentParagraph.ID"> <div class="@(displayType == VariantGroupDisplayType.VariantName ? string.Empty : "ratio")" style="@(buttonAspectRatio)"> @switch (displayType) { case VariantGroupDisplayType.VariantOptionImage: if (!string.IsNullOrEmpty(option.OptionImage.Value)) { <img style="object-fit:cover;--variantoption-check-color:@(contrastColor)" src="/Admin/Public/GetImage.ashx?image=@(option.OptionImage.Value)&width=64&format=webp"> } else if (!string.IsNullOrEmpty(option.Color)) { <span class="" style="background-color:@(option.Color);--variantoption-check-color:@(contrastColor)"><span class="visually-hidden">@option.Color</span></span> } else { <span class="d-flex align-items-center justify-content-center">@(option.Name)</span> } break; case VariantGroupDisplayType.VariantImage: string variantImage = string.Empty; variantImages.TryGetValue(option.Id, out variantImage); <img class="theme" style="object-fit:contain" src="/Admin/Public/GetImage.ashx?image=@(variantImage)&width=64&format=webp"> break; case VariantGroupDisplayType.VariantColor: contrastColor = GetContrastColor(option.Color); <span class="" style="background-color:@(option.Color);--variantoption-check-color:@(contrastColor)"><span class="visually-hidden">@option.Color</span></span> break; case VariantGroupDisplayType.VariantName: <span class="d-flex align-items-center justify-content-center">@(option.Name)</span> break; } </div> </button> } } else { <select class="form-select" id="VariantDropdown_@variantGroup.Id" aria-label="@variantGroup.Name" onchange="swift.VariantSelector.OptionClick(event)"> @if (string.IsNullOrEmpty(product.VariantId)) { <option value="" class="variant-option js-variant-option" data-variant-id="">@Translate("Nothing selected")</option> } @foreach (var option in variantGroup.Options) { string active = variantId != null && variantId.Contains(option.Id) ? "active" : ""; var selected = variantId != null && variantId.Contains(option.Id) ? "selected" : ""; var value = $"{product.Id}_{option.Id}"; <option value="@(value)" class="variant-option js-variant-option @active" data-variant-id="@option.Id" id="@(value)_@(Pageview.CurrentParagraph.ID)" @selected>@option.Name</option> } </select> } </div> </div> groupNumber++; } </form> <script type="module"> swift.VariantSelector.init(); </script> } else if (Pageview.IsVisualEditorMode) { string horizontalAlign = GetDefaultOrVariantGroupValue("", "HorizontalAlignment", "", new Dictionary<string, string> { { "center", "justify-content-center" }, { "end", "justify-content-end" } }); string horizontalTextAlign = GetDefaultOrVariantGroupValue("", "HorizontalAlignment", "", new Dictionary<string, string> { { "center", "text-center" }, { "end", "text-end" } }); <form class="d-flex flex-column js-variant-selector @itemId" data-combinations="VO1,VO2,VO3,VO4"> <div> @if (!hideGroupHeaders) { <h3 class="h6 @horizontalTextAlign">@Translate("Sizes")</h3> } <div class="mb-3 @horizontalAlign js-variant-group" data-group-id="0"> <button type="button" class="btn btn-secondary d-inline-block mb-2 variant-option js-variant-option" onclick="swift.VariantSelector.OptionClick(event)" data-variant-id="VO1" id="@(product.Id)_VO1_@Pageview.CurrentParagraph.ID">S</button> <button type="button" class="btn btn-secondary d-inline-block mb-2 variant-option js-variant-option" onclick="swift.VariantSelector.OptionClick(event)" data-variant-id="VO2" id="@(product.Id)_VO2_@Pageview.CurrentParagraph.ID">M</button> <button type="button" class="btn btn-secondary d-inline-block mb-2 variant-option js-variant-option" onclick="swift.VariantSelector.OptionClick(event)" data-variant-id="VO3" id="@(product.Id)_VO3_@Pageview.CurrentParagraph.ID">L</button> <button type="button" class="btn btn-secondary d-inline-block mb-2 variant-option js-variant-option" onclick="swift.VariantSelector.OptionClick(event)" data-variant-id="VO4" id="@(product.Id)_VO4_@Pageview.CurrentParagraph.ID">XL</button> </div> </div> </form> <script type="module"> swift.VariantSelector.init(); </script> } } else if (Pageview.IsVisualEditorMode) { <div class="alert alert-dark m-0" role="alert"> <span>@Translate("No products available")</span> </div> }
Error executing template "Designs/Swift/Paragraph/Swift_ProductAddToCart.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateVariantInfo(VariantInfoViewModelSettings settings, ViewModelPropertyFiller`1 filler, Product product, String variantId, VariantOption variantOption, Lazy`1 productImages, Lazy`1 details, Boolean isLeaf, VariantInfoViewModel parent) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 1664
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.AddVariantInfoToRootTree(VariantInfoViewModelSettings settings, ViewModelPropertyFiller`1 filler, VariantInfoViewModel root, Product product, String variantId, Lazy`1 productImages, Lazy`1 details) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 1646
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(VariantInfoViewModelSettings settings, IEnumerable`1 products, Lazy`1 details) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 838
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass15_1.<BulkCreateView>b__6() in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 123
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
--- End of stack trace from previous location ---
   at System.Lazy`1.CreateValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_d1166215278240c9a436b4dfe51efb4a.ExecuteAsync()
   at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.DynamicWrapperService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass23_0.<Run>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template) in /_/src/Application/Providers/Dynamicweb.Rendering.Providers.NetCore/Razor/RazorTemplateRenderingProvider.cs:line 68
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template) in C:\Users\frn\source\repos\Dynamicweb10\src\Core\Dynamicweb.Core\Rendering\TemplateRenderingService.cs:line 14
   at Dynamicweb.Rendering.Template.RenderRazorTemplate() in C:\Users\frn\source\repos\Dynamicweb10\src\Core\Dynamicweb.Core\Rendering\Template.cs:line 805

1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> @using Dynamicweb.Ecommerce.ProductCatalog @using Dynamicweb.Core.Encoders @using System.Globalization @functions { string DoubleToString(double? value) { if (value.HasValue) { return value.Value.ToString(CultureInfo.InvariantCulture); } return null; } } @{ ProductViewModel product = null; if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) { product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; } else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) { var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); if (productList?.Products is object) { product = productList.Products[0]; } } string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); bool anonymousUser = Pageview.User == null; bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); bool hideAddToCart = anonymousUsersLimitations.Contains("cart") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHideAddToCart") && isErpConnectionDown; hideAddToCart = Pageview.IsVisualEditorMode ? false : hideAddToCart; } @if (product is object && !hideAddToCart) { string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); horizontalAlign = horizontalAlign == "center" ? "justify-content-center" : horizontalAlign; horizontalAlign = horizontalAlign == "end" ? "justify-content-end" : horizontalAlign; horizontalAlign = horizontalAlign == "full" ? "" : horizontalAlign; bool favoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; bool quantitySelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowQuantitySelector")) ? Model.Item.GetBoolean("ShowQuantitySelector") : false; bool unitsSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowUnitsSelector")) ? Model.Item.GetBoolean("ShowUnitsSelector") : false; bool hideInventory = !string.IsNullOrEmpty(Model.Item.GetString("HideInventory")) ? Model.Item.GetBoolean("HideInventory") : false; bool hideStockState = !string.IsNullOrEmpty(Model.Item.GetString("HideStockState")) ? Model.Item.GetBoolean("HideStockState") : false; string buttonSize = Model.Item.GetRawValueString("ButtonSize", "regular"); string inputSize = string.Empty; switch (buttonSize) { case "small": inputSize = " input-group-sm"; buttonSize = " btn-sm"; break; case "regular": buttonSize = string.Empty; break; case "large": inputSize = " input-group-lg"; buttonSize = " btn-lg"; break; } string iconPath = "/Files/icons/"; string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); if (!url.Contains("LayoutTemplate")) { url += url.Contains("?") ? "&LayoutTemplate=Swift_MiniCart.cshtml" : "?LayoutTemplate=Swift_MiniCart.cshtml"; } string whenVariantsExist = Model.Item.GetRawValueString("WhenVariantsExist", "hide"); string flexFill = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "flex-fill" : ""; string fullWidth = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "w-100" : ""; string addToCartIcon = Model.Item.GetRawValueString("Icon", iconPath + "shopping-cart.svg"); string addToCartLabel = !addToCartIcon.Contains("_none") ? $"<span class=\"icon-2\">{ReadFile(addToCartIcon)}</span>" : ""; addToCartLabel += !addToCartIcon.Contains("_none") && !Model.Item.GetBoolean("HideButtonText") ? " " : ""; addToCartLabel += !Model.Item.GetBoolean("HideButtonText") ? $"<span class=\"d-none d-md-inline\">{Translate("Add to cart")}</span><span class=\"d-inline d-md-none\">{Translate("Add")}</span>" : ""; bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); bool userHasPendingQuote = Dynamicweb.Ecommerce.Common.Context.Cart != null && Dynamicweb.Ecommerce.Common.Context.Cart.IsQuote; if (product.VariantInfo.VariantInfo == null || whenVariantsExist == "disable") { string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : product.DefaultUnitId; if (string.IsNullOrEmpty(unitId) && product?.UnitOptions != null) { if (product.UnitOptions.FirstOrDefault<UnitOptionViewModel>() != null) { unitId = product.UnitOptions.FirstOrDefault<UnitOptionViewModel>().Id; } } double? stepQty = product.PurchaseQuantityStep > 0 ? product.PurchaseQuantityStep : 1; double? minQty = product.PurchaseMinimumQuantity > 0 ? product.PurchaseMinimumQuantity : 1; double? valueQty = minQty > stepQty ? minQty : stepQty; string disableAddToCart = null; double? maxQty = null; if (product.ProductType == Dynamicweb.Ecommerce.Products.ProductType.Stock && !product.NeverOutOfstock) { disableAddToCart = (product.StockLevel <= 0) || (!product.NeverOutOfstock && isLazyLoadingForProductInfoEnabled) ? "disabled" : disableAddToCart; maxQty = product.StockLevel; } disableAddToCart = whenVariantsExist == "disable" && product.VariantInfo.VariantInfo != null && string.IsNullOrEmpty(product.VariantId) ? "disabled" : disableAddToCart; disableAddToCart = product.Discontinued ? "disabled" : disableAddToCart; if (unitsSelector && product.UnitOptions.Count > 0) { <form method="post" action="/Default.aspx?ID=@(Pageview.Page.ID)&ProductId=@product.Id" id="UnitSelectorForm_@(product.Id)_@(product.VariantId.Replace(".", "_"))_@Model.ID"> <input type="hidden" name="redirect" value="false"> <input type="hidden" name="VariantID" value="@product.VariantId"> <input type="hidden" name="UnitID" class="js-unit-id" value="@unitId"> </form> } <div class="d-flex @horizontalAlign @fullWidth js-input-group item_@Model.Item.SystemName.ToLower()"> @if (!anonymousUser && favoritesSelector) { @RenderPartial("Components/ToggleFavorite.cshtml", product) } <form method="post" action="@url" class="@fullWidth" style="z-index: 1"> <input type="hidden" name="redirect" value="false"> <input type="hidden" name="ProductId" value="@product.Id"> <input type="hidden" name="ProductName" value="@HtmlEncoder.HtmlEncode(product.Name)"> <input type="hidden" name="ProductVariantName" value="@product.VariantName"> <input type="hidden" name="ProductCurrency" value="@Dynamicweb.Ecommerce.Common.Context.Currency.Code"> <input type="hidden" name="ProductPrice" value="@PriceViewModelExtensions.ToStringInvariant(product.Price)"> <input type="hidden" name="ProductReferer" value="component_ProductAddToCart"> <input type="hidden" name="cartcmd" value="add"> <input type="submit" class="d-none" onclick="event.preventDefault(); swift.Cart.Update(event)"> @* Fix for enterKey should not redirect to minicart page *@ @if (!string.IsNullOrEmpty(product.VariantId)) { <input type="hidden" name="VariantId" value="@product.VariantId"> } <template class="js-step-quantity-warning"> <div class="modal-header"> <h1 class="modal-title fs-5">@Translate("The quantity is not valid")</h1> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> @Translate("Please select a quantity that is dividable by") @stepQty </div> </template> <template class="js-min-quantity-warning"> <div class="modal-header"> <h1 class="modal-title fs-5">@Translate("The product could not be added to the cart")</h1> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> @Translate("The quantity is not valid. You must buy at least") @product.PurchaseMinimumQuantity </div> </template> <template class="js-value-missing-warning"> <div class="modal-header"> <h1 class="modal-title fs-5">@Translate("No amount specified")</h1> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> @Translate("Specify an amount to add to the cart") </div> </template> @if (userHasPendingQuote) { <input type="hidden" name="PendingQuote" value="true"> <template class="js-pending-quote-notice"> <div class="modal-header"> <h1 class="modal-title fs-5">@Translate("Pending Quote")</h1> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="@Translate("Close")"></button> </div> <div class="modal-body"> @Translate("You need to complete your current quote or empty the cart before adding this product to cart.") </div> </template> } @if (quantitySelector || (!anonymousUser && product.VariantInfo.VariantInfo != null) || (!anonymousUser && favoritesSelector)) { <input type="hidden" id="Unit_@(product.Id)_@product.VariantId.Replace(".", "_")" name="UnitID" value="@unitId" /> } <div class="d-flex flex-row w-100"> @if (!quantitySelector) { <input id="Quantity_@(product.Id)_@product.VariantId.Replace(".", "_")" class="swift_quantity_field" name="Quantity" value="@valueQty" type="hidden" @disableAddToCart> } @if (unitsSelector && product.UnitOptions.Count > 0) { string selectedUnitName = !string.IsNullOrEmpty(unitId) && product?.UnitOptions != null ? unitId : product.UnitOptions.FirstOrDefault<UnitOptionViewModel>().Name; foreach (var unitOption in product.UnitOptions) { if (unitOption.Id == unitId) { selectedUnitName = unitOption.Name; } } <div class="d-flex flex-column gap-2 w-100"> <div class="input-group input-primary-button-group flex-nowrap@(inputSize)"> @if (quantitySelector) { <input id="Quantity_@(product.Id)_@product.VariantId.Replace(".", "_")" name="Quantity" value="@DoubleToString(valueQty)" step="@DoubleToString(stepQty)" min="@DoubleToString(minQty)" max="@DoubleToString(maxQty)" class="form-control swift_quantity-field" style="min-width: 60px; max-width: 100px; z-index: 1" type="number" @disableAddToCart> } <button class="btn btn-secondary @flexFill dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> @selectedUnitName </button> <ul class="dropdown-menu swift_unit-field"> @foreach (var unitOption in product.UnitOptions) { var selectedUnit = unitOption.Id == unitId ? "selected" : ""; <li> <button type="button" class="btn dropdown-item" data-value="@unitOption.Id" onclick="document.querySelector('#UnitSelectorForm_@(product.Id)_@(product.VariantId.Replace(".", "_"))_@Model.ID').querySelector('.js-unit-id').value = this.getAttribute('data-value'); document.querySelector('#Unit_@(product.Id)_@product.VariantId.Replace(".", "_")').value = this.getAttribute('data-value'); swift.PageUpdater.Update(document.querySelector('#UnitSelectorForm_@(product.Id)_@(product.VariantId.Replace(".", "_"))_@Model.ID'))"> <span>@unitOption.Name</span> <span> @if (unitOption.StockLevel > 0 || unitOption.NeverOutOfStock) { if (!Model.Item.GetBoolean("HideInventory") && !unitOption.NeverOutOfStock) { <span class="small text-success">@unitOption.StockLevel @Translate("In stock")</span> } else { <span class="small text-success">@Translate("In stock")</span> } } else { <span class="small text-danger">@Translate("Out of Stock")</span> } </span> </button> </li> } </ul> </div> <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary @(buttonSize) js-add-to-cart-button" style="white-space: nowrap" @disableAddToCart title="@Translate("Add to cart")" id="AddToCartButton@(product.Id)_@Pageview.CurrentParagraph.ID"> @if (!Model.Item.GetBoolean("HideButtonText")) { <span class="text-nowrap d-flex align-items-center justify-content-center gap-2"> @addToCartLabel </span> } else { @addToCartLabel } </button> </div> } else { <div class="input-group input-primary-button-group flex-nowrap@(inputSize)"> @if (quantitySelector) { <input id="Quantity_@(product.Id)_@product.VariantId.Replace(".", "_")" name="Quantity" value="@DoubleToString(valueQty)" step="@DoubleToString(stepQty)" min="@DoubleToString(minQty)" max="@DoubleToString(maxQty)" class="form-control swift_quantity-field" style="min-width: 60px; max-width: 100px; z-index: 1" type="number" @disableAddToCart> } <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary @(buttonSize) @flexFill js-add-to-cart-button" style="white-space: nowrap" @disableAddToCart title="@Translate("Add to cart")" id="AddToCartButton@(product.Id)_@Pageview.CurrentParagraph.ID"> @if (!Model.Item.GetBoolean("HideButtonText")) { <span class="text-nowrap d-flex align-items-center justify-content-center gap-2"> @addToCartLabel </span> } else { @addToCartLabel } </button> </div> } </div> </form> </div> } else if (whenVariantsExist == "modal") { string ButtonShape = Model.Item.GetRawValueString("VariantButtonShape", "square"); string buttonAspectRatio = Model.Item.GetRawValueString("VariantImageAspectRatio", "56%"); string buttonText = Translate("Select"); string variantId = !string.IsNullOrWhiteSpace(product.VariantId) ? product.VariantId : product.DefaultVariantId; string variantSelectorServicePageId = !string.IsNullOrEmpty(Model.Item.GetString("VariantSelectorServicePageId")) ? Model.Item.GetLink("VariantSelectorServicePageId").PageId.ToString() : ""; variantSelectorServicePageId = variantSelectorServicePageId != "" ? variantSelectorServicePageId : GetPageIdByNavigationTag("VariantSelectorService").ToString(); <div class="d-flex @horizontalAlign w-100 item_@Model.Item.SystemName.ToLower()"> @if (!anonymousUser && favoritesSelector) { @RenderPartial("Components/ToggleFavorite.cshtml", product) } <form action="/Default.aspx?ID=@variantSelectorServicePageId" data-response-target-element="DynamicModalContent" data-preloader="inline" style="z-index: 1" class="@fullWidth"> <input type="hidden" name="ProductID" value="@product.Id"> <input type="hidden" name="VariantID" value="@variantId"> <input type="hidden" name="QuantitySelector" value="@quantitySelector.ToString()"> <input type="hidden" name="HideInventory" value="@hideInventory.ToString()"> <input type="hidden" name="HideStockState" value="@hideStockState.ToString()"> <input type="hidden" name="ButtonLayout" value="@ButtonShape"> <input type="hidden" name="ButtonAspectRatio" value="@buttonAspectRatio"> <input type="hidden" name="VariantSelectorServicePage" value="@variantSelectorServicePageId"> <input type="hidden" name="ViewType" value="ModalContent"> @if (isLazyLoadingForProductInfoEnabled) { @* If lazy loading is enabled, bypass it because we're loading a modal window, so render everything as if it was server-side *@ <input type="hidden" name="getproductinfo" value="true"> } <button type="button" onclick="swift.PageUpdater.Update(event)" class="btn btn-primary@(buttonSize) @fullWidth" title="@Translate("Select")" data-bs-toggle="modal" data-bs-target="#DynamicModal" id="OpenVariantSelectorModal@(product.Id)_@Pageview.CurrentParagraph.ID">@buttonText</button> </form> </div> } } else if (Pageview.IsVisualEditorMode) { <div class="alert alert-dark m-0">@Translate("No products available")</div> }
Error executing template "Designs/Swift/Paragraph/Swift_ProductStock.cshtml"
System.Net.Http.HttpRequestException: Unauthorized Response: <error xmlns="http://docs.oasis-open.org/odata/ns/metadata"><code>Unauthorized</code><message>The credentials provided are incorrect</message></error>
 ---> System.Net.Http.HttpRequestException: Unauthorized
 ---> System.InvalidOperationException: <error xmlns="http://docs.oasis-open.org/odata/ns/metadata"><code>Unauthorized</code><message>The credentials provided are incorrect</message></error>
   --- End of inner exception stack trace ---
   at Dynamicweb.DataIntegration.EndpointManagement.EndpointHttpClient.SendRequest(HttpClient client, HttpRequestMessage msg) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\DataIntegration\Dynamicweb.DataIntegration\EndpointManagement\EndpointHttpClient.cs:line 55
   at Dynamicweb.DataIntegration.EndpointManagement.EndpointHttpClient.Execute(Endpoint endpoint, TimeSpan requestTimeout, String requestBody) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\DataIntegration\Dynamicweb.DataIntegration\EndpointManagement\EndpointHttpClient.cs:line 33
   at Dynamicweb.DataIntegration.EndpointManagement.EndpointService.GetResponse(Endpoint endpoint, String requestBody, TimeSpan requestTimeout) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\DataIntegration\Dynamicweb.DataIntegration\EndpointManagement\EndpointService.cs:line 525
   --- End of inner exception stack trace ---
   at Dynamicweb.DataIntegration.EndpointManagement.EndpointService.HandleException(Exception ex, Endpoint endpoint) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\DataIntegration\Dynamicweb.DataIntegration\EndpointManagement\EndpointService.cs:line 661
   at Dynamicweb.DataIntegration.EndpointManagement.EndpointService.GetResponse(Endpoint endpoint, String requestBody, TimeSpan requestTimeout) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\DataIntegration\Dynamicweb.DataIntegration\EndpointManagement\EndpointService.cs:line 531
   at DynamicwebLiveIntegration3.EndpointManager.ExecuteEndpointRequest(String urlSuffix, Object requestBody)
   at DynamicwebLiveIntegration3.Caching.StockCache.FetchMissing(IEnumerable`1 keys)
   at Dynamicweb.Caching.ServiceCache`2.GetCache(IEnumerable`1 keys) in C:\Users\frn\source\repos\Dynamicweb10\src\Core\Dynamicweb.Core\Caching\ServiceCache.cs:line 317
   at Dynamicweb.Caching.ServiceCache`2.GetCache(TKey key) in C:\Users\frn\source\repos\Dynamicweb10\src\Core\Dynamicweb.Core\Caching\ServiceCache.cs:line 274
   at DynamicwebLiveIntegration3.LiveIntegrationService.GetStock(ProductStockCacheKey productStockCacheKey, Boolean silent)
   at DynamicwebLiveIntegration3.Providers.ProductStockProvider.FindStockLevel(Product product, String unitId, StockLocation stockLocation)
   at Dynamicweb.Ecommerce.Products.ProductExtentions.GetUnitStock(Product product, StockLocation stockLocation, String unitId) in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\Products\ProductExtentions.cs:line 202
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass15_1.<BulkCreateView>b__23() in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 142
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.CreateValue()
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass15_2.<BulkCreateView>b__25() in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 144
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.CreateValue()
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass15_2.<BulkCreateView>b__27() in C:\Users\frn\source\repos\Dynamicweb10\src\Features\Ecommerce\Dynamicweb.Ecommerce\ProductCatalog\ViewEngine.cs:line 146
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.CreateValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_a7480fc9df1341b88e874af1f6db2f1c.ExecuteAsync()
   at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.DynamicWrapperService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass23_0.<Run>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template) in /_/src/Application/Providers/Dynamicweb.Rendering.Providers.NetCore/Razor/RazorTemplateRenderingProvider.cs:line 68
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template) in C:\Users\frn\source\repos\Dynamicweb10\src\Core\Dynamicweb.Core\Rendering\TemplateRenderingService.cs:line 14
   at Dynamicweb.Rendering.Template.RenderRazorTemplate() in C:\Users\frn\source\repos\Dynamicweb10\src\Core\Dynamicweb.Core\Rendering\Template.cs:line 805

1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> @using Dynamicweb.Ecommerce.ProductCatalog @{ ProductViewModel product = null; if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) { product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; } else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) { var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); if (productList?.Products is object) { product = productList.Products[0]; } } bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); bool hideStock = Model.Item.GetBoolean("HideStockState") || (Pageview.AreaSettings.GetBoolean("ErpDownHideStock") && isErpConnectionDown); } @if (product is object && product.ProductType == Dynamicweb.Ecommerce.Products.ProductType.Stock && !hideStock) { string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; bool hasExpectedDelivery = product.ExpectedDelivery != null && product.ExpectedDelivery > DateTime.Now; string expectedDeliveryDate = product.ExpectedDelivery?.ToShortDateString() ?? ""; string liveInfoClass = ""; string productInfoFeed = ""; bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); if (isLazyLoadingForProductInfoEnabled) { if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) { productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); if (!string.IsNullOrEmpty(productInfoFeed)) { productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; } } liveInfoClass = "js-live-info"; } if (!product.NeverOutOfstock) { string deliveryLabel = !string.IsNullOrEmpty(product.StockDeliveryText) ? $"{product.StockDeliveryText}" : ""; deliveryLabel += !string.IsNullOrEmpty(product.StockDeliveryValue) ? $" {product.StockDeliveryValue}" : ""; if (isLazyLoadingForProductInfoEnabled) { string inStockStateLabel = !string.IsNullOrEmpty(product.StockStatus) ? product.StockStatus : Translate("In stock"); string noStockStateLabel = !string.IsNullOrEmpty(product.StockStatus) ? product.StockStatus : Translate("Out of Stock"); <div class="js-stock-state @horizontalAlign item_@Model.Item.SystemName.ToLower() @liveInfoClass" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> <div class="js-stock-state spinner-border"> <div class="small d-none" data-show-if="LiveProductInfo.product.StockLevel > 0"> @if (!Model.Item.GetBoolean("HideInventory")) { <span class="text-success js-text-stock"></span> } <span class="text-success">@inStockStateLabel</span> <span class="opacity-75">@deliveryLabel</span> </div> <div class="small text-danger d-none" data-show-if="LiveProductInfo.product.StockLevel <= 0">@noStockStateLabel</div> <div class="d-none" data-show-if="LiveProductInfo.product.ExpectedDelivery != null && new Date(LiveProductInfo.product.ExpectedDelivery) > new Date()"> <span>@Translate("Expected back in stock"): </span> <span class="js-text-expected-delivery"></span> </div> </div> </div> } else { string firstUnitId = product?.UnitOptions?.FirstOrDefault() != null ? product.UnitOptions.FirstOrDefault().Id : ""; string defaultUnitId = !string.IsNullOrEmpty(product.DefaultUnitId) ? product.DefaultUnitId : firstUnitId; string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : defaultUnitId; double? currentStockLevel = product.StockLevel; string stockStateLabel = currentStockLevel > 0 ? Translate("In stock") : Translate("Out of stock"); stockStateLabel = !string.IsNullOrEmpty(product.StockStatus) ? product.StockStatus : stockStateLabel; string stockStateCss = currentStockLevel > 0 ? "text-success" : "text-danger"; string stockStateIconCss = currentStockLevel > 0 ? "bg-success" : "bg-danger"; <div class="js-stock-state @horizontalAlign item_@Model.Item.SystemName.ToLower()"> <div class="small"> @if (!Model.Item.GetBoolean("HideInventory") && currentStockLevel > 0) { <span class="@stockStateCss js-text-stock">@currentStockLevel</span> } <span class="@stockStateCss">@stockStateLabel</span> @if (!string.IsNullOrEmpty(deliveryLabel)) { <span class="opacity-75">@deliveryLabel</span> } </div> @if (hasExpectedDelivery) { <div> <span>@Translate("Expected in stock"): </span> <span>@expectedDeliveryDate</span> </div> } </div> } } else if (Pageview.IsVisualEditorMode) { <div class="alert alert-info">@Translate("No products available")</div> } }

Shipping

Delivery within 7 work days

Warranty

3 years warranty

Be comfortable with our equipments

Specifications

Be updated on the newest events

Trending

More products

By clicking 'Accept All' you consent that we may collect information about you for various purposes, including: Statistics and Marketing