Komponent editor til: Slider product card - Compressed

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Smartpage.PhilipsonWine.Ecommerce.ProductInformation.ProductInformation..ctor(ProductViewModel product) in D:\a\1\s\Smartpage.PhilipsonWine.Ecommerce\ProductInformation\ProductInformation.cs:line 89
   at CompiledRazorTemplates.Dynamic.RazorEngine_5dd590282dbf44e29eab65207bb00f75.Execute() in D:\dynamicweb.net\Solutions\Wineshop\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 32
   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 Smartpage.PhilipsonWine.Ecommerce.ProductInformation 4 @using Smartpage.PhilipsonWine.EcomPrices 5 @using Smartpage.PhilipsonWine.EcomPrices.Models 6 @using Dynamicweb.Core 7 8 @* CUSTOMIZED STANDARD SWIFT (1.21.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Item["DummyProduct"] != null) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 ProductInformation productInformation = new ProductInformation(product); 33 var currentUser = Dynamicweb.Security.UserManagement.User.GetCurrentFrontendUser(); 34 //Get customer specific price and quantity 35 CustomPrice customPrice = null; 36 CustomPriceService.GetCustomPriceProducts(currentUser)?.TryGetValue(product.Id, out customPrice); 37 int kolli = productInformation.CurrentPriceQuantity; 38 39 int priceQuantity = customPrice?.PriceQuantity != null && customPrice?.PriceQuantity > 0 ? Converter.ToInt32(customPrice?.PriceQuantity) : productInformation.MaxPriceBasedOn; 40 var priceObject = new Smartpage.PhilipsonWine.Ecommerce.Prices.PriceObject(product.Id, priceQuantity, 0, productInformation.OnSale, Dynamicweb.Ecommerce.Common.Context.Currency, Dynamicweb.Ecommerce.Common.Context.Country, product.LanguageId, Pageview.Area.EcomShopId); 41 } 42 43 @if (product is object && !hidePrice) 44 { 45 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 46 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 47 48 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "fs-2"); 49 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 50 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 51 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 52 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 53 54 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 55 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 56 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 57 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 58 59 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 60 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 61 string order = layout == "horizontal" ? string.Empty : "order-0"; 62 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 63 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 64 65 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 66 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 67 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 68 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 69 70 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 71 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 72 73 string priceMin = ""; 74 string priceMax = ""; 75 76 string liveInfoClass = ""; 77 string productInfoFeed = ""; 78 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 79 if (isLazyLoadingForProductInfoEnabled) 80 { 81 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 82 { 83 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 84 if (!string.IsNullOrEmpty(productInfoFeed)) 85 { 86 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 87 } 88 } 89 liveInfoClass = "js-live-info"; 90 } 91 92 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower() custom" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 93 @if (showInformativePrice && product.PriceInformative.Price != 0) 94 { 95 <div> 96 <span class="@priceFontSize opacity-50 text-price">@product.PriceInformative.PriceFormatted</span> 97 </div> 98 } 99 <div class="@priceFontSize m-0 d-flex @flexDirection @flexGap @horizontalAlign" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 100 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 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="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.ToString(System.Globalization.CultureInfo.InvariantCulture)" class="d-none"></span> 114 if (priceObject.NormalPrice != priceObject.DiscountPrice) 115 { 116 <span class="text-normal-price opacity-50 @order">@priceObject.NormalPrice</span> 117 <span class="text-normal-price-single-bottle">@Translate("Custom:OneBottlePrice", "pr. fl.")</span> 118 } 119 } 120 } 121 else 122 { 123 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 124 { 125 <span itemprop="price" content="" class="d-none"></span> 126 <span class="opacity-75 me-3 text-price js-text-price d-none" data-show-if="LiveProductInfo.product.Price.Price != LiveProductInfo.product.PriceBeforeDiscount.Price"></span> 127 } 128 else 129 { 130 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 131 132 <span itemprop="price" content="@product.Price.Price.ToString(System.Globalization.CultureInfo.InvariantCulture)" class="d-none"></span> 133 134 if (priceObject.NormalPrice != priceObject.DiscountPrice) 135 { 136 <div class="opacity-50 @order"> 137 <span class="text-normal-price">@priceObject.NormalPrice</span> 138 <span class="text-normal-price-single-bottle">@Translate("Custom:OneBottlePrice", "pr. fl.")</span> 139 </div> 140 } 141 } 142 } 143 144 @if (showPricesWithVat == "false" && !neverShowVat) 145 { 146 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 147 { 148 <span class="text-price js-text-price"> 149 <span class="spinner-border" role="status"></span> 150 </span> 151 } 152 else 153 { 154 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 155 156 if (product?.VariantInfo?.VariantInfo != null) 157 { 158 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 159 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 160 } 161 if (priceMin != priceMax) 162 { 163 price = priceMin + " - " + priceMax; 164 } 165 <div class="@theme @contentPadding"> 166 <p class="text-price">@priceObject.DiscountPriceFormatted</p> 167 <p class="text-price-kolli">@Translate("Custom:KolliPrice", "pr. fl. v/")@kolli</p> 168 </div> 169 } 170 } 171 else 172 { 173 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 174 { 175 <span class="text-price js-text-price"> 176 <span class="spinner-border" role="status"></span> 177 </span> 178 } 179 else 180 { 181 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 182 183 if (product?.VariantInfo?.VariantInfo != null) 184 { 185 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 186 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 187 } 188 if (priceMin != priceMax) 189 { 190 price = priceMin + " - " + priceMax; 191 } 192 <div class="@theme @contentPadding"> 193 <p class="text-price">@priceObject.DiscountPriceFormatted</p> 194 <p class="text-price-kolli">@Translate("Custom:KolliPrice", "pr. fl. v/")@kolli</p> 195 </div> 196 } 197 } 198 199 @* Stock state for Schema.org, start *@ 200 @{ 201 Uri url = Dynamicweb.Context.Current.Request.Url; 202 } 203 204 <link itemprop="url" href="@url"> 205 206 @{ 207 bool IsNeverOutOfStock = product.NeverOutOfstock; 208 } 209 210 @if (IsNeverOutOfStock) 211 { 212 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 213 } 214 else 215 { 216 if (product.StockLevel > 0) 217 { 218 <span itemprop="availability" class="d-none">InStock</span> 219 } 220 else 221 { 222 <span itemprop="availability" class="d-none">OutOfStock</span> 223 } 224 } 225 @* Stock state for Schema.org, stop *@ 226 227 </div> 228 229 @if (showPricesWithVat == "false" && !neverShowVat) 230 { 231 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 232 { 233 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(Translate("Incl. VAT"))"></small> 234 } 235 else 236 { 237 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 238 239 if (product?.VariantInfo?.VariantInfo != null) 240 { 241 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 242 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 243 } 244 if (priceMin != priceMax) 245 { 246 price = priceMin + " - " + priceMax; 247 } 248 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 249 } 250 } 251 </div> 252 } 253 else if (Pageview.IsVisualEditorMode) 254 { 255 <div class="alert alert-dark m-0" role="alert"> 256 <span>@Translate("No products available")</span> 257 </div> 258 } 259
