Component builder for: Granzow Slider Component

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_5c2e2faf396c4b19803e941e814f6483.Execute() in D:\dynamicweb.net\Solutions\CO3\granzow2023.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice.cshtml:line 25
   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 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 22 bool anonymousUser = Pageview.User == null; 23 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 24 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 25 hidePrice = !hidePrice && product.Id != null && !Convert.ToBoolean(product.ProductFields["Custom_EnableAnonymousPurchase"]?.Value) && anonymousUser ? true : hidePrice; // #22458 26 hidePrice = Pageview.IsVisualEditorMode ? false : hidePrice; // #22458 27 28 bool productIsDiscontinued = product is object && product.Discontinued; 29 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 30 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 31 } 32 33 @if (product is object && !hidePrice && !isDiscontinued) { 34 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 35 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 36 37 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "fs-2"); 38 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 39 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 40 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 41 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 42 43 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 44 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 46 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 47 48 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 49 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 50 string order = layout == "horizontal" ? string.Empty : "order-2"; 51 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 52 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 53 54 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 55 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 56 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 57 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 58 59 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 60 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 61 62 string priceMin = ""; 63 string priceMax = ""; 64 65 string liveInfoClass = ""; 66 string productInfoFeed = ""; 67 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 68 if (isLazyLoadingForProductInfoEnabled) 69 { 70 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 71 { 72 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 73 if (!string.IsNullOrEmpty(productInfoFeed)) 74 { 75 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 76 } 77 } 78 liveInfoClass = "js-live-info"; 79 } 80 81 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 82 @if (showInformativePrice && product.PriceInformative.Price != 0) 83 { 84 <div class="opacity-50"> 85 <span>@Translate("RRP") </span> 86 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 87 </div> 88 } 89 <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"> 90 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 91 92 93 @if (showPricesWithVat == "false" && !neverShowVat) 94 { 95 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 96 { 97 <span itemprop="price" content="" class="d-none"></span> 98 <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> 99 } 100 else 101 { 102 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 103 104 <span itemprop="price" content="@product.Price.PriceWithoutVat" class="d-none"></span> 105 106 if (product.Price.Price != product.PriceBeforeDiscount.Price) 107 { 108 <span class="text-decoration-line-through opacity-75 @order">@beforePrice</span> 109 } 110 } 111 } 112 else 113 { 114 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 115 { 116 <span itemprop="price" content="" class="d-none"></span> 117 <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> 118 } 119 else 120 { 121 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 122 123 <span itemprop="price" content="@product.Price.Price" class="d-none"></span> 124 125 if (product.Price.Price != product.PriceBeforeDiscount.Price) 126 { 127 <span class="text-decoration-line-through opacity-75 @order"> 128 <span class="text-price">@beforePrice</span> 129 </span> 130 } 131 } 132 } 133 134 @if (showPricesWithVat == "false" && !neverShowVat) 135 { 136 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 137 { 138 <span class="text-price js-text-price"> 139 <span class="spinner-border" role="status"></span> 140 </span> 141 } 142 else 143 { 144 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 145 146 if (product?.VariantInfo?.VariantInfo != null) 147 { 148 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 149 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 150 } 151 if (priceMin != priceMax) 152 { 153 price = priceMin + " - " + priceMax; 154 } 155 <span class="@theme @contentPadding"> 156 <span class="text-price">@price</span> 157 </span> 158 } 159 } 160 else 161 { 162 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 163 { 164 <span class="text-price js-text-price"> 165 <span class="spinner-border" role="status"></span> 166 </span> 167 } 168 else 169 { 170 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 171 172 if (product?.VariantInfo?.VariantInfo != null) 173 { 174 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 175 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 176 } 177 if (priceMin != priceMax) 178 { 179 price = priceMin + " - " + priceMax; 180 } 181 <span class="@theme @contentPadding"> 182 <span class="text-price">@price</span> 183 </span> 184 } 185 } 186 187 @* Stock state for Schema.org, start *@ 188 @{ 189 Uri url = Dynamicweb.Context.Current.Request.Url; 190 } 191 192 <link itemprop="url" href="@url"> 193 194 @{ 195 bool IsNeverOutOfStock = product.NeverOutOfstock; 196 } 197 198 @if (IsNeverOutOfStock) 199 { 200 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 201 } 202 else 203 { 204 if (product.StockLevel > 0) 205 { 206 <span itemprop="availability" class="d-none">InStock</span> 207 } 208 else 209 { 210 <span itemprop="availability" class="d-none">OutOfStock</span> 211 } 212 } 213 @* Stock state for Schema.org, stop *@ 214 215 </div> 216 217 @if (showPricesWithVat == "false" && !neverShowVat) 218 { 219 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 220 { 221 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 222 } 223 else 224 { 225 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 226 227 if (product?.VariantInfo?.VariantInfo != null) 228 { 229 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 230 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 231 } 232 if (priceMin != priceMax) 233 { 234 price = priceMin + " - " + priceMax; 235 } 236 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 237 } 238 } 239 </div> 240 } 241 else if (Pageview.IsVisualEditorMode) 242 { 243 <div class="alert alert-dark m-0" role="alert"> 244 <span>@Translate("No products available")</span> 245 </div> 246 } 247
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_91bc7b4934dc45158a25d65292b27539.Execute() in D:\dynamicweb.net\Solutions\CO3\granzow2023.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\Paragraph\Swift_ProductAddToCart.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 @using Dynamicweb.Core.Encoders 4 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 5 6 7 @{ 8 ProductViewModel product = null; 9 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 10 { 11 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 12 } 13 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 14 { 15 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 16 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 17 18 if (productList?.Products is object) 19 { 20 product = productList.Products[0]; 21 } 22 } 23 24 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 25 bool anonymousUser = Pageview.User == null; 26 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 27 bool hideAddToCart = anonymousUsersLimitations.Contains("cart") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHideAddToCart") && isErpConnectionDown; 28 hideAddToCart = !hideAddToCart && product.Id != null && !Convert.ToBoolean(product.ProductFields["Custom_EnableAnonymousPurchase"]?.Value) && anonymousUser ? true : hideAddToCart; // #22458 29 hideAddToCart = Pageview.IsVisualEditorMode ? false : hideAddToCart; 30 } 31 32 @if (product is object && !hideAddToCart) { 33 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 34 horizontalAlign = horizontalAlign == "center" ? "justify-content-center" : horizontalAlign; 35 horizontalAlign = horizontalAlign == "end" ? "justify-content-end" : horizontalAlign; 36 horizontalAlign = horizontalAlign == "full" ? "" : horizontalAlign; 37 38 bool favoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 39 bool quantitySelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowQuantitySelector")) ? Model.Item.GetBoolean("ShowQuantitySelector") : false; 40 bool unitsSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowUnitsSelector")) ? Model.Item.GetBoolean("ShowUnitsSelector") : false; 41 bool hideInventory = !string.IsNullOrEmpty(Model.Item.GetString("HideInventory")) ? Model.Item.GetBoolean("HideInventory") : false; 42 bool hideStockState = !string.IsNullOrEmpty(Model.Item.GetString("HideStockState")) ? Model.Item.GetBoolean("HideStockState") : false; 43 44 string buttonSize = Model.Item.GetRawValueString("ButtonSize", "regular"); 45 string inputSize = string.Empty; 46 47 switch (buttonSize) 48 { 49 case "small": 50 inputSize = " input-group-sm"; 51 buttonSize = " btn-sm"; 52 break; 53 case "regular": 54 buttonSize = string.Empty; 55 break; 56 case "large": 57 inputSize = " input-group-lg"; 58 buttonSize = " btn-lg"; 59 break; 60 } 61 62 string iconPath = "/Files/icons/"; 63 string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 64 if (!url.Contains("LayoutTemplate")) 65 { 66 url += url.Contains("?") ? "&LayoutTemplate=Swift_MiniCart.cshtml" : "?LayoutTemplate=Swift_MiniCart.cshtml"; 67 } 68 69 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 70 string disableAddToCart = (product.StockLevel <= 0) ? "disabled" : ""; 71 bool isNeverOutOfStock = product.NeverOutOfstock; 72 disableAddToCart = isNeverOutOfStock && !isLazyLoadingForProductInfoEnabled ? "" : disableAddToCart; 73 74 string whenVariantsExist = Model.Item.GetRawValueString("WhenVariantsExist", "hide"); 75 76 string flexFill = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "flex-fill" : ""; 77 string fullWidth = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "w-100" : ""; 78 string addToCartIcon = Model.Item.GetRawValueString("Icon", iconPath + "shopping-cart.svg"); 79 string addToCartLabel = !addToCartIcon.Contains("_none") ? $"<span class=\"icon-2\">{ReadFile(addToCartIcon)}</span>" : ""; 80 addToCartLabel += !addToCartIcon.Contains("_none") && !Model.Item.GetBoolean("HideButtonText") ? " " : ""; 81 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>" : ""; 82 83 if (product.VariantInfo.VariantInfo == null || whenVariantsExist == "disable") { 84 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : product.DefaultUnitId; 85 if (string.IsNullOrEmpty(unitId) && product?.UnitOptions != null) { 86 if (product.UnitOptions.FirstOrDefault<UnitOptionViewModel>() != null) { 87 unitId = product.UnitOptions.FirstOrDefault<UnitOptionViewModel>().Id; 88 } 89 } 90 91 string minQty = product.PurchaseMinimumQuantity != 1 ? $"min=\"{product.PurchaseMinimumQuantity.ToString()}\"" : "min=\"1\""; 92 string stepQty = product.PurchaseQuantityStep > 1 ? product.PurchaseQuantityStep.ToString() : "1"; 93 string valueQty = product.PurchaseMinimumQuantity > product.PurchaseQuantityStep ? product.PurchaseMinimumQuantity.ToString() : stepQty; 94 disableAddToCart = product.VariantInfo.VariantInfo != null && string.IsNullOrEmpty(product.VariantId) ? "disabled" : disableAddToCart; 95 disableAddToCart = product.Discontinued ? "disabled" : disableAddToCart; 96 97 var reserveMode = Dynamicweb.Ecommerce.Frontend.Cart.ProductReserve.Mode; 98 99 if (unitsSelector && product.UnitOptions.Count > 0) { 100 <form method="post" action="/Default.aspx?ID=@(Pageview.Page.ID)&ProductId=@product.Id" id="UnitSelectorForm_@(product.Id)_@(product.VariantId)_@Model.ID"> 101 <input type="hidden" name="redirect" value="false"> 102 <input type="hidden" name="VariantID" value="@product.VariantId"> 103 <input type="hidden" name="UnitID" class="js-unit-id" value="@unitId"> 104 </form> 105 } 106 107 <div class="d-flex @horizontalAlign @fullWidth js-input-group item_@Model.Item.SystemName.ToLower()"> 108 <form method="post" action="@url" class="@fullWidth" style="z-index: 1"> 109 <input type="hidden" name="redirect" value="false"> 110 <input type="hidden" name="ProductId" value="@product.Id"> 111 <input type="hidden" name="ProductName" value="@HtmlEncoder.HtmlEncode(product.Name)"> 112 <input type="hidden" name="ProductVariantName" value="@product.VariantName"> 113 <input type="hidden" name="ProductCurrency" value="@Dynamicweb.Ecommerce.Common.Context.Currency.Code"> 114 <input type="hidden" name="ProductPrice" value="@PriceViewModelExtensions.ToStringInvariant(product.Price)"> 115 <input type="hidden" name="ProductReferer" value="component_ProductAddToCart"> 116 <input type="hidden" name="cartcmd" value="add"> 117 118 @if (reserveMode == Dynamicweb.Ecommerce.Frontend.Cart.ProductReserveMode.AddToCart) 119 { 120 <input type="hidden" name="GetReservedAmount" value="true"> 121 } 122 123 @if (!string.IsNullOrEmpty(product.VariantId)) 124 { 125 <input type="hidden" name="VariantId" value="@product.VariantId"> 126 } 127 128 @if (!product.NeverOutOfstock) 129 { 130 <input type="hidden" name="Stock" value="@product.StockLevel"> 131 132 <template class="js-out-of-stock-notice"> 133 <div class="modal-header"> 134 <h1 class="modal-title fs-5">@Translate("Stock limit")</h1> 135 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 136 </div> 137 <div class="modal-body"> 138 @Translate("There are not enough products in stock. The product might be sold out or discontinued. Please adjust the quantity.") 139 </div> 140 </template> 141 } 142 143 @if (stepQty != "1") 144 { 145 <template class="js-step-quantity-warning"> 146 <div class="modal-header"> 147 <h1 class="modal-title fs-5">@Translate("The quantity is not valid")</h1> 148 </div> 149 <div class="modal-body"> 150 @Translate("Please select a quantity that is dividable by") @stepQty 151 </div> 152 </template> 153 } 154 @if (product.PurchaseMinimumQuantity != 1) 155 { 156 <template class="js-min-quantity-warning"> 157 <div class="modal-header"> 158 <h1 class="modal-title fs-5">@Translate("The product could not be added to the cart")</h1> 159 </div> 160 <div class="modal-body"> 161 @Translate("The quantity is not valid. You must buy at least") @product.PurchaseMinimumQuantity 162 </div> 163 </template> 164 } 165 166 @if (quantitySelector || (!anonymousUser && product.VariantInfo.VariantInfo != null) || (!anonymousUser && favoritesSelector)) 167 { 168 <input type="hidden" id="Unit_@(product.Id)_@product.VariantId" name="UnitID" value="@unitId" /> 169 } 170 171 <div class="d-flex flex-row w-100"> 172 @if (!quantitySelector) 173 { 174 <input id="Quantity_@(product.Id)_@product.VariantId" class="swift_quantity_field" name="Quantity" value="@valueQty" type="hidden" @disableAddToCart> 175 } 176 177 @if (unitsSelector && product.UnitOptions.Count > 0) 178 { 179 string selectedUnitName = !string.IsNullOrEmpty(unitId) && product?.UnitOptions != null ? unitId : product.UnitOptions.FirstOrDefault<UnitOptionViewModel>().Name; 180 181 foreach (var unitOption in product.UnitOptions) 182 { 183 if (unitOption.Id == unitId) 184 { 185 selectedUnitName = unitOption.Name; 186 } 187 } 188 189 <div class="d-flex flex-column gap-2 w-100"> 190 <div class="input-group input-primary-button-group flex-nowrap@(inputSize)"> 191 @if (!anonymousUser && favoritesSelector) 192 { 193 @RenderPartial("Components/ToggleFavorite.cshtml", product) 194 } 195 196 @if (quantitySelector) 197 { 198 <input id="Quantity_@(product.Id)_@product.VariantId" name="Quantity" value="@valueQty" step="@stepQty" @minQty class="form-control swift_quantity-field" style="min-width: 60px; max-width: 100px; z-index: 1" type="number" onchange="swift.Cart.UpdateOnEnterKey(event)" onkeyup="swift.Cart.UpdateOnEnterKey(event)" @disableAddToCart> 199 } 200 201 <button class="btn btn-secondary @flexFill dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> 202 @selectedUnitName 203 </button> 204 205 <ul class="dropdown-menu swift_unit-field"> 206 @foreach (var unitOption in product.UnitOptions) 207 { 208 var selectedUnit = unitOption.Id == unitId ? "selected" : ""; 209 210 <li> 211 <button type="button" class="btn dropdown-item" data-value="@unitOption.Id" onclick="document.querySelector('#UnitSelectorForm_@(product.Id)_@(product.VariantId)_@Model.ID').querySelector('.js-unit-id').value = this.getAttribute('data-value'); 212 document.querySelector('#Unit_@(product.Id)_@product.VariantId').value = this.getAttribute('data-value'); 213 swift.PageUpdater.Update(document.querySelector('#UnitSelectorForm_@(product.Id)_@(product.VariantId)_@Model.ID'))"> 214 <span>@unitOption.Name</span> 215 <span> 216 @if (unitOption.StockLevel > 0 || unitOption.NeverOutOfStock) 217 { 218 if (!Model.Item.GetBoolean("HideInventory") && !unitOption.NeverOutOfStock) 219 { 220 <span class="small text-success">@unitOption.StockLevel @Translate("In stock")</span> 221 } 222 else 223 { 224 <span class="small text-success">@Translate("In stock")</span> 225 } 226 } 227 else 228 { 229 <span class="small text-danger">@Translate("Out of Stock")</span> 230 } 231 </span> 232 </button> 233 </li> 234 } 235 </ul> 236 </div> 237 <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"> 238 @if (!Model.Item.GetBoolean("HideButtonText")) 239 { 240 <span class="text-nowrap d-flex align-items-center justify-content-center gap-2"> 241 @addToCartLabel 242 </span> 243 } 244 else 245 { 246 @addToCartLabel 247 } 248 </button> 249 </div> 250 } 251 else 252 { 253 if (!anonymousUser && favoritesSelector) 254 { 255 @RenderPartial("Components/ToggleFavorite.cshtml", product) 256 } 257 258 <div class="input-group input-primary-button-group flex-nowrap@(inputSize)"> 259 @if (quantitySelector) 260 { 261 <input id="Quantity_@(product.Id)_@product.VariantId" name="Quantity" value="@valueQty" step="@stepQty" @minQty class="form-control swift_quantity-field" style="min-width: 60px; max-width: 100px; z-index: 1" type="number" onchange="swift.Cart.UpdateOnEnterKey(event)" onkeyup="swift.Cart.UpdateOnEnterKey(event)" @disableAddToCart> 262 } 263 264 <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"> 265 @if (!Model.Item.GetBoolean("HideButtonText")) 266 { 267 <span class="text-nowrap d-flex align-items-center justify-content-center gap-2"> 268 @addToCartLabel 269 </span> 270 } 271 else 272 { 273 @addToCartLabel 274 } 275 </button> 276 </div> 277 } 278 </div> 279 </form> 280 </div> 281 } else if (whenVariantsExist == "modal") { 282 string buttonText = Translate("Select"); 283 string variantId = !string.IsNullOrWhiteSpace(product.VariantId) ? product.VariantId : product.DefaultVariantId; 284 285 string variantSelectorServicePageId = !string.IsNullOrEmpty(Model.Item.GetString("VariantSelectorServicePageId")) ? Model.Item.GetLink("VariantSelectorServicePageId").PageId.ToString() : ""; 286 variantSelectorServicePageId = variantSelectorServicePageId != "" ? variantSelectorServicePageId : GetPageIdByNavigationTag("VariantSelectorService").ToString(); 287 288 <div class="d-flex @horizontalAlign w-100 item_@Model.Item.SystemName.ToLower()"> 289 @if (!anonymousUser && favoritesSelector) 290 { 291 @RenderPartial("Components/ToggleFavorite.cshtml", product) 292 } 293 <form action="/Default.aspx?ID=@variantSelectorServicePageId" data-response-target-element="DynamicModalContent" data-preloader="inline" style="z-index: 1" class="@fullWidth"> 294 <input type="hidden" name="ProductID" value="@product.Id"> 295 <input type="hidden" name="VariantID" value="@variantId"> 296 <input type="hidden" name="QuantitySelector" value="@quantitySelector.ToString()"> 297 <input type="hidden" name="HideInventory" value="@hideInventory.ToString()"> 298 <input type="hidden" name="HideStockState" value="@hideStockState.ToString()"> 299 <input type="hidden" name="VariantSelectorServicePage" value="@variantSelectorServicePageId"> 300 <input type="hidden" name="ViewType" value="ModalContent"> 301 @if (isLazyLoadingForProductInfoEnabled) 302 { 303 @* If lazy loading is enabled, bypass it because we're loading a modal window, so render everything as if it was server-side *@ 304 <input type="hidden" name="getproductinfo" value="true"> 305 } 306 <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> 307 </form> 308 </div> 309 } 310 } else if (Pageview.IsVisualEditorMode) { 311 <div class="alert alert-dark m-0">@Translate("No products available")</div> 312 } 313