Component builder for: Product list card
Error executing template "Designs/Swift/Paragraph/Swift_ProductHeader.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at CompiledRazorTemplates.Dynamic.RazorEngine_622bb4a9cf17491f8549646595af403f.Execute() in D:\dynamicweb.net\Solutions\Dynamicweb\dignet.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\Paragraph\Swift_ProductHeader.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> @using Dynamicweb.Ecommerce.ProductCatalog @{ ProductViewModel product = new ProductViewModel(); ProductViewModelSettings productSetting = new ProductViewModelSettings { LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, ShopId = Pageview.Area.EcomShopId }; if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) { product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; } else if (Pageview.Item["DummyProduct"] != null) { string dummyProductId = ""; var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); if (productList.Products != null) { foreach (var p in productList.Products) { dummyProductId = p.Id; } ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); product = dummyProduct; } else { product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); } } else if (Pageview.Item["DummyProduct"] == null) { product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); } string titleFontSize = Model.Item.GetRawValueString("FontSize", "fs-6"); string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; string headingLevel = Model.Item.GetString("HeadingLevel", "h2"); string headingLevelStart = $"<{headingLevel} class=\"{titleFontSize} {horizontalAlign} m-0\" itemprop=\"name\">"; string headingLevelStop = $"</{headingLevel}>"; } @if (product.Id != null) { @headingLevelStart @product.Name @headingLevelStop } else if (Pageview.IsVisualEditorMode) { <div class="alert alert-dark m-0">@Translate("No products available")</div> }
Error executing template "Designs/Swift/Paragraph/Swift_ProductNumber.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at CompiledRazorTemplates.Dynamic.RazorEngine_5c0e1c176e9b40c6951ec1aaf40e3063.Execute() in D:\dynamicweb.net\Solutions\Dynamicweb\dignet.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\Paragraph\Swift_ProductNumber.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> @using Dynamicweb.Ecommerce.ProductCatalog @{ ProductViewModel product = new ProductViewModel(); ProductViewModelSettings productSetting = new ProductViewModelSettings { LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, ShopId = Pageview.Area.EcomShopId }; if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) { product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; } else if (Pageview.Item["DummyProduct"] != null) { string dummyProductId = ""; var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); if (productList.Products != null) { foreach (var p in productList.Products) { dummyProductId = p.Id; } ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); product = dummyProduct; } else { product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); } } else if (Pageview.Item["DummyProduct"] == null) { product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); } string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; } @if (!Model.Item.GetBoolean("HideProductNumber") && product.Id != null) { <div class="fs-7 opacity-85 @horizontalAlign item_@Model.Item.SystemName.ToLower()" itemprop="sku">@product.Number</div> } else if (Pageview.IsVisualEditorMode) { <div class="alert alert-warning">@Translate("No products available")</div> }
Error executing template "Designs/Swift/Paragraph/Swift_ProductSpecification.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at CompiledRazorTemplates.Dynamic.RazorEngine_83c65ade7b114b22a269c5801e091902.Execute() in D:\dynamicweb.net\Solutions\Dynamicweb\dignet.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\Paragraph\Swift_ProductSpecification.cshtml:line 31 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> @using Dynamicweb.Ecommerce.ProductCatalog @{ bool isVisualEditor = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("VisualEdit")) ? Convert.ToBoolean(Dynamicweb.Context.Current.Request.QueryString.Get("VisualEdit")) : false; ProductViewModel product = new ProductViewModel(); ProductViewModelSettings productSetting = new ProductViewModelSettings { LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, ShopId = Pageview.Area.EcomShopId }; if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) { product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; } else if (Pageview.Item["DummyProduct"] != null) { string dummyProductId = ""; var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); if (productList.Products != null) { foreach (var p in productList.Products) { dummyProductId = p.Id; } ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); product = dummyProduct; } else { product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); } } else if (Pageview.Item["DummyProduct"] == null) { product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); } } @if (product?.Id != null) { IEnumerable<string> selectedDisplayGroupIds = Model.Item.GetRawValueString("DisplayGroups").Split(',').ToList(); List<CategoryFieldViewModel> displayGroups = new List<CategoryFieldViewModel>(); foreach (var selection in selectedDisplayGroupIds) { foreach (CategoryFieldViewModel group in product.FieldDisplayGroups.Values) { if (selection == group.Id) { displayGroups.Add(group); } } } bool showProductFields = Model.Item.GetBoolean("ProductFields"); bool hideTitle = Model.Item.GetBoolean("HideTitle"); string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; string titleFontSize = Model.Item.GetRawValueString("TitleFontSize", "display-4"); string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); contentPadding = contentPadding == "none" ? string.Empty : contentPadding; contentPadding = contentPadding == "small" ? " p-2 p-md-3" : contentPadding; contentPadding = contentPadding == "large" ? " p-4 p-md-5" : contentPadding; string layout = Model.Item.GetRawValueString("Layout", "list"); string size = Model.Item.GetRawValueString("Size", "full"); string gaps = size == "full" ? " gap-4" : " gap-2"; if (Pageview.IsVisualEditorMode && displayGroups.Count() == 0) { product.ProductFields.Clear(); product.ProductFields.Add(Translate("Width"), new FieldValueViewModel { Name = Translate("Width"), Value = "99cm" }); product.ProductFields.Add(Translate("Height"), new FieldValueViewModel { Name = Translate("Height"), Value = "195cm" }); showProductFields = true; } if (layout == "commas") { gaps = size == "full" ? " gap-4" : " gap-2"; } <div class="grid h-100@(gaps)@(theme)@(contentPadding) item_@Model.Item.SystemName.ToLower()"> @if ((product.ProductFields != null && Model.Item.GetBoolean("ProductFields")) || (product.ProductCategories != null && Model.Item.GetBoolean("CategoryFields")) || (displayGroups.Count != 0)) { if (!hideTitle) { <h2 class="g-col-12 @titleFontSize mb-0">@Model.Item.GetString("Title")</h2> } } @if (displayGroups.Count != 0) { foreach (var group in displayGroups) { bool hideHeader = Model.Item.GetBoolean("HideGroupHeaders"); if (!hideHeader) { <h4 class="g-col-12 h4 mb-0">@group.Name</h4> } @RenderFieldsFromList(group.Fields, layout); } } @if (product.ProductFields != null && showProductFields) { if (product.ProductFields.Count > 0) { @RenderFieldsFromList(product.ProductFields, layout); } } @if (product.ProductCategories != null && Model.Item.GetBoolean("CategoryFields")) { if (product.ProductCategories.Count > 0) { foreach (var group in product.ProductCategories) { CategoryFieldViewModel category = group.Value; bool hideHeader = Model.Item.GetBoolean("HideGroupHeaders"); if (!hideHeader) { <h4 class="g-col-12 h4 mb-0">@group.Value.Name</h4> } @RenderFieldsFromList(category.Fields, layout); } } } </div> } else if (Pageview.IsVisualEditorMode) { <div class="alert alert-warning m-0">@Translate("No products available")</div> } @helper RenderFieldsFromList(Dictionary<string, FieldValueViewModel> fields, string layout) { string size = Model.Item.GetRawValueString("Size", "full"); string gaps = size != "full" ? " gap-1" : string.Empty; bool hideFieldLabels = Model.Item.GetBoolean("HideFieldLabels"); if (layout == "columns") { <div class="g-col-12 grid@(gaps)"> @foreach (var field in fields) { @RenderField(field.Value, layout) } </div> } if (layout == "list") { <dl class="g-col-12 grid@(gaps)"> @foreach (var field in fields) { @RenderField(field.Value, layout) } </dl> } if (layout == "table") { string tableSize = size == "full" ? "" : " table-sm"; <div class="g-col-12"> <table class="table table-striped@(tableSize)"> @foreach (var field in fields) { @RenderField(field.Value, layout) } </table> </div> } if (layout == "bullets") { string listSize = size == "full" ? "" : "m-0 p-0 lh-1 fs-7 opacity-75"; string listStyle = size == "full" ? "" : "style=\"list-style-position: inside\""; <div class="g-col-12"> <ul class="@listSize" @listStyle> @foreach (var field in fields) { @RenderField(field.Value, layout) } </ul> </div> } if (layout == "commas") { List<string> featuresList = new List<string>(); foreach (var field in fields) { if (field.Value.Value is object && !string.IsNullOrEmpty(field.Value.Value.ToString())) { if (field.Value.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) { List<string> options = new List<string>(); foreach (FieldOptionValueViewModel option in field.Value.Value as System.Collections.Generic.List<FieldOptionValueViewModel>) { if (!string.IsNullOrWhiteSpace(option.Value)) { if (option.Value.ToString().Contains("#") && (Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) { string colorSpan = "<span class=\"colorbox-sm\" style=\"background-color: " + option.Value + "\"></span>"; options.Add(colorSpan); } else if (!string.IsNullOrEmpty(option.Value)) { options.Add(option.Name); } } } string optionsString = (string.Join(", ", options.Select(x => x.ToString()).ToArray())); if ((Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) { optionsString = (string.Join(" ", options.Select(x => x.ToString()).ToArray())); } if (!hideFieldLabels) { featuresList.Add(field.Value.Name + ": " + optionsString); } else { featuresList.Add(optionsString); } } else { if (!string.IsNullOrWhiteSpace(field.Value.Value.ToString())) { if (field.Value.Value.ToString().Contains("#") && (Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) { string colorSpan = "<span class=\"colorbox-sm\" style=\"background-color: " + field.Value.Value + "\"></span>"; if (!hideFieldLabels) { featuresList.Add(field.Value.Name + ": " + colorSpan); } else { featuresList.Add(colorSpan); } } else { if (!hideFieldLabels) { featuresList.Add(field.Value.Name + ": " + field.Value.Value.ToString()); } else { featuresList.Add(field.Value.Value.ToString()); } } } } } } string featuresString = (string.Join(", ", featuresList.Select(x => x.ToString()).ToArray())); <div class="g-col-12 opacity-75 fs-7">@featuresString</div> } } @helper RenderField(FieldValueViewModel field, string layout) { string size = Model.Item.GetRawValueString("Size", "full"); string fieldValue = field?.Value != null ? field.Value.ToString() : ""; bool hideFieldLabels = Model.Item.GetBoolean("HideFieldLabels"); bool noValues = false; if (!string.IsNullOrEmpty(fieldValue)) { if (field.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) { System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; noValues = values.Count > 0 ? false : true; } } if (!string.IsNullOrEmpty(fieldValue) && noValues == false) { if (layout == "columns") { <div class="grid g-col-6 g-col-lg-4 gap-1"> @if(!hideFieldLabels) { <dt class="g-col-12 g-col-lg-4">@field.Name</dt> } <dd class="g-col-12 g-col-lg-8 mb-0 text-break">@RenderFieldValue(field)</dd> </div> } if (layout == "list") { if (!hideFieldLabels) { <dt class="g-col-4">@field.Name</dt> } <dd class="g-col-8 mb-0 text-break"> @RenderFieldValue(field) </dd> } if (layout == "table") { <tr> @if (!hideFieldLabels) { <th class="w-25 w-lg-50" scope="row">@field.Name</th> } <td class="text-break">@RenderFieldValue(field)</td> </tr> } if (layout == "bullets") { <li> @if (!hideFieldLabels) { <strong>@field.Name</strong> } <span>@RenderFieldValue(field)</span> </li> } } } @helper RenderFieldValue(FieldValueViewModel field) { string fieldValue = field?.Value != null ? field.Value.ToString() : ""; bool isLink = field?.Type == "Link"; bool isColor = false; bool isBrandName = field?.SystemName == "Brand_name"; fieldValue = fieldValue == "False" ? Translate("No") : fieldValue; fieldValue = fieldValue == "True" ? Translate("Yes") : fieldValue; if (field.Value.GetType() == typeof(System.Collections.Generic.List<Dynamicweb.Ecommerce.ProductCatalog.FieldOptionValueViewModel>)) { int valueCount = 0; System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; int totalValues = values.Count; foreach (FieldOptionValueViewModel option in values) { if (!string.IsNullOrEmpty(option.Value)) { if (option.Value.Substring(0,1) == "#") { isColor = true; } } if (!isColor) { @option.Name } else { <span class="colorbox-sm" style="background-color: @option.Value" title="@option.Name"></span> } if (valueCount != totalValues && valueCount < (totalValues - 1)) { if (isColor) { <text> </text> } else { <text>, </text> } } valueCount++; } } else { if (fieldValue.Substring(0,1) == "#") { isColor = true; } if (!isColor) { if(isLink) { string linktTitle = !fieldValue.Contains("aspx") ? fieldValue : Translate("Go to link"); string target = Pageview.AreaSettings.GetBoolean("OpenLinksInNewTab") && fieldValue.Contains("http") ? "target=\"_blank\"" : string.Empty; string rel = Pageview.AreaSettings.GetBoolean("OpenLinksInNewTab") && fieldValue.Contains("http") ? "rel=\"noopener\"" : string.Empty; <a href="@field.Value" title="@field.Name" @target @rel>@linktTitle</a> } else if (isBrandName) { <span itemprop="brand" itemtype="https://schema.org/Brand" itemscope> <span itemprop="name">@fieldValue</span> </span> } else { @fieldValue } } else { <span class="colorbox-sm" style="background-color: @fieldValue" title="@fieldValue"></span> } } }
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at CompiledRazorTemplates.Dynamic.RazorEngine_1863c87416d24aafb3cbf063808a01cb.Execute() in D:\dynamicweb.net\Solutions\Dynamicweb\dignet.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage.cshtml:line 33 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> @using Dynamicweb.Ecommerce.ProductCatalog @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites @{ ProductViewModel product = new ProductViewModel(); ProductViewModelSettings productSetting = new ProductViewModelSettings { LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, ShopId = Pageview.Area.EcomShopId }; if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) { product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; } else if (Pageview.Item["DummyProduct"] != null) { string dummyProductId = ""; var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); if (productList.Products != null) { foreach (var p in productList.Products) { dummyProductId = p.Id; } ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); product = dummyProduct; } else { product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); } } else if (Pageview.Item["DummyProduct"] == null) { product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); } string imagePath = product?.DefaultImage?.Value ?? ""; imagePath = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); ratio = ratio != "0" ? ratio : ""; string ratioCssClass = ratio != "" ? " ratio" : ""; string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; string width = Model.Item.GetRawValueString("Width", "auto"); int smallImageSize = 640; int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); string imagePathXs = "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePath + "&format=webp"; string imagePathS = "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePath + "&format=webp"; string imagePathFallBack = "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePath + "&format=webp"; var badgeParms = new Dictionary<string, object>(); badgeParms.Add("size", "h7"); badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; bool showFavoritesSelectorMasterProduct = !string.IsNullOrEmpty(Model.Item.GetString("ShowFavoritesSelectorMasterProduct")) ? Model.Item.GetBoolean("ShowFavoritesSelectorMasterProduct") : false; string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); bool anonymousUser = Pageview.User == null; var favoriteParameters = new Dictionary<string, object>(); if (!anonymousUser && showFavoritesSelector) { int defaultFavoriteListId = 0; IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); if (favoreiteLists.Count() == 1) { foreach (FavoriteList list in favoreiteLists) { defaultFavoriteListId = list.ListId; } } favoriteParameters.Add("ListId", defaultFavoriteListId); } @* Theme settings *@ string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; } @if (product.Id != null) { string imageId = "ProductImage_" + product.Id + product.VariantId; bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; DateTime createdDate = product.Created.Value; bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) ? true : showBadges; string fullWidth = width == "auto" ? "w-100" : ""; string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; if (!string.IsNullOrEmpty(imagePath)) { <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> <div class="ratio" style="@(ratioVariable)"> <div class="d-flex justify-content-center align-items-center"> <img id="@imageId" srcset=" @imagePathXs @(smallImageSize)w, @imagePathS @(largeImageSize)w" sizes="(min-width: 992px) 33vw, 50vw" src="@imagePathFallBack" loading="lazy" decoding="async" class="h-100 w-100 @themePadding" style="object-fit: contain; @themeBorder" alt="@product.Name"> </div> </div> @if (showBadges) { <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> @RenderPartial("Components/EcommerceBadge.cshtml", product, badgeParms) </div> } @if (!anonymousUser) { if (showFavoritesSelector && product.VariantInfo.VariantInfo == null) { <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) </div> } else if (showFavoritesSelectorMasterProduct) { <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) </div> } } </div> } } else if (Pageview.IsVisualEditorMode) { <div class="alert alert-dark m-0">@Translate("No products available")</div> }
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_c1a6e5d00ddb4a60a8a3db52490899ff.Execute() in D:\dynamicweb.net\Solutions\Dynamicweb\dignet.cloud.dynamicweb-cms.com\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> @using Dynamicweb.Ecommerce.ProductCatalog @{ ProductViewModel product = new ProductViewModel(); ProductViewModelSettings productSetting = new ProductViewModelSettings { LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, ShopId = Pageview.Area.EcomShopId }; if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) { product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; } else if (Pageview.Item["DummyProduct"] != null) { string dummyProductId = ""; var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); if (productList.Products != null) { foreach (var p in productList.Products) { dummyProductId = p.Id; } ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); product = dummyProduct; } else { product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); } } else if (Pageview.Item["DummyProduct"] == null) { product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); } string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); bool anonymousUser = Pageview.User == null; bool isErpConnectionDown = !Dynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplatesHelper.IsWebServiceConnectionAvailable(); bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; string priceFontSize = Model.Item.GetRawValueString("PriceSize", "fs-2"); string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); string layout = Model.Item.GetRawValueString("Layout", "horizontal"); string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; textAlign = horizontalAlign == "end" ? "text-end" : textAlign; horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; string order = layout == "horizontal" ? string.Empty : "order-2"; string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "px-2 theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; } @if (!hidePrice && product.Id != null) { string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); string priceMin = ""; string priceMax = ""; string liveInfoClass = ""; string productInfoFeed = ""; bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplatesHelper.IsLazyLoadingForProductInfoEnabled; if (isLazyLoadingForProductInfoEnabled) { if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) { productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); if (!string.IsNullOrEmpty(productInfoFeed)) { productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; } } liveInfoClass = "js-live-info"; } <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" @productInfoFeed> @if (showInformativePrice && product.PriceInformative.Price != 0) { <div class="opacity-50"> <span>@Translate("RRP") </span> <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> </div> } <div class="@priceFontSize m-0 d-flex @flexDirection @flexGap @horizontalAlign" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> @if (showPricesWithVat == "false" && !neverShowVat) { if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) { <span itemprop="price" content="" class="d-none"></span> <span class="text-decoration-line-through js-text-decoration-line-through opacity-75 me-3 text-price js-text-price d-none" data-show-if="LiveProductInfo.product.Price.Price != LiveProductInfo.product.PriceBeforeDiscount.Price"></span> } else { string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; <span itemprop="price" content="@product.Price.PriceWithoutVat" class="d-none"></span> if (product.Price.Price != product.PriceBeforeDiscount.Price) { <span class="text-decoration-line-through opacity-75 @order">@beforePrice</span> } } } else { if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) { <span itemprop="price" content="" class="d-none"></span> <span class="text-decoration-line-through js-text-decoration-line-through opacity-75 me-3 text-price js-text-price d-none" data-show-if="LiveProductInfo.product.Price.Price != LiveProductInfo.product.PriceBeforeDiscount.Price"></span> } else { string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; <span itemprop="price" content="@product.Price.Price" class="d-none"></span> if (product.Price.Price != product.PriceBeforeDiscount.Price) { <span class="text-decoration-line-through opacity-75 @order"> <span class="text-price">@beforePrice</span> </span> } } } @if (showPricesWithVat == "false" && !neverShowVat) { if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) { <span class="text-price js-text-price"> <span class="spinner-border" role="status"></span> </span> } else { string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; if (product?.VariantInfo?.VariantInfo != null) { priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; } if (priceMin != priceMax) { price = priceMin + " - " + priceMax; } <span class="@theme"> <span class="text-price">@price</span> </span> } } else { if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) { <span class="text-price js-text-price"> <span class="spinner-border" role="status"></span> </span> } else { string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; if (product?.VariantInfo?.VariantInfo != null) { priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; } if (priceMin != priceMax) { price = priceMin + " - " + priceMax; } <span class="@theme"> <span class="text-price">@price</span> </span> } } @* Stock state for Schema.org, start *@ @{ Uri url = Dynamicweb.Context.Current.Request.Url; } <link itemprop="url" href="@url"> @{ bool IsNeverOutOfStock = product.NeverOutOfstock; } @if (IsNeverOutOfStock) { <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> } else { if (product.StockLevel > 0) { <span itemprop="availability" class="d-none">InStock</span> } else { <span itemprop="availability" class="d-none">OutOfStock</span> } } @* Stock state for Schema.org, stop *@ </div> @if (showPricesWithVat == "false" && !neverShowVat) { if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) { <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> } else { string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; if (product?.VariantInfo?.VariantInfo != null) { priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; } if (priceMin != priceMax) { price = priceMin + " - " + priceMax; } <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> } } </div> } else if (Pageview.IsVisualEditorMode) { <div class="alert alert-dark m-0" role="alert"> <span>@Translate("No products available")</span> </div> }
Error executing template "Designs/Swift/Paragraph/Swift_ProductAddToCart.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at CompiledRazorTemplates.Dynamic.RazorEngine_27cbaf1c681c4c52af130ff04c150c83.Execute() in D:\dynamicweb.net\Solutions\Dynamicweb\dignet.cloud.dynamicweb-cms.com\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> @using Dynamicweb.Ecommerce.ProductCatalog @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites @{ ProductViewModel product = new ProductViewModel(); ProductViewModelSettings productSetting = new ProductViewModelSettings { LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, ShopId = Pageview.Area.EcomShopId }; if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) { product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; } else if (Pageview.Item["DummyProduct"] != null) { string dummyProductId = ""; var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); if (productList.Products != null) { foreach (var p in productList.Products) { dummyProductId = p.Id; } ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); product = dummyProduct; } else { product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); } } else if (Pageview.Item["DummyProduct"] == null) { product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); } string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); horizontalAlign = horizontalAlign == "center" ? "justify-content-center" : horizontalAlign; horizontalAlign = horizontalAlign == "end" ? "justify-content-end" : horizontalAlign; horizontalAlign = horizontalAlign == "full" ? "" : horizontalAlign; string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); bool anonymousUser = Pageview.User == null; bool isErpConnectionDown = !Dynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplatesHelper.IsWebServiceConnectionAvailable(); bool hideAddToCart = anonymousUsersLimitations.Contains("cart") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHideAddToCart") && isErpConnectionDown; hideAddToCart = Pageview.IsVisualEditorMode ? false : hideAddToCart; bool favoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; bool showFavoritesSelectorMasterProduct = !string.IsNullOrEmpty(Model.Item.GetString("ShowFavoritesSelectorMasterProduct")) ? Model.Item.GetBoolean("ShowFavoritesSelectorMasterProduct") : false; bool quantitySelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowQuantitySelector")) ? Model.Item.GetBoolean("ShowQuantitySelector") : false; bool unitsSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowUnitsSelector")) ? Model.Item.GetBoolean("ShowUnitsSelector") : false; bool hideInventory = !string.IsNullOrEmpty(Model.Item.GetString("HideInventory")) ? Model.Item.GetBoolean("HideInventory") : false; bool hideStockState = !string.IsNullOrEmpty(Model.Item.GetString("HideStockState")) ? Model.Item.GetBoolean("HideStockState") : false; string buttonSize = Model.Item.GetRawValueString("ButtonSize", "regular"); string inputSize = string.Empty; switch (buttonSize) { case "small": inputSize = " input-group-sm"; buttonSize = " btn-sm"; break; case "regular": buttonSize = string.Empty; break; case "large": inputSize = " input-group-lg"; buttonSize = " btn-lg"; break; } } @if (!hideAddToCart && product.Id != null) { string iconPath = "/Files/icons/"; string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); if (!url.Contains("LayoutTemplate")) { url += url.Contains("?") ? "&LayoutTemplate=Swift_MiniCart.cshtml" : "?LayoutTemplate=Swift_MiniCart.cshtml"; } string disableAddToCart = (product.StockLevel <= 0) ? "disabled" : ""; bool isNeverOutOfStock = product.NeverOutOfstock; disableAddToCart = isNeverOutOfStock ? "" : disableAddToCart; string whenVariantsExist = Model.Item.GetRawValueString("WhenVariantsExist", "hide"); string flexFill = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "flex-fill" : ""; string fullWidth = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "w-100" : ""; string addToCartIcon = Model.Item.GetRawValueString("Icon", iconPath + "shopping-cart.svg"); string addToCartLabel = !addToCartIcon.Contains("_none") ? "<span class=\"icon-2\">" + ReadFile(addToCartIcon) + "</span>" : ""; addToCartLabel += !addToCartIcon.Contains("_none") && !Model.Item.GetBoolean("HideButtonText") ? " " : ""; addToCartLabel += !Model.Item.GetBoolean("HideButtonText") ? Translate("Add to cart") : ""; if (product.VariantInfo.VariantInfo == null || whenVariantsExist == "disable") { string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : product.DefaultUnitId; if (string.IsNullOrEmpty(unitId) && product?.UnitOptions != null) { if (product.UnitOptions.FirstOrDefault<UnitOptionViewModel>() != null) { unitId = product.UnitOptions.FirstOrDefault<UnitOptionViewModel>().Id; } } string minQty = product.PurchaseMinimumQuantity != 1 ? "min=\"" + product.PurchaseMinimumQuantity.ToString() + "\"" : "min=\"1\""; string stepQty = product.PurchaseQuantityStep > 1 ? product.PurchaseQuantityStep.ToString() : "1"; string valueQty = product.PurchaseMinimumQuantity > product.PurchaseQuantityStep ? product.PurchaseMinimumQuantity.ToString() : stepQty; string qtyValidCheck = stepQty != "1" ? "onkeyup=\"swift.Cart.QuantityValidate(event)\"" : ""; disableAddToCart = product.VariantInfo.VariantInfo != null && string.IsNullOrEmpty(product.VariantId) ? "disabled" : disableAddToCart; if (unitsSelector && product.UnitOptions.Count > 0) { <form method="post" action="/Default.aspx?ID=@(Pageview.Page.ID)&ProductId=@product.Id" id="UnitSelectorForm_@(product.Id)_@(product.VariantId)_@Model.ID"> <input type="hidden" name="redirect" value="false"> <input type="hidden" name="VariantID" value="@product.VariantId"> <input type="hidden" name="UnitID" class="js-unit-id" value="@unitId"> </form> } <div class="d-flex @horizontalAlign @fullWidth item_@Model.Item.SystemName.ToLower()"> <form method="post" action="@url" class="@fullWidth" style="z-index: 1"> <input type="hidden" name="redirect" value="false"> <input type="hidden" name="ProductId" value="@product.Id"> <input type="hidden" name="ProductName" value="@product.Name"> <input type="hidden" name="ProductVariantName" value="@product.VariantName"> <input type="hidden" name="ProductCurrency" value="@Dynamicweb.Ecommerce.Common.Context.Currency.Code"> <input type="hidden" name="ProductPrice" value="@product.Price.Price"> <input type="hidden" name="ProductReferer" value="component_ProductAddToCart"> <input type="hidden" name="cartcmd" value="add"> @if (!string.IsNullOrEmpty(product.VariantId)) { <input type="hidden" name="VariantId" value="@product.VariantId"> } @if (quantitySelector || (!anonymousUser && showFavoritesSelectorMasterProduct && product.VariantInfo.VariantInfo != null) || (!anonymousUser && favoritesSelector)) { <div class="d-flex flex-row w-100"> @if (!anonymousUser) { if (favoritesSelector && product.VariantInfo.VariantInfo == null) { @RenderPartial("Components/ToggleFavorite.cshtml", product) } else if (showFavoritesSelectorMasterProduct) { @RenderPartial("Components/ToggleFavorite.cshtml", product) } } <div class="input-group input-primary-button-group flex-nowrap@(inputSize)"> <input id="Quantity_@(product.Id)_@product.VariantId" name="Quantity" value="@valueQty" step="@stepQty" @minQty class="form-control" style="min-width: 60px; max-width: 100px; z-index: 1" type="number" onkeydown="swift.Cart.UpdateOnEnterKey(event)" @disableAddToCart> @if (unitsSelector && product.UnitOptions.Count > 0) { string selectedUnitName = !string.IsNullOrEmpty(unitId) && product?.UnitOptions != null ? unitId : product.UnitOptions.FirstOrDefault<UnitOptionViewModel>().Name; foreach (var unitOption in product.UnitOptions) { if (unitOption.Id == unitId) { selectedUnitName = unitOption.Name; } } <input type="hidden" id="Unit_@(product.Id)_@product.VariantId" name="UnitID" value="@unitId" /> <div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> @selectedUnitName </button> <ul class="dropdown-menu"> @foreach (var unitOption in product.UnitOptions) { var selectedUnit = unitOption.Id == unitId ? "selected" : ""; <li> <button type="button" class="btn dropdown-item" data-value="@unitOption.Id" onclick="document.querySelector('#UnitSelectorForm_@(product.Id)_@(product.VariantId)_@Model.ID').querySelector('.js-unit-id').value = this.getAttribute('data-value'); document.querySelector('#Unit_@(product.Id)_@product.VariantId').value = this.getAttribute('data-value'); swift.PageUpdater.Update(document.querySelector('#UnitSelectorForm_@(product.Id)_@(product.VariantId)_@Model.ID'))"> <span>@unitOption.Name</span> <span> @if (unitOption.StockLevel > 0) { if (!Model.Item.GetBoolean("HideInventory")) { <span class="small text-success">@unitOption.StockLevel @Translate("In stock")</span> } else { <span class="small text-success">@Translate("In stock")</span> } } else { <span class="small text-danger">@Translate("Out of Stock")</span> } </span> </button> </li> } </ul> </div> } <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary @(buttonSize) @flexFill js-add-to-cart-button" style="white-space: nowrap" @disableAddToCart title="@Translate("Add to cart")" id="AddToCartButton@(product.Id)_@Pageview.CurrentParagraph.ID"> @if (!Model.Item.GetBoolean("HideButtonText")) { <span class="text-nowrap d-flex align-items-center justify-content-center gap-2"> @addToCartLabel </span> } else { @addToCartLabel } </button> </div> @if (stepQty != "1") { <div class="invalid-feedback d-none"> @Translate("Please select a quantity that is dividable by") @stepQty </div> } </div> } else { <div class="d-flex flex-row w-100" style="z-index: 1;"> @if (!anonymousUser) { if (favoritesSelector && product.VariantInfo.VariantInfo == null) { @RenderPartial("Components/ToggleFavorite.cshtml", product) } else if (showFavoritesSelectorMasterProduct) { @RenderPartial("Components/ToggleFavorite.cshtml", product) } } <input id="Quantity_@(product.Id)_@product.VariantId" name="Quantity" value="@valueQty" type="hidden" @disableAddToCart> @if (unitsSelector && product.UnitOptions.Count > 0) { string selectedUnitName = !string.IsNullOrEmpty(unitId) && product?.UnitOptions != null ? unitId : product.UnitOptions.FirstOrDefault<UnitOptionViewModel>().Name; foreach (var unitOption in product.UnitOptions) { if (unitOption.Id == unitId) { selectedUnitName = unitOption.Name; } } <input type="hidden" id="Unit_@(product.Id)_@product.VariantId" name="UnitID" value="@unitId" /> <div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> @selectedUnitName </button> <ul class="dropdown-menu"> @foreach (var unitOption in product.UnitOptions) { var selectedUnit = unitOption.Id == unitId ? "selected" : ""; <li> <button type="button" class="btn dropdown-item" data-value="@unitOption.Id" onclick="document.querySelector('#UnitSelectorForm_@(product.Id)_@(product.VariantId)_@Model.ID').querySelector('.js-unit-id').value = this.getAttribute('data-value'); document.querySelector('#Unit_@(product.Id)_@product.VariantId').value = this.getAttribute('data-value'); swift.PageUpdater.Update(document.querySelector('#UnitSelectorForm_@(product.Id)_@(product.VariantId)_@Model.ID'))"> <span>@unitOption.Name</span> <span> @if (unitOption.StockLevel > 0) { if (!Model.Item.GetBoolean("HideInventory")) { <span class="small text-success">@unitOption.StockLevel @Translate("In stock")</span> } else { <span class="small text-success">@Translate("In stock")</span> } } else { <span class="small text-danger">@Translate("Out of Stock")</span> } </span> </button> </li> } </ul> </div> } <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary@(buttonSize) @flexFill js-add-to-cart-button" @disableAddToCart title="@Translate("Add to cart")" id="AddToCartButton@(product.Id)_@Pageview.CurrentParagraph.ID"> @if (!Model.Item.GetBoolean("HideButtonText")) { <span class="text-nowrap d-flex align-items-center justify-content-center gap-2"> @addToCartLabel </span> } else { @addToCartLabel } </button> </div> } </form> </div> } else if (whenVariantsExist == "modal") { string buttonText = Translate("Select"); string variantSelectorServicePageId = !string.IsNullOrEmpty(Model.Item.GetString("VariantSelectorServicePageId")) ? Model.Item.GetLink("VariantSelectorServicePageId").PageId.ToString() : ""; variantSelectorServicePageId = variantSelectorServicePageId != "" ? variantSelectorServicePageId : GetPageIdByNavigationTag("VariantSelectorService").ToString(); <div class="d-flex @horizontalAlign w-100 item_@Model.Item.SystemName.ToLower()"> @if (!anonymousUser && showFavoritesSelectorMasterProduct) { @RenderPartial("Components/ToggleFavorite.cshtml", product) } <form action="/Default.aspx?ID=@variantSelectorServicePageId" data-response-target-element="DynamicModalContent" data-preloader="inline" style="z-index: 1" class="@fullWidth"> <input type="hidden" name="ProductID" value="@product.Id"> <input type="hidden" name="QuantitySelector" value="@quantitySelector.ToString()"> <input type="hidden" name="HideInventory" value="@hideInventory.ToString()"> <input type="hidden" name="HideStockState" value="@hideStockState.ToString()"> <input type="hidden" name="VariantSelectorServicePage" value="@variantSelectorServicePageId"> <input type="hidden" name="ViewType" value="ModalContent"> <button type="button" onclick="swift.PageUpdater.Update(event)" class="btn btn-primary@(buttonSize) @fullWidth" title="@Translate("Select")" data-bs-toggle="modal" data-bs-target="#DynamicModal" id="OpenVariantSelectorModal@(product.Id)_@Pageview.CurrentParagraph.ID">@buttonText</button> </form> </div> } } else if (Pageview.IsVisualEditorMode) { <div class="alert alert-dark m-0">@Translate("No products available")</div> }