Error executing template "/Designs/Swift/Paragraph/Swift_ProductAddToCart_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Smartpage.PhilipsonWine.Ecommerce.ProductInformation.ProductInformation..ctor(ProductViewModel product) in D:\a\1\s\Smartpage.PhilipsonWine.Ecommerce\ProductInformation\ProductInformation.cs:line 89
   at CompiledRazorTemplates.Dynamic.RazorEngine_f9304474067c45248709de825fa8ff76.Execute() in D:\dynamicweb.net\Solutions\Wineshop\Files\Templates\Designs\Swift\Paragraph\Swift_ProductAddToCart_Custom.cshtml:line 37
   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 @*Custom code*@ 5 @using Smartpage.PhilipsonWine.Ecommerce.ProductInformation 6 @using Dynamicweb.Core 7 @using Smartpage.PhilipsonWine.EcomPrices 8 @using Smartpage.PhilipsonWine.EcomPrices.Models 9 @using Smartpage.Tracking.Helper 10 @using System 11 @using System.Web 12 13 14 @{ 15 ProductViewModel product = null; 16 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 17 { 18 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 19 } 20 else if (Pageview.Item["DummyProduct"] != null) 21 { 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 25 if (productList?.Products is object) 26 { 27 product = productList.Products[0]; 28 } 29 } 30 31 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 32 bool anonymousUser = Pageview.User == null; 33 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 34 bool hideAddToCart = anonymousUsersLimitations.Contains("cart") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHideAddToCart") && isErpConnectionDown; 35 hideAddToCart = Pageview.IsVisualEditorMode ? false : hideAddToCart; 36 //Custom code 37 var productField = new ProductInformation(product); 38 var kolli = productField.CurrentPriceQuantity; 39 string productLink = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl("Default.aspx?Id=" + GetPageIdByNavigationTag("Shop") + "&ProductId=" + product.Id); 40 string productImage = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + product.DefaultImage.Value; 41 var currentUser = Dynamicweb.Security.UserManagement.User.GetCurrentExtranetUser(); 42 CustomPrice customPrice = null; 43 CustomPriceService.GetCustomPriceProducts(currentUser)?.TryGetValue(product.Id, out customPrice); 44 int priceQuantity = customPrice?.PriceQuantity != null && customPrice?.PriceQuantity > 0 ? Converter.ToInt32(customPrice?.PriceQuantity) : productField.MaxPriceBasedOn; 45 string shopId = Pageview.Area.EcomShopId; 46 var priceObject = new Smartpage.PhilipsonWine.Ecommerce.Prices.PriceObject(product.Id, priceQuantity, product.Discount.Price, productField.OnSale, Dynamicweb.Ecommerce.Common.Context.Currency, Dynamicweb.Ecommerce.Common.Context.Country, product.LanguageId, shopId); 47 var productDiscount = PriceHelper.FormatPrice(priceObject.NormalPrice - priceObject.DiscountPrice); 48 string areaId = Converter.ToString(Pageview.AreaID); 49 string time = DateTime.Now.ToString("G", System.Globalization.CultureInfo.InvariantCulture); 50 string uniqueId = Guid.NewGuid().ToString("N"); 51 } 52 53 @if (product is object && !hideAddToCart) 54 { 55 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 56 horizontalAlign = horizontalAlign == "center" ? "justify-content-center" : horizontalAlign; 57 horizontalAlign = horizontalAlign == "end" ? "justify-content-end" : horizontalAlign; 58 horizontalAlign = horizontalAlign == "full" ? "" : horizontalAlign; 59 60 bool favoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 61 bool quantitySelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowQuantitySelector")) ? Model.Item.GetBoolean("ShowQuantitySelector") : false; 62 bool unitsSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowUnitsSelector")) ? Model.Item.GetBoolean("ShowUnitsSelector") : false; 63 bool hideInventory = !string.IsNullOrEmpty(Model.Item.GetString("HideInventory")) ? Model.Item.GetBoolean("HideInventory") : false; 64 bool hideStockState = !string.IsNullOrEmpty(Model.Item.GetString("HideStockState")) ? Model.Item.GetBoolean("HideStockState") : false; 65 66 string buttonSize = Model.Item.GetRawValueString("ButtonSize", "regular"); 67 string inputSize = string.Empty; 68 69 switch (buttonSize) 70 { 71 case "small": 72 inputSize = " input-group-sm"; 73 buttonSize = " btn-sm"; 74 break; 75 case "regular": 76 buttonSize = string.Empty; 77 break; 78 case "large": 79 inputSize = " input-group-lg"; 80 buttonSize = " btn-lg"; 81 break; 82 } 83 84 string iconPath = "/Files/icons/"; 85 string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 86 if (!url.Contains("LayoutTemplate")) 87 { 88 url += url.Contains("?") ? "&LayoutTemplate=Swift_MiniCart.cshtml" : "?LayoutTemplate=Swift_MiniCart.cshtml"; 89 } 90 91 bool outOfStock = (product.StockLevel <= 0); 92 string hideColliClass = outOfStock ? "d-none" : ""; 93 string disableAddToCart = outOfStock ? "disabled" : ""; 94 bool isNeverOutOfStock = product.NeverOutOfstock; 95 disableAddToCart = isNeverOutOfStock ? "" : disableAddToCart; 96 97 string soldOutBorderRadiusClass = outOfStock ? "sold-out-button" : ""; 98 99 string whenVariantsExist = Model.Item.GetRawValueString("WhenVariantsExist", "hide"); 100 101 string flexFill = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "flex-fill" : ""; 102 string fullWidth = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "w-100" : ""; 103 string addToCartIcon = Model.Item.GetRawValueString("Icon", iconPath + "shopping-cart.svg"); 104 string addToCartLabel = !addToCartIcon.Contains("_none") ? "<span class=\"icon-2\">" + ReadFile(addToCartIcon) + "</span>" : ""; 105 addToCartLabel += !addToCartIcon.Contains("_none") && !Model.Item.GetBoolean("HideButtonText") ? " " : ""; 106 addToCartLabel += !Model.Item.GetBoolean("HideButtonText") && !outOfStock ? Translate("Add to cart") : Translate("Sold out"); 107 108 if (product.VariantInfo.VariantInfo == null || whenVariantsExist == "disable") 109 { 110 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : product.DefaultUnitId; 111 if (string.IsNullOrEmpty(unitId) && product?.UnitOptions != null) 112 { 113 if (product.UnitOptions.FirstOrDefault<UnitOptionViewModel>() != null) 114 { 115 unitId = product.UnitOptions.FirstOrDefault<UnitOptionViewModel>().Id; 116 } 117 } 118 119 string minQty = product.PurchaseMinimumQuantity != 1 ? "min=\"" + product.PurchaseMinimumQuantity.ToString() + "\"" : "min=\"1\""; 120 string stepQty = product.PurchaseQuantityStep > 1 ? product.PurchaseQuantityStep.ToString() : "1"; 121 string valueQty = product.PurchaseMinimumQuantity > product.PurchaseQuantityStep ? product.PurchaseMinimumQuantity.ToString() : stepQty; 122 disableAddToCart = product.VariantInfo.VariantInfo != null && string.IsNullOrEmpty(product.VariantId) ? "disabled" : disableAddToCart; 123 124 var reserveMode = Dynamicweb.Ecommerce.Frontend.Cart.ProductReserve.Mode; 125 126 if (unitsSelector && product.UnitOptions.Count > 0) 127 { 128 <form method="post" action="/Default.aspx?ID=@(Pageview.Page.ID)&ProductId=@product.Id" id="UnitSelectorForm_@(product.Id)_@(product.VariantId)_@Model.ID"> 129 <input type="hidden" name="redirect" value="false"> 130 <input type="hidden" name="VariantID" value="@product.VariantId"> 131 <input type="hidden" name="UnitID" class="js-unit-id" value="@unitId"> 132 </form> 133 } 134 135 <div class="d-flex @horizontalAlign @fullWidth js-input-group item_@Model.Item.SystemName.ToLower()"> 136 <form method="post" action="@url" class="@fullWidth" style="z-index: 1"> 137 <input type="hidden" name="redirect" value="false"> 138 <input type="hidden" name="ProductId" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Id)"> 139 <input type="hidden" name="ProductName" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 140 <input type="hidden" name="ProductVariantName" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.VariantName)"> 141 <input type="hidden" name="ProductCurrency" value="@Dynamicweb.Ecommerce.Common.Context.Currency.Code"> 142 <input type="hidden" name="ProductPrice" value="@Converter.ToInt32(PriceViewModelExtensions.ToStringInvariant(product.Price))"> 143 <input type="hidden" name="ProductReferer" value="component_ProductAddToCart"> 144 <input type="hidden" name="cartcmd" value="add"> 145 @*Custom code*@ 146 <input type="hidden" name="ProductBrand" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(productField.Brand)"> 147 <input type="hidden" name="ProductType" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(productField.Type)"> 148 <input type="hidden" name="ProductPrimaryGrape" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(productField.PrimaryGrape)"> 149 <input type="hidden" name="ProductCountry" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(productField.Country)"> 150 <input type="hidden" name="ProductRegion" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(productField.Area)"> 151 <input type="hidden" name="ProductCounty" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(productField.County)"> 152 <input type="hidden" name="ProductVintage" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(productField.Year)"> 153 <input type="hidden" name="ProductOnSale" value="@productField.OnSale.ToString()"> 154 <input type="hidden" name="ProductBottleSize" value="@productField.BottleSizeCl"> 155 <input type="hidden" name="ProductLink" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(productLink)"> 156 <input type="hidden" name="ProductImage" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(productImage)"> 157 <input type="hidden" name="ProductDiscount" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(productDiscount)"> 158 <input type="hidden" name="ShopId" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(shopId)"> 159 <input type="hidden" name="AreaId" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(areaId)"> 160 <input type="hidden" name="Time" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(time)"> 161 <input type="hidden" name="UniqueId" value="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(uniqueId)"> 162 163 @if (reserveMode == Dynamicweb.Ecommerce.Frontend.Cart.ProductReserveMode.AddToCart) 164 { 165 <input type="hidden" name="GetReservedAmount" value="true"> 166 } 167 168 @if (!string.IsNullOrEmpty(product.VariantId)) 169 { 170 <input type="hidden" name="VariantId" value="@product.VariantId"> 171 } 172 173 @if (!product.NeverOutOfstock) 174 { 175 <input type="hidden" name="Stock" value="@product.StockLevel"> 176 177 <template class="js-out-of-stock-notice"> 178 <div class="modal-header"> 179 <h1 class="modal-title fs-5">@Translate("Stock limit")</h1> 180 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 181 </div> 182 <div class="modal-body"> 183 @Translate("There are not enough products in stock. The product might be sold out or discontinued. Please adjust the quantity.") 184 </div> 185 </template> 186 } 187 188 @if (stepQty != "1") 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 </div> 194 <div class="modal-body"> 195 @Translate("Please select a quantity that is dividable by") @stepQty 196 </div> 197 </template> 198 } 199 @if (product.PurchaseMinimumQuantity != 1) 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 </div> 205 <div class="modal-body"> 206 @Translate("The quantity is not valid. You must buy at least") @product.PurchaseMinimumQuantity 207 </div> 208 </template> 209 } 210 211 @if (quantitySelector || (!anonymousUser && product.VariantInfo.VariantInfo != null) || (!anonymousUser && favoritesSelector)) 212 { 213 <input type="hidden" id="Unit_@(product.Id)_@product.VariantId" name="UnitID" value="@unitId" /> 214 } 215 216 <div class="d-flex flex-row w-100"> 217 @if (!anonymousUser && favoritesSelector) 218 { 219 @RenderPartial("Components/ToggleFavorite.cshtml", product) 220 } 221 222 @if (!quantitySelector) 223 { 224 <input id="Quantity_@(product.Id)_@product.VariantId" name="Quantity" value="@kolli" type="hidden" class="@hideColliClass">//Custom code 225 } 226 227 <div class="input-group input-primary-button-group flex-nowrap@(inputSize)"> 228 @if (quantitySelector) 229 { 230 <input id="Quantity_@(product.Id)_@product.VariantId" name="Quantity" value="@kolli" step="@stepQty" @minQty class="form-control swift_quantity-field @hideColliClass" style="min-width: 60px; max-width: 100px; z-index: 1" type="number" onchange="swift.Cart.UpdateOnEnterKey(event)" onkeyup="swift.Cart.UpdateOnEnterKey(event)" @disableAddToCart>//Custom code 231 } 232 233 @if (unitsSelector && product.UnitOptions.Count > 0) 234 { 235 string selectedUnitName = !string.IsNullOrEmpty(unitId) && product?.UnitOptions != null ? unitId : product.UnitOptions.FirstOrDefault<UnitOptionViewModel>().Name; 236 237 foreach (var unitOption in product.UnitOptions) 238 { 239 if (unitOption.Id == unitId) 240 { 241 selectedUnitName = unitOption.Name; 242 } 243 } 244 245 <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> 246 @selectedUnitName 247 </button> 248 <ul class="dropdown-menu swift_unit-field"> 249 @foreach (var unitOption in product.UnitOptions) 250 { 251 var selectedUnit = unitOption.Id == unitId ? "selected" : ""; 252 253 <li> 254 <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'); 255 document.querySelector('#Unit_@(product.Id)_@product.VariantId').value = this.getAttribute('data-value'); 256 swift.PageUpdater.Update(document.querySelector('#UnitSelectorForm_@(product.Id)_@(product.VariantId)_@Model.ID'))"> 257 <span>@unitOption.Name</span> 258 <span> 259 @if (unitOption.StockLevel > 0) 260 { 261 if (!Model.Item.GetBoolean("HideInventory")) 262 { 263 <span class="small text-success">@unitOption.StockLevel @Translate("In stock")</span> 264 } 265 else 266 { 267 <span class="small text-success">@Translate("In stock")</span> 268 } 269 } 270 else 271 { 272 <span class="small text-danger">@Translate("Out of Stock")</span> 273 } 274 </span> 275 </button> 276 </li> 277 } 278 </ul> 279 } 280 281 <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary @(buttonSize) @flexFill js-add-to-cart-button @soldOutBorderRadiusClass" style="white-space: nowrap;" @disableAddToCart title="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(Translate("Add to cart"))" id="AddToCartButton@(product.Id)_@Pageview.CurrentParagraph.ID"> 282 @if (!Model.Item.GetBoolean("HideButtonText")) 283 { 284 <span class="text-nowrap d-flex align-items-center justify-content-center gap-2"> 285 @addToCartLabel 286 </span> 287 } 288 else 289 { 290 @addToCartLabel 291 } 292 </button> 293 294 </div> 295 </div> 296 </form> 297 </div> 298 } 299 else if (whenVariantsExist == "modal") 300 { 301 string buttonText = Translate("Select"); 302 303 string variantSelectorServicePageId = !string.IsNullOrEmpty(Model.Item.GetString("VariantSelectorServicePageId")) ? Model.Item.GetLink("VariantSelectorServicePageId").PageId.ToString() : ""; 304 variantSelectorServicePageId = variantSelectorServicePageId != "" ? variantSelectorServicePageId : GetPageIdByNavigationTag("VariantSelectorService").ToString(); 305 306 <div class="d-flex @horizontalAlign w-100 item_@Model.Item.SystemName.ToLower()"> 307 @if (!anonymousUser && favoritesSelector) 308 { 309 @RenderPartial("Components/ToggleFavorite.cshtml", product) 310 } 311 <form action="/Default.aspx?ID=@variantSelectorServicePageId" data-response-target-element="DynamicModalContent" data-preloader="inline" style="z-index: 1" class="@fullWidth"> 312 <input type="hidden" name="ProductID" value="@product.Id"> 313 <input type="hidden" name="QuantitySelector" value="@quantitySelector.ToString()"> 314 <input type="hidden" name="HideInventory" value="@hideInventory.ToString()"> 315 <input type="hidden" name="HideStockState" value="@hideStockState.ToString()"> 316 <input type="hidden" name="VariantSelectorServicePage" value="@variantSelectorServicePageId"> 317 <input type="hidden" name="ViewType" value="ModalContent"> 318 <button type="button" onclick="swift.PageUpdater.Update(event)" class="btn btn-primary@(buttonSize) @fullWidth" title="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(Translate("Select"))" data-bs-toggle="modal" data-bs-target="#DynamicModal" id="OpenVariantSelectorModal@(product.Id)_@Pageview.CurrentParagraph.ID">@buttonText</button> 319 </form> 320 </div> 321 } 322 } 323 else if (Pageview.IsVisualEditorMode) 324 { 325 <div class="alert alert-dark m-0">@Translate("No products available")</div> 326 } 327