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