Component builder for: Product list card

Error executing template "Designs/Swift/Paragraph/Swift_ProductPrice.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_617c1028786a418f8b972ca37e1991b5.Execute() in F:\Domains\Sites\int-krvc.mydwsitec.com\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice.cshtml:line 28
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> 2 @using Dynamicweb.Ecommerce.ProductCatalog 3 4 @{ 5 ProductViewModel product = null; 6 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 7 { 8 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 9 } 10 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 11 { 12 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 13 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 14 15 if (productList?.Products is object) 16 { 17 product = productList.Products[0]; 18 } 19 } 20 21 bool showZeroPrice = Model.Item.GetString("ShowPrice") == "show"; 22 string zeroPriceMessage = Model.Item.GetString("Message"); 23 24 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 25 bool anonymousUser = Pageview.User == null; 26 bool isErpConnectionDown = !Dna.Ecommerce.LiveIntegration.TemplatesHelper.IsWebServiceConnectionAvailable(); 27 bool isLazyLoadingForProductInfoEnabled = Dna.Ecommerce.LiveIntegration.TemplatesHelper.IsLazyLoadingForProductInfoEnabled; 28 bool hidePrice = (anonymousUsersLimitations.Contains("price") && anonymousUser) || (Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown) || (!showZeroPrice && product.Price.Price <= 0 && !isLazyLoadingForProductInfoEnabled); 29 30 bool productIsDiscontinued = product is object && product.Discontinued; 31 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 32 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 33 } 34 35 @if (product is object && !hidePrice && !isDiscontinued) { 36 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 37 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 38 39 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "fs-2"); 40 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 41 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 42 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 43 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 44 45 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 46 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 47 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 48 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 49 50 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 51 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 52 string order = layout == "horizontal" ? string.Empty : "order-2"; 53 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 54 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 55 56 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 57 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 58 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 59 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 60 61 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 62 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 63 64 string priceMin = ""; 65 string priceMax = ""; 66 67 string liveInfoClass = ""; 68 string productInfoFeed = ""; 69 70 @* START CUSTOM CODE *@ 71 var displayUnits = ""; 72 if (Model.Item.GetBoolean("ShowDisplayUnits")) 73 { 74 product.ProductFields.TryGetValue("DisplayUnits", out FieldValueViewModel displayUnitsObject); 75 if (displayUnitsObject != null) 76 { 77 displayUnits = Dynamicweb.Core.Converter.ToString(displayUnitsObject.Value); 78 } 79 } 80 @* END CUSTOM CODE *@ 81 82 if (isLazyLoadingForProductInfoEnabled) 83 { 84 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 85 { 86 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 87 if (!string.IsNullOrEmpty(productInfoFeed)) 88 { 89 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 90 } 91 } 92 liveInfoClass = "js-live-info"; 93 } 94 95 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" data-show-zero-price="@showZeroPrice" data-zero-price-message="@zeroPriceMessage" @productInfoFeed> 96 @if (showInformativePrice && product.PriceInformative.Price != 0) 97 { 98 <div class="opacity-50"> 99 <span>@Translate("RRP") </span> 100 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 101 </div> 102 } 103 <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"> 104 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 105 106 107 @if (showPricesWithVat == "false" && !neverShowVat) 108 { 109 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 110 { 111 <span itemprop="price" content="" class="d-none"></span> 112 <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> 113 } 114 else 115 { 116 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 117 118 <span itemprop="price" content="@product.Price.PriceWithoutVat" class="d-none"></span> 119 if (product.Price.Price != product.PriceBeforeDiscount.Price) 120 { 121 <span class="text-decoration-line-through opacity-75 @order">@beforePrice</span> 122 } 123 } 124 } 125 else 126 { 127 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 128 { 129 <span itemprop="price" content="" class="d-none"></span> 130 <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> 131 } 132 else 133 { 134 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 135 136 <span itemprop="price" content="@product.Price.Price" class="d-none"></span> 137 138 if (product.Price.Price != product.PriceBeforeDiscount.Price) 139 { 140 <span class="text-decoration-line-through opacity-75 @order"> 141 <span class="text-price">@beforePrice</span> 142 </span> 143 } 144 } 145 } 146 147 @if (showPricesWithVat == "false" && !neverShowVat) 148 { 149 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 150 { 151 <span class="text-price js-text-price"> 152 <span class="spinner-border" role="status"></span> 153 </span> 154 } 155 else 156 { 157 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 158 159 if (product?.VariantInfo?.VariantInfo != null) 160 { 161 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 162 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 163 } 164 if (priceMin != priceMax) 165 { 166 price = priceMin + " - " + priceMax; 167 } 168 <span class="@theme @contentPadding"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 <span class="@theme @contentPadding"> 195 @* START CUSTOM CODE *@ 196 <span class="text-price"> 197 @price 198 @if (!string.IsNullOrEmpty(displayUnits)) 199 { 200 <small>@displayUnits</small> 201 } 202 </span> 203 @* END CUSTOM CODE *@ 204 </span> 205 } 206 } 207 208 @* Stock state for Schema.org, start *@ 209 @{ 210 Uri url = Dynamicweb.Context.Current.Request.Url; 211 } 212 213 <link itemprop="url" href="@url"> 214 215 @{ 216 bool IsNeverOutOfStock = product.NeverOutOfstock; 217 } 218 219 @if (IsNeverOutOfStock) 220 { 221 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 222 } 223 else 224 { 225 if (product.StockLevel > 0) 226 { 227 <span itemprop="availability" class="d-none">InStock</span> 228 } 229 else 230 { 231 <span itemprop="availability" class="d-none">OutOfStock</span> 232 } 233 } 234 @* Stock state for Schema.org, stop *@ 235 236 </div> 237 238 @if (showPricesWithVat == "false" && !neverShowVat) 239 { 240 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 241 { 242 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 243 } 244 else 245 { 246 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 247 248 if (product?.VariantInfo?.VariantInfo != null) 249 { 250 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 251 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 252 } 253 if (priceMin != priceMax) 254 { 255 price = priceMin + " - " + priceMax; 256 } 257 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 258 } 259 } 260 </div> 261 } 262 else if (!string.IsNullOrEmpty(zeroPriceMessage)) 263 { 264 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 265 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 266 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 267 268 <div class="@textAlign item_@Model.Item.SystemName.ToLower()">@zeroPriceMessage</div> 269 } 270 else if (Pageview.IsVisualEditorMode) 271 { 272 <div class="alert alert-dark m-0" role="alert"> 273 <span>@Translate("No products available")</span> 274 </div> 275 } 276
Error executing template "Designs/Swift/Paragraph/Swift_ProductAddToCart.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fa61c8e38a6475894b0b6825a46e0d5.Execute() in F:\Domains\Sites\int-krvc.mydwsitec.com\Files\Templates\Designs\Swift\Paragraph\Swift_ProductAddToCart.cshtml:line 55
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> 2 @using Dynamicweb.Ecommerce.ProductCatalog 3 @using Dynamicweb.Core.Encoders 4 @using System.Globalization 5 6 @functions { 7 string DoubleToString(double? value) 8 { 9 if (value.HasValue) 10 { 11 return value.Value.ToString(CultureInfo.InvariantCulture); 12 } 13 return null; 14 } 15 } 16 17 @{ 18 ProductViewModel product = null; 19 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 20 { 21 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 22 } 23 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 24 { 25 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 26 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 27 28 if (productList?.Products is object) 29 { 30 product = productList.Products[0]; 31 } 32 } 33 34 //START CUSTOM CODE 35 // Resolve the replacement product up front so the "View Replacement" button links to the 36 // replacement's own product page instead of relying on a ?ProductId= redirect on the shop page. 37 string replacementProductLink = null; 38 if (product?.ReplacementProduct != null && !string.IsNullOrEmpty(product.ReplacementProduct.ProductId)) 39 { 40 ProductViewModel replacementProduct = product.ReplacementProduct.GetProduct(); 41 if (replacementProduct != null && !string.IsNullOrEmpty(replacementProduct.Id) && replacementProduct.Active) 42 { 43 replacementProductLink = replacementProduct.GetProductLink(GetPageIdByNavigationTag("Shop"), false); 44 } 45 } 46 //END CUSTOM CODE 47 48 bool showZeroPrice = Model.Item.GetString("ShowPrice") == "show"; 49 string zeroPriceMessage = Model.Item.GetString("Message"); 50 51 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 52 bool anonymousUser = Pageview.User == null; 53 bool isErpConnectionDown = !Dna.Ecommerce.LiveIntegration.TemplatesHelper.IsWebServiceConnectionAvailable(); 54 bool isLazyLoadingForProductInfoEnabled = Dna.Ecommerce.LiveIntegration.TemplatesHelper.IsLazyLoadingForProductInfoEnabled; 55 bool hideAddToCart = (anonymousUsersLimitations.Contains("cart") && anonymousUser) || (Pageview.AreaSettings.GetBoolean("ErpDownHideAddToCart") && isErpConnectionDown) || (!showZeroPrice && (product.Price.Price <= 0 && !isLazyLoadingForProductInfoEnabled)); 56 hideAddToCart = Dna.SwiftRizzo.NonOrderable.Helpers.IsProductNonOrderable(product) || hideAddToCart; 57 hideAddToCart = Pageview.IsVisualEditorMode ? false : hideAddToCart; 58 59 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 60 horizontalAlign = horizontalAlign == "center" ? "justify-content-center" : horizontalAlign; 61 horizontalAlign = horizontalAlign == "end" ? "justify-content-end" : horizontalAlign; 62 horizontalAlign = horizontalAlign == "full" ? "" : horizontalAlign; 63 64 string fullWidth = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "w-100" : ""; 65 } 66 67 @if (product is object && !hideAddToCart) 68 { 69 bool favoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 70 bool quantitySelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowQuantitySelector")) ? Model.Item.GetBoolean("ShowQuantitySelector") : false; 71 bool unitsSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowUnitsSelector")) ? Model.Item.GetBoolean("ShowUnitsSelector") : false; 72 bool hideInventory = !string.IsNullOrEmpty(Model.Item.GetString("HideInventory")) ? Model.Item.GetBoolean("HideInventory") : false; 73 bool hideStockState = !string.IsNullOrEmpty(Model.Item.GetString("HideStockState")) ? Model.Item.GetBoolean("HideStockState") : false; 74 75 string buttonSize = Model.Item.GetRawValueString("ButtonSize", "regular"); 76 string inputSize = string.Empty; 77 78 switch (buttonSize) 79 { 80 case "small": 81 inputSize = " input-group-sm"; 82 buttonSize = " btn-sm"; 83 break; 84 case "regular": 85 buttonSize = string.Empty; 86 break; 87 case "large": 88 inputSize = " input-group-lg"; 89 buttonSize = " btn-lg"; 90 break; 91 } 92 93 string iconPath = "/Files/icons/"; 94 string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 95 if (!url.Contains("LayoutTemplate")) 96 { 97 url += url.Contains("?") ? "&LayoutTemplate=Swift_MiniCart.cshtml" : "?LayoutTemplate=Swift_MiniCart.cshtml"; 98 } 99 100 string whenVariantsExist = Model.Item.GetRawValueString("WhenVariantsExist", "hide"); 101 string flexFill = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "flex-fill" : ""; 102 string addToCartIcon = Model.Item.GetRawValueString("Icon", iconPath + "shopping-cart.svg"); 103 string addToCartLabel = !addToCartIcon.Contains("_none") ? $"<span class=\"icon-2\">{ReadFile(addToCartIcon)}</span>" : ""; 104 addToCartLabel += !addToCartIcon.Contains("_none") && !Model.Item.GetBoolean("HideButtonText") ? " " : ""; 105 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>" : ""; 106 107 bool userHasPendingQuote = Dynamicweb.Ecommerce.Common.Context.Cart != null && Dynamicweb.Ecommerce.Common.Context.Cart.IsQuote; 108 string cartOnClickText = userHasPendingQuote ? $"alert('{Translate("You need to complete your current quote or empty the cart before adding this product to cart")}')" 109 : "swift.Cart.Update(event)"; 110 111 string liveInfoClass = isLazyLoadingForProductInfoEnabled ? "js-live-info" : ""; 112 113 if (product.VariantInfo.VariantInfo == null || whenVariantsExist == "disable") 114 { 115 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : product.DefaultUnitId; 116 if (string.IsNullOrEmpty(unitId) && product?.UnitOptions != null) 117 { 118 if (product.UnitOptions.FirstOrDefault<UnitOptionViewModel>() != null) 119 { 120 unitId = product.UnitOptions.FirstOrDefault<UnitOptionViewModel>().Id; 121 } 122 } 123 124 double? stepQty = product.PurchaseQuantityStep > 0 ? product.PurchaseQuantityStep : 1; 125 double? minQty = product.PurchaseMinimumQuantity > 0 ? product.PurchaseMinimumQuantity : 1; 126 double? valueQty = minQty > stepQty ? minQty : stepQty; 127 string disableAddToCart = null; 128 double? maxQty = null; 129 130 //START CUSTOM CODE 131 if ((product.ProductType == Dynamicweb.Ecommerce.Products.ProductType.Stock || product.ProductType == Dynamicweb.Ecommerce.Products.ProductType.Bom) && !product.NeverOutOfstock) 132 { 133 //END CUSTOM CODE 134 disableAddToCart = (product.StockLevel <= 0) || (!product.NeverOutOfstock && isLazyLoadingForProductInfoEnabled) ? "disabled" : disableAddToCart; 135 maxQty = product.StockLevel; 136 } 137 138 disableAddToCart = whenVariantsExist == "disable" && product.VariantInfo.VariantInfo != null && string.IsNullOrEmpty(product.VariantId) ? "disabled" : disableAddToCart; 139 140 //START CUSTOM CODE 141 if (disableAddToCart == "disabled") { 142 addToCartLabel = !addToCartIcon.Contains("_none") ? $"<span class=\"icon-2\">{ReadFile(addToCartIcon)}</span>" : ""; 143 addToCartLabel += !addToCartIcon.Contains("_none") && !Model.Item.GetBoolean("HideButtonText") ? " " : ""; 144 addToCartLabel += !Model.Item.GetBoolean("HideButtonText") ? $"<span class=\"d-none d-md-inline\">{Translate("Currently Unavailable")}</span><span class=\"d-inline d-md-none\">{Translate("Unavailable")}</span>" : ""; 145 } 146 //END CUSTOM CODE 147 148 if (unitsSelector && product.UnitOptions.Count > 0) 149 { 150 <form method="post" action="/Default.aspx?ID=@(Pageview.Page.ID)&ProductId=@product.Id" id="UnitSelectorForm_@(product.Id)_@(product.VariantId.Replace(".", "_"))_@Model.ID"> 151 <input type="hidden" name="redirect" value="false"> 152 <input type="hidden" name="VariantID" value="@product.VariantId"> 153 <input type="hidden" name="UnitID" class="js-unit-id" value="@unitId"> 154 </form> 155 } 156 157 <div class="d-flex @horizontalAlign @fullWidth @liveInfoClass js-input-group item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" data-show-zero-price="@showZeroPrice" data-zero-price-message="@zeroPriceMessage"> 158 @if (!anonymousUser && favoritesSelector) 159 { 160 @RenderPartial("Components/ToggleFavorite.cshtml", product) 161 } 162 163 @*START CUSTOM CODE*@ 164 @if (!string.IsNullOrEmpty(replacementProductLink)) 165 { 166 @* z-index keeps the button above the stretched-link overlay on product list tiles, same as the add to cart form below *@ 167 <div class="@fullWidth ms-4" style="z-index: 1"> 168 <a href="@replacementProductLink" class="btn btn-primary text-nowrap">@Translate("View Replacement")</a> 169 </div> 170 } 171 else 172 { 173 @*END CUSTOM CODE*@ 174 <form method="post" action="@url" class="@fullWidth" style="z-index: 1"> 175 <input type="hidden" name="redirect" value="false"> 176 <input type="hidden" name="ProductId" value="@product.Id"> 177 <input type="hidden" name="ProductName" value="@HtmlEncoder.HtmlEncode(product.Name)"> 178 <input type="hidden" name="ProductVariantName" value="@product.VariantName"> 179 <input type="hidden" name="ProductCurrency" value="@Dynamicweb.Ecommerce.Common.Context.Currency.Code"> 180 <input type="hidden" name="ProductPrice" value="@PriceViewModelExtensions.ToStringInvariant(product.Price)"> 181 <input type="hidden" name="ProductReferer" value="component_ProductAddToCart"> 182 <input type="hidden" name="cartcmd" value="add"> 183 <input type="submit" class="d-none" onclick="event.preventDefault(); swift.Cart.Update(event)"> @* Fix for enterKey should not redirect to minicart page *@ 184 185 @if (!string.IsNullOrEmpty(product.VariantId)) 186 { 187 <input type="hidden" name="VariantId" value="@product.VariantId"> 188 } 189 190 <template class="js-step-quantity-warning"> 191 <div class="modal-header"> 192 <h1 class="modal-title fs-5">@Translate("The quantity is not valid")</h1> 193 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 194 </div> 195 <div class="modal-body"> 196 @Translate("Please select a quantity that is dividable by") @stepQty 197 </div> 198 </template> 199 200 201 <template class="js-min-quantity-warning"> 202 <div class="modal-header"> 203 <h1 class="modal-title fs-5">@Translate("The product could not be added to the cart")</h1> 204 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 205 </div> 206 <div class="modal-body"> 207 @Translate("The quantity is not valid. You must buy at least") @product.PurchaseMinimumQuantity 208 </div> 209 </template> 210 211 <template class="js-value-missing-warning"> 212 <div class="modal-header"> 213 <h1 class="modal-title fs-5">@Translate("No amount specified")</h1> 214 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 215 </div> 216 <div class="modal-body"> 217 @Translate("Specify an amount to add to the cart") 218 </div> 219 </template> 220 221 222 @if (userHasPendingQuote) 223 { 224 <input type="hidden" name="PendingQuote" value="true"> 225 226 <template class="js-pending-quote-notice"> 227 <div class="modal-header"> 228 <h1 class="modal-title fs-5">@Translate("Pending Quote")</h1> 229 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="@Translate("Close")"></button> 230 </div> 231 <div class="modal-body"> 232 @Translate("You need to complete your current quote or empty the cart before adding this product to cart.") 233 </div> 234 </template> 235 } 236 237 @if (quantitySelector || (!anonymousUser && product.VariantInfo.VariantInfo != null) || (!anonymousUser && favoritesSelector)) 238 { 239 <input type="hidden" id="Unit_@(product.Id)_@product.VariantId.Replace(".", "_")" name="UnitID" value="@unitId" /> 240 } 241 242 <div class="d-flex flex-row w-100"> 243 @if (!quantitySelector) 244 { 245 <input id="Quantity_@(product.Id)_@product.VariantId.Replace(".", "_")" class="swift_quantity_field" name="Quantity" value="@valueQty" type="hidden" @disableAddToCart> 246 } 247 248 @if (unitsSelector && product.UnitOptions.Count > 0) 249 { 250 string selectedUnitName = !string.IsNullOrEmpty(unitId) && product?.UnitOptions != null ? unitId : product.UnitOptions.FirstOrDefault<UnitOptionViewModel>().Name; 251 252 foreach (var unitOption in product.UnitOptions) 253 { 254 if (unitOption.Id == unitId) 255 { 256 selectedUnitName = unitOption.Name; 257 } 258 } 259 260 <div class="d-flex flex-column gap-2 w-100"> 261 <div class="input-group input-primary-button-group flex-nowrap@(inputSize)"> 262 263 @if (quantitySelector) 264 { 265 <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> 266 } 267 268 <button class="btn btn-secondary @flexFill dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> 269 @selectedUnitName 270 </button> 271 272 <ul class="dropdown-menu swift_unit-field"> 273 @foreach (var unitOption in product.UnitOptions) 274 { 275 var selectedUnit = unitOption.Id == unitId ? "selected" : ""; 276 277 <li> 278 <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'); 279 document.querySelector('#Unit_@(product.Id)_@product.VariantId.Replace(".", "_")').value = this.getAttribute('data-value'); 280 swift.PageUpdater.Update(document.querySelector('#UnitSelectorForm_@(product.Id)_@(product.VariantId.Replace(".", "_"))_@Model.ID'))"> 281 <span>@unitOption.Name</span> 282 <span> 283 @if (unitOption.StockLevel > 0 || unitOption.NeverOutOfStock) 284 { 285 if (!Model.Item.GetBoolean("HideInventory") && !unitOption.NeverOutOfStock) 286 { 287 <span class="small text-success">@unitOption.StockLevel @Translate("In stock")</span> 288 } 289 else 290 { 291 <span class="small text-success">@Translate("In stock")</span> 292 } 293 } 294 else 295 { 296 <span class="small text-danger">@Translate("Out of Stock")</span> 297 } 298 </span> 299 </button> 300 </li> 301 } 302 </ul> 303 </div> 304 <button type="button" onclick="@cartOnClickText" 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"> 305 @if (!Model.Item.GetBoolean("HideButtonText")) 306 { 307 <span class="text-nowrap d-flex align-items-center justify-content-center gap-2"> 308 @addToCartLabel 309 </span> 310 } 311 else 312 { 313 @addToCartLabel 314 } 315 </button> 316 </div> 317 } 318 else 319 { 320 <div class="input-group input-primary-button-group flex-nowrap@(inputSize)"> 321 @if (quantitySelector) 322 { 323 <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> 324 } 325 326 <button type="button" onclick="@cartOnClickText" 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"> 327 @if (!Model.Item.GetBoolean("HideButtonText")) 328 { 329 <span class="text-nowrap d-flex align-items-center justify-content-center gap-2"> 330 @addToCartLabel 331 </span> 332 } 333 else 334 { 335 @addToCartLabel 336 } 337 </button> 338 </div> 339 } 340 </div> 341 </form> 342 @*START CUSTOM CODE*@ 343 } 344 @*END CUSTOM CODE*@ 345 346 347 </div> 348 } 349 else if (whenVariantsExist == "modal") 350 { 351 string ButtonShape = Model.Item.GetRawValueString("VariantButtonShape", "square"); 352 string buttonAspectRatio = Model.Item.GetRawValueString("VariantImageAspectRatio", "56%"); 353 354 string buttonText = Translate("Select"); 355 string variantId = !string.IsNullOrWhiteSpace(product.VariantId) ? product.VariantId : product.DefaultVariantId; 356 357 string variantSelectorServicePageId = !string.IsNullOrEmpty(Model.Item.GetString("VariantSelectorServicePageId")) ? Model.Item.GetLink("VariantSelectorServicePageId").PageId.ToString() : ""; 358 variantSelectorServicePageId = variantSelectorServicePageId != "" ? variantSelectorServicePageId : GetPageIdByNavigationTag("VariantSelectorService").ToString(); 359 360 <div class="d-flex @horizontalAlign w-100 item_@Model.Item.SystemName.ToLower()"> 361 @if (!anonymousUser && favoritesSelector) 362 { 363 @RenderPartial("Components/ToggleFavorite.cshtml", product) 364 } 365 <form action="/Default.aspx?ID=@variantSelectorServicePageId" data-response-target-element="DynamicModalContent" data-preloader="inline" style="z-index: 1" class="@fullWidth"> 366 <input type="hidden" name="ProductID" value="@product.Id"> 367 <input type="hidden" name="VariantID" value="@variantId"> 368 <input type="hidden" name="QuantitySelector" value="@quantitySelector.ToString()"> 369 <input type="hidden" name="HideInventory" value="@hideInventory.ToString()"> 370 <input type="hidden" name="HideStockState" value="@hideStockState.ToString()"> 371 <input type="hidden" name="ButtonLayout" value="@ButtonShape"> 372 <input type="hidden" name="ButtonAspectRatio" value="@buttonAspectRatio"> 373 <input type="hidden" name="VariantSelectorServicePage" value="@variantSelectorServicePageId"> 374 <input type="hidden" name="ViewType" value="ModalContent"> 375 @if (isLazyLoadingForProductInfoEnabled) 376 { 377 @* If lazy loading is enabled, bypass it because we're loading a modal window, so render everything as if it was server-side *@ 378 <input type="hidden" name="getproductinfo" value="true"> 379 } 380 <button type="button" onclick="@cartOnClickText" 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> 381 </form> 382 </div> 383 } 384 } 385 else if (!string.IsNullOrEmpty(zeroPriceMessage)) 386 { 387 <div class="d-flex @horizontalAlign @fullWidth item_@Model.Item.SystemName.ToLower()">@zeroPriceMessage</div> 388 } 389 else if (Pageview.IsVisualEditorMode) 390 { 391 <div class="alert alert-dark m-0">@Translate("No products available")</div> 392 } 393