Komponent editor til: List card 1
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_146800583f8749238584d4a2039b8c59.Execute() in H:\Solutions\Hamonoya\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> 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 } 20 else if (Pageview.Item["DummyProduct"] != null) 21 { 22 string dummyProductId = ""; 23 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 24 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 25 if (productList.Products != null) 26 { 27 foreach (var p in productList.Products) { dummyProductId = p.Id; } 28 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 29 product = dummyProduct; 30 } 31 else 32 { 33 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 34 } 35 } 36 else if (Pageview.Item["DummyProduct"] == null) 37 { 38 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 39 } 40 41 string imagePath = product?.DefaultImage?.Value ?? ""; 42 imagePath = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 43 44 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 45 ratio = ratio != "0" ? ratio : ""; 46 string ratioCssClass = ratio != "" ? " ratio" : ""; 47 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 48 49 string width = Model.Item.GetRawValueString("Width", "auto"); 50 int smallImageSize = 640; 51 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 52 53 string imagePathXs = "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePath + "&format=webp"; 54 string imagePathS = "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePath + "&format=webp"; 55 string imagePathFallBack = "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePath + "&format=webp"; 56 57 var badgeParms = new Dictionary<string, object>(); 58 badgeParms.Add("size", "h7"); 59 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 60 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 61 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 62 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 63 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 64 65 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 66 67 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 68 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 69 bool anonymousUser = Pageview.User == null; 70 71 var favoriteParameters = new Dictionary<string, object>(); 72 if (!anonymousUser && showFavoritesSelector) 73 { 74 int defaultFavoriteListId = 0; 75 76 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 77 if (favoreiteLists.Count() == 1) 78 { 79 foreach (FavoriteList list in favoreiteLists) 80 { 81 defaultFavoriteListId = list.ListId; 82 } 83 } 84 85 favoriteParameters.Add("ListId", defaultFavoriteListId); 86 } 87 88 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 89 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 90 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 91 MediaViewModel alternativeImage = allAssetsImages.FirstOrDefault(); 92 93 string altImagePathXs = string.Empty; 94 string altImagePathS = string.Empty; 95 96 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 97 { 98 altImagePathXs = "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp"; 99 altImagePathS = "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp"; 100 } 101 102 @* Theme settings *@ 103 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 104 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 105 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 106 } 107 108 @if (product.Id != null) 109 { 110 string imageId = "ProductImage_" + product.Id + product.VariantId; 111 112 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 113 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 114 DateTime createdDate = product.Created.Value; 115 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 116 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 117 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) ? true : showBadges; 118 119 string fullWidth = width == "auto" ? "w-100" : ""; 120 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 121 122 123 if (!string.IsNullOrEmpty(imagePath)) 124 { 125 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 126 <div class="ratio" style="@(ratioVariable)"> 127 <div class="d-flex justify-content-center align-items-center"> 128 <img id="@imageId" 129 srcset=" 130 @imagePathXs @(smallImageSize)w, 131 @imagePathS @(largeImageSize)w" 132 sizes="(min-width: 992px) 33vw, 50vw" 133 src="@imagePathFallBack" 134 @if (!string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 135 data-alternative-image=" 136 @altImagePathXs @(smallImageSize)w, 137 @altImagePathS @(largeImageSize)w" 138 onmouseover="swift.Image.swapImage(event)" 139 onmouseout="swift.Image.swapImage(event)" 140 </text> } 141 loading="lazy" 142 decoding="async" 143 class="h-100 w-100 @themePadding" 144 style="object-fit: contain; @themeBorder" 145 alt="@product.Name"> 146 </div> 147 </div> 148 149 @if (showBadges) 150 { 151 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 152 @RenderPartial("Components/EcommerceBadge.cshtml", product, badgeParms) 153 </div> 154 } 155 156 @if (!anonymousUser) 157 { 158 if (showFavoritesSelector) 159 { 160 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 161 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 162 </div> 163 } 164 } 165 </div> 166 } 167 } 168 else if (Pageview.IsVisualEditorMode) 169 { 170 <div class="alert alert-dark m-0">@Translate("No products available")</div> 171 } 172
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_c3d50f69b0d548d197ffdecb069ea855.Execute() in H:\Solutions\Hamonoya\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> 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 } 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 titleFontSize = Model.Item.GetRawValueString("FontSize", "fs-6"); 37 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 38 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 39 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 40 41 string headingLevel = Model.Item.GetString("HeadingLevel", "h2"); 42 string headingLevelStart = $"<{headingLevel} class=\"{titleFontSize} {horizontalAlign} m-0 item_{Model.Item.SystemName.ToLower()}\" itemprop=\"name\">"; 43 string headingLevelStop = $"</{headingLevel}>"; 44 } 45 46 47 @if (product.Id != null) { 48 @headingLevelStart 49 @product.Name 50 @headingLevelStop 51 } else if (Pageview.IsVisualEditorMode) { 52 <div class="alert alert-dark m-0">@Translate("No products available")</div> 53 } 54
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_6b616eb90f7f4387a034332a506412e6.Execute() in H:\Solutions\Hamonoya\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> 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 string dummyProductId = ""; 20 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 21 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 22 if (productList.Products != null) 23 { 24 foreach (var p in productList.Products) { dummyProductId = p.Id; } 25 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 26 product = dummyProduct; 27 } else { 28 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 29 } 30 } else if (Pageview.Item["DummyProduct"] == null) { 31 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 32 } 33 34 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 35 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 36 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 37 } 38 39 @if (!Model.Item.GetBoolean("HideProductNumber") && product.Id != null) { 40 <div class="fs-7 opacity-85 @horizontalAlign item_@Model.Item.SystemName.ToLower()" itemprop="sku">@product.Number</div> 41 } else if (Pageview.IsVisualEditorMode) { 42 <div class="alert alert-warning">@Translate("No products available")</div> 43 } 44
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_cae6462a9ba64c9e9aed38cea404b514.Execute() in H:\Solutions\Hamonoya\Files\Templates\Designs\Swift\Paragraph\Swift_ProductSpecification.cshtml:line 35 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 bool isVisualEditor = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("VisualEdit")) ? Convert.ToBoolean(Dynamicweb.Context.Current.Request.QueryString.Get("VisualEdit")) : false; 6 7 ProductViewModel product = new ProductViewModel(); 8 9 ProductViewModelSettings productSetting = new ProductViewModelSettings 10 { 11 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 12 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 13 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 14 ShopId = Pageview.Area.EcomShopId 15 }; 16 17 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 18 { 19 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 20 } 21 else if (Pageview.Item["DummyProduct"] != null) 22 { 23 24 string dummyProductId = ""; 25 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 26 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 27 if (productList.Products != null) 28 { 29 foreach (var p in productList.Products) { dummyProductId = p.Id; } 30 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 31 product = dummyProduct; 32 } 33 else 34 { 35 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 36 } 37 } 38 else if (Pageview.Item["DummyProduct"] == null) 39 { 40 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 41 } 42 } 43 44 @if (product?.Id != null) 45 { 46 IEnumerable<string> selectedDisplayGroupIds = Model.Item.GetRawValueString("DisplayGroups").Split(',').ToList(); 47 List<CategoryFieldViewModel> displayGroups = new List<CategoryFieldViewModel>(); 48 49 foreach (var selection in selectedDisplayGroupIds) 50 { 51 foreach (CategoryFieldViewModel group in product.FieldDisplayGroups.Values) 52 { 53 if (selection == group.Id) 54 { 55 int fieldsWithNoValueOrZero = 0; 56 57 foreach (var field in group.Fields) 58 { 59 if (string.IsNullOrEmpty(field.Value.Value.ToString())) 60 { 61 fieldsWithNoValueOrZero++; 62 } 63 } 64 65 if (fieldsWithNoValueOrZero != group.Fields.Count) 66 { 67 displayGroups.Add(group); 68 } 69 } 70 } 71 } 72 73 bool showProductFields = Model.Item.GetBoolean("ProductFields"); 74 75 bool hideTitle = Model.Item.GetBoolean("HideTitle"); 76 77 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 78 79 string titleFontSize = Model.Item.GetRawValueString("TitleFontSize", "display-4"); 80 81 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 82 contentPadding = contentPadding == "none" ? string.Empty : contentPadding; 83 contentPadding = contentPadding == "small" ? " p-2 p-md-3" : contentPadding; 84 contentPadding = contentPadding == "large" ? " p-4 p-md-5" : contentPadding; 85 86 string layout = Model.Item.GetRawValueString("Layout", "list"); 87 string size = Model.Item.GetRawValueString("Size", "full"); 88 string gaps = size == "full" ? " gap-4" : " gap-2"; 89 90 91 if (Pageview.IsVisualEditorMode && displayGroups.Count() == 0) 92 { 93 product.ProductFields.Clear(); 94 product.ProductFields.Add(Translate("Width"), new FieldValueViewModel { Name = Translate("Width"), Value = "99cm" }); 95 product.ProductFields.Add(Translate("Height"), new FieldValueViewModel { Name = Translate("Height"), Value = "195cm" }); 96 showProductFields = true; 97 } 98 99 if (layout == "commas") 100 { 101 gaps = size == "full" ? " gap-4" : " gap-2"; 102 103 } 104 105 <div class="h-100@(gaps)@(theme)@(contentPadding) item_@Model.Item.SystemName.ToLower()"> 106 <div class="grid"> 107 @if ((product.ProductFields != null && Model.Item.GetBoolean("ProductFields")) || (product.ProductCategories != null && Model.Item.GetBoolean("CategoryFields")) || (displayGroups.Count != 0)) { 108 if (!hideTitle) 109 { 110 <h2 class="g-col-12 @titleFontSize">@Model.Item.GetString("Title")</h2> 111 } 112 } 113 114 @if (displayGroups.Count != 0) 115 { 116 if (layout != "accordion") 117 { 118 foreach (var group in displayGroups) 119 { 120 bool hideHeader = Model.Item.GetBoolean("HideGroupHeaders"); 121 122 if (!hideHeader) { 123 <h4 class="g-col-12 h4 mb-0">@group.Name</h4> 124 } 125 126 { @RenderFieldsFromList(group.Fields, layout) } 127 128 } 129 } 130 else 131 { 132 <div class="g-col-12"> 133 <div class="accordion accordion-flush w-100" id="Specifications_@Model.ID"> 134 @foreach (var group in displayGroups) 135 { 136 <div class="accordion-item"> 137 <h2 class="accordion-header" id="SpecificationHeading_@group.Id"> 138 <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#SpecificationItem_@group.Id" aria-expanded="false" aria-controls="SpecificationItem_@group.Id"> 139 @group.Name 140 </button> 141 </h2> 142 <div id="SpecificationItem_@group.Id" class="accordion-collapse collapse" aria-labelledby="SpecificationHeading_@group.Id" data-bs-parent="#Specifications_@Model.ID"> 143 <div class="accordion-body"> 144 @{ @RenderFieldsFromList(group.Fields, "list") } 145 </div> 146 </div> 147 </div> 148 } 149 </div> 150 </div> 151 } 152 } 153 154 @if (product.ProductFields != null && showProductFields) 155 { 156 if (product.ProductFields.Count > 0) 157 { 158 if (layout != "accordion") 159 { 160 {@RenderFieldsFromList(product.ProductFields, layout) } 161 } 162 else 163 { 164 <div class="g-col-12"> 165 <div class="accordion accordion-flush w-100" id="Specifications_@Model.ID"> 166 <div class="accordion-item"> 167 <h2 class="accordion-header" id="SpecificationHeading_@Model.ID"> 168 <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#SpecificationItem_@Model.ID" aria-expanded="false" aria-controls="SpecificationItem_@Model.ID"> 169 @Translate("Specifications") 170 </button> 171 </h2> 172 <div id="SpecificationItem_@Model.ID" class="accordion-collapse" aria-labelledby="SpecificationHeading_@Model.ID" data-bs-parent="#Specifications_@Model.ID"> 173 <div class="accordion-body"> 174 @{ @RenderFieldsFromList(product.ProductFields, "List") } 175 </div> 176 </div> 177 </div> 178 </div> 179 </div> 180 } 181 } 182 } 183 184 @if (product.ProductCategories != null && Model.Item.GetBoolean("CategoryFields")) 185 { 186 if (product.ProductCategories.Count > 0) 187 { 188 if (layout != "accordion") 189 { 190 foreach (var group in product.ProductCategories) 191 { 192 CategoryFieldViewModel category = group.Value; 193 bool hideHeader = Model.Item.GetBoolean("HideGroupHeaders"); 194 195 if (!hideHeader) { 196 <h4 class="g-col-12 h4 mb-0">@group.Value.Name</h4> 197 } 198 199 { @RenderFieldsFromList(category.Fields, layout) } 200 } 201 } 202 else 203 { 204 <div class="g-col-12"> 205 <div class="accordion accordion-flush w-100" id="Specifications_@Model.ID"> 206 @foreach (var group in product.ProductCategories) 207 { 208 CategoryFieldViewModel category = group.Value; 209 210 <div class="accordion-item"> 211 <h2 class="accordion-header" id="SpecificationHeading_@group.Value.Id"> 212 <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#SpecificationItem_@group.Value.Id" aria-expanded="false" aria-controls="SpecificationItem_@group.Value.Id"> 213 @group.Value.Name 214 </button> 215 </h2> 216 <div id="SpecificationItem_@group.Value.Id" class="accordion-collapse" aria-labelledby="SpecificationHeading_@group.Value.Id" data-bs-parent="#Specifications_@Model.ID"> 217 <div class="accordion-body"> 218 @{ @RenderFieldsFromList(category.Fields, "list") } 219 </div> 220 </div> 221 </div> 222 } 223 </div> 224 </div> 225 } 226 } 227 } 228 </div> 229 </div> 230 } 231 else if (Pageview.IsVisualEditorMode) 232 { 233 <div class="alert alert-warning m-0">@Translate("No products available")</div> 234 } 235 236 @helper RenderFieldsFromList(Dictionary<string, FieldValueViewModel> fields, string layout) 237 { 238 string size = Model.Item.GetRawValueString("Size", "full"); 239 string gaps = size != "full" ? " gap-1" : string.Empty; 240 bool hideFieldLabels = Model.Item.GetBoolean("HideFieldLabels"); 241 bool hideFieldsWithZeroValue = Model.Item.GetBoolean("HideFieldsWithZeroValue"); 242 243 if (layout == "columns") { 244 <div class="g-col-12"> 245 <div class="grid@(gaps)"> 246 @foreach (var field in fields) 247 { 248 {@RenderField(field.Value, layout)} 249 } 250 </div> 251 </div> 252 } 253 if (layout == "list") { 254 <div class="g-col-12"> 255 <dl class="grid@(gaps)"> 256 @foreach (var field in fields) 257 { 258 {@RenderField(field.Value, layout)} 259 } 260 </dl> 261 </div> 262 } 263 if (layout == "table") 264 { 265 string tableSize = size == "full" ? "" : " table-sm"; 266 <div class="g-col-12"> 267 <table class="table table-striped@(tableSize)"> 268 @foreach (var field in fields) 269 { 270 {@RenderField(field.Value, layout)} 271 } 272 </table> 273 </div> 274 } 275 if (layout == "bullets") 276 { 277 string listSize = size == "full" ? "" : "m-0 p-0 lh-1 fs-7 opacity-75"; 278 string listStyle = size == "full" ? "" : "style=\"list-style-position: inside\""; 279 <div class="g-col-12"> 280 <ul class="@listSize" @listStyle> 281 @foreach (var field in fields) 282 { 283 {@RenderField(field.Value, layout)} 284 } 285 </ul> 286 </div> 287 } 288 if (layout == "commas") 289 { 290 List<string> featuresList = new List<string>(); 291 292 foreach (var field in fields) 293 { 294 string firstListItemValue = string.Empty; //Hack to support field type providers with a single value 295 296 if (field.Value?.Value != null) 297 { 298 if (field.Value.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) 299 { 300 System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; 301 302 //Hack to support field type providers with a single value 303 if (values.FirstOrDefault() != null) 304 { 305 firstListItemValue = values.FirstOrDefault().Value; 306 } 307 } 308 } 309 310 if (!hideFieldsWithZeroValue || (firstListItemValue != "0" && firstListItemValue != "0.0" && field.Value.Value.ToString() != "0" && field.Value.Value.ToString() != "0.0")) 311 { 312 if (field.Value.Value is object && !string.IsNullOrEmpty(field.Value.Value.ToString())) 313 { 314 if (field.Value.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) 315 { 316 List<string> options = new List<string>(); 317 foreach (FieldOptionValueViewModel option in field.Value.Value as System.Collections.Generic.List<FieldOptionValueViewModel>) 318 { 319 if (!string.IsNullOrWhiteSpace(option.Value)) 320 { 321 if (option.Value.ToString().Contains("#") && (Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) 322 { 323 string colorSpan = "<span class=\"colorbox-sm\" style=\"background-color: " + option.Value + "\"></span>"; 324 options.Add(colorSpan); 325 } 326 else if (!string.IsNullOrEmpty(option.Value)) 327 { 328 options.Add(option.Name); 329 } 330 } 331 } 332 string optionsString = (string.Join(", ", options.Select(x => x.ToString()).ToArray())); 333 if ((Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) 334 { 335 optionsString = (string.Join(" ", options.Select(x => x.ToString()).ToArray())); 336 } 337 338 if (!string.IsNullOrEmpty(optionsString)) 339 { 340 if (!hideFieldLabels) 341 { 342 featuresList.Add(field.Value.Name + ": " + optionsString); 343 } 344 else 345 { 346 featuresList.Add(optionsString); 347 } 348 } 349 } 350 else 351 { 352 if (!string.IsNullOrWhiteSpace(field.Value.Value.ToString())) 353 { 354 if (field.Value.Value.ToString().Contains("#") && (Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) 355 { 356 string colorSpan = "<span class=\"colorbox-sm\" style=\"background-color: " + field.Value.Value + "\"></span>"; 357 358 if (!hideFieldLabels) 359 { 360 featuresList.Add(field.Value.Name + ": " + colorSpan); 361 } 362 else 363 { 364 featuresList.Add(colorSpan); 365 } 366 } 367 else 368 { 369 if (!hideFieldLabels) 370 { 371 featuresList.Add(field.Value.Name + ": " + field.Value.Value.ToString()); 372 } 373 else 374 { 375 featuresList.Add(field.Value.Value.ToString()); 376 } 377 } 378 } 379 } 380 } 381 } 382 } 383 384 string featuresString = (string.Join(", ", featuresList.Select(x => x.ToString()).ToArray())); 385 386 <div class="g-col-12 opacity-75 fs-7">@featuresString</div> 387 } 388 } 389 390 @helper RenderField(FieldValueViewModel field, string layout) 391 { 392 string size = Model.Item.GetRawValueString("Size", "full"); 393 string fieldValue = field?.Value != null ? field.Value.ToString() : ""; 394 bool hideFieldLabels = Model.Item.GetBoolean("HideFieldLabels"); 395 bool noValues = false; 396 string firstListItemValue = string.Empty; //Hack to support field type providers with a single value 397 bool hideFieldsWithZeroValue = Model.Item.GetBoolean("HideFieldsWithZeroValue"); 398 399 if (!string.IsNullOrEmpty(fieldValue)) 400 { 401 if (field.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) 402 { 403 System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; 404 noValues = values.Count > 0 ? false : true; 405 406 //Hack to support field type providers with a single value 407 if (values.FirstOrDefault() != null) 408 { 409 firstListItemValue = values.FirstOrDefault().Value; 410 } 411 } 412 } 413 414 if (!string.IsNullOrEmpty(fieldValue) && noValues == false) 415 { 416 if (!hideFieldsWithZeroValue || (firstListItemValue != "0" && firstListItemValue != "0.0" && field.Value.ToString() != "0" && field.Value.ToString() != "0.0")) 417 { 418 if (layout == "columns") 419 { 420 421 <div class="grid g-col-6 g-col-lg-4 gap-1"> 422 @if (!hideFieldLabels) 423 { 424 <dt class="g-col-12 g-col-lg-4">@field.Name</dt> 425 } 426 <dd class="g-col-12 g-col-lg-8 mb-0 text-break"> 427 @{ @RenderFieldValue(field) } 428 </dd> 429 </div> 430 } 431 if (layout == "list") 432 { 433 if (!hideFieldLabels) 434 { 435 <dt class="g-col-4">@field.Name</dt> 436 } 437 <dd class="g-col-8 mb-0 text-break"> 438 @{ @RenderFieldValue(field) } 439 </dd> 440 } 441 if (layout == "table") 442 { 443 <tr> 444 @if (!hideFieldLabels) 445 { 446 <th class="w-25 w-lg-50" scope="row">@field.Name</th> 447 } 448 <td class="text-break"> 449 @{ @RenderFieldValue(field) } 450 </td> 451 </tr> 452 } 453 if (layout == "bullets") 454 { 455 <li> 456 @if (!hideFieldLabels) 457 { 458 <strong>@field.Name</strong> 459 } 460 <span> 461 @{ @RenderFieldValue(field) } 462 </span> 463 </li> 464 } 465 } 466 } 467 } 468 469 @helper RenderFieldValue(FieldValueViewModel field) 470 { 471 string fieldValue = field?.Value != null ? field.Value.ToString() : ""; 472 473 bool isLink = field?.Type == "Link"; 474 bool isColor = false; 475 bool isBrandName = field?.SystemName == "Brand_name"; 476 477 fieldValue = fieldValue == "False" ? Translate("No") : fieldValue; 478 fieldValue = fieldValue == "True" ? Translate("Yes") : fieldValue; 479 480 481 if (field.Value.GetType() == typeof(System.Collections.Generic.List<Dynamicweb.Ecommerce.ProductCatalog.FieldOptionValueViewModel>)) 482 { 483 int valueCount = 0; 484 System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; 485 int totalValues = values.Count; 486 487 foreach (FieldOptionValueViewModel option in values) 488 { 489 if (!string.IsNullOrEmpty(option.Value)) 490 { 491 if (option.Value.Substring(0, 1) == "#") 492 { 493 isColor = true; 494 } 495 } 496 497 if (!isColor) 498 { 499 @option.Name 500 } 501 else 502 { 503 <span class="colorbox-sm" style="background-color: @option.Value" title="@option.Name"></span> 504 } 505 506 if (valueCount != totalValues && valueCount < (totalValues - 1)) 507 { 508 if (isColor) 509 { 510 <text> </text> 511 } 512 else 513 { 514 <text>, </text> 515 } 516 } 517 valueCount++; 518 } 519 } 520 else 521 { 522 if (fieldValue.Substring(0, 1) == "#") 523 { 524 isColor = true; 525 } 526 527 if (!isColor) 528 { 529 if (isLink) 530 { 531 string linktTitle = !fieldValue.Contains("aspx") ? fieldValue : Translate("Go to link"); 532 string target = Pageview.AreaSettings.GetBoolean("OpenLinksInNewTab") && fieldValue.Contains("http") ? "target=\"_blank\"" : string.Empty; 533 string rel = Pageview.AreaSettings.GetBoolean("OpenLinksInNewTab") && fieldValue.Contains("http") ? "rel=\"noopener\"" : string.Empty; 534 535 <a href="@field.Value" title="@field.Name" @target @rel>@linktTitle</a> 536 } 537 else if (isBrandName) 538 { 539 <span itemprop="brand" itemtype="https://schema.org/Brand" itemscope> 540 <span itemprop="name">@fieldValue</span> 541 </span> 542 } 543 else 544 { 545 @fieldValue 546 } 547 548 } 549 else 550 { 551 <span class="colorbox-sm" style="background-color: @fieldValue" title="@fieldValue"></span> 552 } 553 } 554 } 555
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_ProductStock.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at CompiledRazorTemplates.Dynamic.RazorEngine_c8b79ca4b2c442d680686ad1fc37dcd3.Execute() in H:\Solutions\Hamonoya\Files\Templates\Designs\Swift\Paragraph\Swift_ProductStock.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 bool IsNeverOutOfStock = product.NeverOutOfstock; 36 37 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 38 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 39 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 40 bool hasExpectedDelivery = product.ExpectedDelivery != null && product.ExpectedDelivery > DateTime.Now; 41 string expectedDeliveryDate = product.ExpectedDelivery?.ToShortDateString() ?? ""; 42 43 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 44 bool hideStock = Model.Item.GetBoolean("HideStockState") || (Pageview.AreaSettings.GetBoolean("ErpDownHideStock") && isErpConnectionDown); 45 46 string liveInfoClass = ""; 47 string productInfoFeed = ""; 48 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 49 if (isLazyLoadingForProductInfoEnabled) 50 { 51 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 52 { 53 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 54 if (!string.IsNullOrEmpty(productInfoFeed)) 55 { 56 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 57 } 58 } 59 liveInfoClass = "js-live-info"; 60 } 61 } 62 63 @if (!hideStock) 64 { 65 if (!IsNeverOutOfStock && product.Id != null) { 66 if (isLazyLoadingForProductInfoEnabled) 67 { 68 string hideStockState = string.IsNullOrEmpty(product.VariantId) && product.VariantInfo.VariantInfo != null ? "d-none" : ""; 69 <div class="js-stock-state @horizontalAlign item_@Model.Item.SystemName.ToLower() @liveInfoClass" data-product-id="@product.Id" @productInfoFeed> 70 <div class="mt-3 js-stock-state spinner-border @hideStockState"> 71 @if (!Model.Item.GetBoolean("HideInventory")) 72 { 73 <div class="small text-success d-none" data-show-if="LiveProductInfo.product.StockLevel > 0"> 74 <span class="js-text-stock"></span> 75 @Translate("In stock") 76 </div> 77 } 78 else 79 { 80 <div class="small text-success d-none" data-show-if="LiveProductInfo.product.StockLevel > 0">@Translate("In stock")</div> 81 } 82 <div class="small text-danger d-none" data-show-if="LiveProductInfo.product.StockLevel <= 0">@Translate("Out of Stock")</div> 83 84 <div class="d-none" data-show-if="LiveProductInfo.product.ExpectedDelivery != null && new Date(LiveProductInfo.product.ExpectedDelivery) > new Date()"> 85 <span>@Translate("Expected back in stock"): </span> 86 <span class="js-text-expected-delivery"></span> 87 </div> 88 </div> 89 </div> 90 } 91 else 92 { 93 string firstUnitId = product?.UnitOptions?.FirstOrDefault() != null ? product.UnitOptions.FirstOrDefault().Id : ""; 94 string defaultUnitId = !string.IsNullOrEmpty(product.DefaultUnitId) ? product.DefaultUnitId : firstUnitId; 95 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : defaultUnitId; 96 97 var reserveMode = Dynamicweb.Ecommerce.Frontend.Cart.ProductReserve.Mode; 98 double? reservedAmount = 0; 99 if (reserveMode == Dynamicweb.Ecommerce.Frontend.Cart.ProductReserveMode.AddToCart) { 100 reservedAmount = Dynamicweb.Ecommerce.Frontend.Cart.ProductReserve.GetReservedAmount(product.Id, product.VariantId, 0, unitId); 101 } 102 double? currentStockLevel = product.StockLevel - reservedAmount; 103 104 <div class="js-stock-state @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 105 @if (currentStockLevel > 0) 106 { 107 if (!Model.Item.GetBoolean("HideInventory")) 108 { 109 <div class="small text-success"><span class="js-text-stock">@currentStockLevel</span> @Translate("In stock")</div> 110 } 111 else 112 { 113 <div class="small text-success">@Translate("In stock")</div> 114 } 115 } 116 else 117 { 118 <div class="small text-danger">@Translate("Out of Stock")</div> 119 } 120 121 @if (hasExpectedDelivery) 122 { 123 <div> 124 <span>@Translate("Expected in stock"): </span> 125 <span>@expectedDeliveryDate</span> 126 </div> 127 } 128 129 </div> 130 } 131 } else if (Pageview.IsVisualEditorMode) { 132 <div class="alert alert-info">@Translate("No products available")</div> 133 } 134 } 135
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