Component builder for: Product Details Area

Error executing template "Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_aca7a20c04c041febb62bd40fb1fd47f.Execute() in C:\inetpub\solutions\Goecker-2022-Staging\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 75
   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 @using System.Linq 5 @using Dynamicweb.Core 6 @using NLWI.Core.Factory 7 @using NLWI.Platforms.Dynamicweb9.Specs.ViewModels 8 @using NLWI.Platforms.Dynamicweb9.Specs.Services 9 @using NORRIQ.CustomCode.Razor 10 @using NORRIQ.CustomCode.StockLocations 11 @using System.Text; 12 @using System.Web; 13 14 @* CUSTOMIZED STANDARD SWIFT (v1.15.0) TEMPLATE *@ 15 16 @{ 17 ProductViewModel product = new ProductViewModel(); 18 19 ProductViewModelSettings productSetting = new ProductViewModelSettings 20 { 21 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 22 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 23 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 24 ShopId = Pageview.Area.EcomShopId 25 }; 26 27 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 28 { 29 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 30 } 31 else if (Pageview.Item["DummyProduct"] != null) 32 { 33 34 string dummyProductId = ""; 35 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 36 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 37 if (productList.Products != null) 38 { 39 foreach (var p in productList.Products) { dummyProductId = p.Id; } 40 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 41 product = dummyProduct; 42 } 43 else 44 { 45 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 46 } 47 } 48 else if (Pageview.Item["DummyProduct"] == null) 49 { 50 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 51 } 52 53 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 54 bool anonymousUser = Pageview.User == null; 55 bool isErpConnectionDown = !Dynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplatesHelper.IsWebServiceConnectionAvailable(); 56 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 57 58 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "fs-2"); 59 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 60 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 61 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 62 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 63 64 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 65 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 66 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 67 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 68 69 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 70 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 71 string order = layout == "horizontal" ? string.Empty : "order-2"; 72 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "px-2 theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 73 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 74 75 var disablePrice = product.ProductFields.ContainsKey("Custom_DisablePrice") ? Convert.ToBoolean(product.ProductFields["Custom_DisablePrice"].Value) : false; //CUSTOM 76 } 77 78 @if (!hidePrice && product.Id != null && !disablePrice) //CUSTOM 79 { 80 string showPricesWithVat = HttpContext.Current.Session["Smartpage:ShowPricesWithVat"] != null ? Convert.ToString(HttpContext.Current.Session["Smartpage:ShowPricesWithVat"]) : Pageview.Area.EcomPricesWithVat.ToLower(); 81 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 82 83 string priceMin = ""; 84 string priceMax = ""; 85 86 string liveInfoClass = ""; 87 string productInfoFeed = ""; 88 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplatesHelper.IsLazyLoadingForProductInfoEnabled; 89 if (isLazyLoadingForProductInfoEnabled) 90 { 91 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 92 { 93 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 94 if (!string.IsNullOrEmpty(productInfoFeed)) 95 { 96 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 97 } 98 } 99 liveInfoClass = "js-live-info"; 100 } 101 102 FieldValueViewModel fieldValueViewModel = null; 103 product.ProductFields.TryGetValue("SchillingShowBeforePrice", out fieldValueViewModel); 104 bool showBeforePrice = fieldValueViewModel != null ? Converter.ToBoolean(fieldValueViewModel.Value) : false; 105 106 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" @productInfoFeed> 107 <div class="@priceFontSize m-0 d-flex @flexDirection @flexGap @horizontalAlign" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 108 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 109 110 @if (showPricesWithVat == "false" && !neverShowVat) 111 { 112 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 113 { 114 <span itemprop="price" content="" class="d-none"></span> 115 <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> 116 } 117 else 118 { 119 string beforePrice = product.PriceBeforeDiscount.PriceWithoutVatFormatted; 120 string informativePrice = product.PriceInformative.PriceWithoutVatFormatted; 121 122 <span itemprop="price" content="@product.Price.PriceWithoutVat" class="d-none"></span> 123 if (product.Price.Price != product.PriceBeforeDiscount.Price) 124 { 125 <span class="text-decoration-line-through opacity-75 @order">@beforePrice</span> 126 } 127 else if (product.PriceInformative.Price > 0) 128 { 129 <span class="text-decoration-line-through opacity-75 @order">@informativePrice</span> 130 } 131 } 132 } 133 else 134 { 135 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 136 { 137 <span itemprop="price" content="" class="d-none"></span> 138 <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> 139 } 140 else 141 { 142 string beforePrice = product.PriceBeforeDiscount.PriceFormatted; 143 string informativePrice = product.PriceInformative.PriceFormatted; 144 145 <span itemprop="price" content="@product.Price.Price" class="d-none"></span> 146 147 if (product.Price.Price != product.PriceBeforeDiscount.Price) 148 { 149 <span class="text-decoration-line-through opacity-75 @order"> 150 <span class="text-price">@beforePrice</span> 151 </span> 152 } 153 else if (product.PriceInformative.Price > 0) 154 { 155 <span class="text-decoration-line-through opacity-75 @order"> 156 <span class="text-price">@informativePrice</span> 157 </span> 158 } 159 } 160 } 161 162 @if (showPricesWithVat == "false" && !neverShowVat) 163 { 164 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 165 { 166 <span class="text-price js-text-price"> 167 <div class="spinner-border" role="status"></div> 168 </span> 169 } 170 else 171 { 172 string price = product.Price.PriceWithoutVatFormatted; 173 if (product?.VariantInfo?.VariantInfo != null) 174 { 175 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 176 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 177 } 178 if (priceMin != priceMax) 179 { 180 price = priceMin + " - " + priceMax; 181 } 182 <span class="@theme"> 183 <span class="text-price">@price</span> 184 </span> 185 } 186 } 187 else 188 { 189 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 190 { 191 <span class="text-price js-text-price"> 192 <div class="spinner-border" role="status"></div> 193 </span> 194 } 195 else 196 { 197 string price = product.Price.PriceFormatted; 198 if (product?.VariantInfo?.VariantInfo != null) 199 { 200 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 201 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 202 } 203 if (priceMin != priceMax) 204 { 205 price = priceMin + " - " + priceMax; 206 } 207 <span class="@theme"> 208 <span class="text-price">@price</span> 209 </span> 210 } 211 } 212 213 @* Stock state for Schema.org, start *@ 214 @{ 215 Uri url = Dynamicweb.Context.Current.Request.Url; 216 } 217 218 <link itemprop="url" href="@url"> 219 220 @{ 221 bool IsNeverOutOfStock = product.NeverOutOfstock; 222 } 223 224 @if (IsNeverOutOfStock) 225 { 226 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 227 } 228 else 229 { 230 if (product.StockLevel > 0) 231 { 232 <span itemprop="availability" class="d-none">InStock</span> 233 } 234 else 235 { 236 <span itemprop="availability" class="d-none">OutOfStock</span> 237 } 238 } 239 @* Stock state for Schema.org, stop *@ 240 241 </div> 242 243 @if (showPricesWithVat == "false" && !neverShowVat) 244 { 245 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 246 { 247 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate(" Incl. VAT")"></small> 248 } 249 else 250 { 251 string price = product.Price.PriceWithVatFormatted; 252 if (product?.VariantInfo?.VariantInfo != null) 253 { 254 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 255 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 256 } 257 if (priceMin != priceMax) 258 { 259 price = priceMin + " - " + priceMax; 260 } 261 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 262 } 263 } 264 </div> 265 } 266 else if (Pageview.IsVisualEditorMode) 267 { 268 <div class="alert alert-dark m-0" role="alert"> 269 <span>@Translate("No products available")</span> 270 </div> 271 } 272
Error executing template "Designs/Swift/Paragraph/Swift_ProductBrandImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at NORRIQ.CustomCode.Razor.ProductViewModelExtensions.GetAutoId(ProductViewModel product) in D:\a\1\s\NORRIQ.CustomCode\Razor\ProductViewModelExtensions.cs:line 47
   at CompiledRazorTemplates.Dynamic.RazorEngine_4b253ad9a5ce46fd8fde35075a7a589b.Execute() in C:\inetpub\solutions\Goecker-2022-Staging\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBrandImage_Custom.cshtml:line 49
   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 @using ProductExtensions = NORRIQ.CustomCode.Razor.ProductViewModelExtensions; 5 @using NLWI.Platforms.Dynamicweb9.Specs.Services 6 @using NORRIQ.Common8.Factory 7 @using System.Web 8 9 @* CUSTOM TEMPLATE SUPPORTED BY SWIFT (v1.15.0) *@ 10 11 @{ 12 ProductViewModel product = new ProductViewModel(); 13 14 ProductViewModelSettings productSetting = new ProductViewModelSettings 15 { 16 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 17 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 18 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 19 ShopId = Pageview.Area.EcomShopId 20 }; 21 22 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 23 { 24 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 25 } 26 else if (Pageview.Item["DummyProduct"] != null) 27 { 28 string dummyProductId = ""; 29 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 30 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 31 if (productList.Products != null) 32 { 33 foreach (var p in productList.Products) { dummyProductId = p.Id; } 34 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 35 product = dummyProduct; 36 } 37 else 38 { 39 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 40 } 41 } 42 else if (Pageview.Item["DummyProduct"] == null) 43 { 44 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 45 } 46 47 //Using old norriq code, is specificationService is removed from the project, change where we get the brand logo from 48 var specificationService = ObjectFactory.GetInstance<ProductSpecificationService>(); 49 var specs = specificationService.GetProductSpecifications(ProductExtensions.GetAutoId(product)); 50 51 string imagePath = specs.HasKey("Brandlogo") ? specs.GetByKey("Brandlogo").Value : ""; 52 imagePath = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 53 54 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 55 ratio = ratio != "0" ? ratio : ""; 56 string ratioCssClass = ratio != "" ? " ratio" : ""; 57 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 58 59 string width = Model.Item.GetRawValueString("Width", "auto"); 60 int smallImageSize = 640; 61 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 62 63 string imagePathXs = "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePath + "&format=webp"; 64 string imagePathS = "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePath + "&format=webp"; 65 string imagePathFallBack = "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePath + "&format=webp"; 66 } 67 68 @if (product.Id != null) 69 { 70 string fullWidth = width == "auto" ? "w-100" : ""; 71 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 72 if (!string.IsNullOrEmpty(imagePath)) 73 { 74 <div class="h-100 @fullWidth position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 75 <div class="ratio" style="@(ratioVariable)"> 76 <div class="d-flex justify-content-center align-items-center"> 77 <img id="brandlogo" 78 srcset=" 79 @imagePathXs @(smallImageSize)w, 80 @imagePathS @(largeImageSize)w" 81 sizes="(min-width: 992px) 33vw, 50vw" 82 src="@imagePathFallBack" 83 loading="lazy" 84 decoding="async" 85 class="h-100 w-100" 86 style="object-fit: contain;" 87 alt="@HttpUtility.HtmlAttributeEncode(specs.HasKey("Brandlogo") ? specs.GetByKey("Brandlogo").Caption : "")"> 88 </div> 89 </div> 90 </div> 91 } 92 } 93 else if (Pageview.IsVisualEditorMode) 94 { 95 <div class="alert alert-dark m-0">@Translate("No products available")</div> 96 } 97
Error executing template "Designs/Swift/Paragraph/Swift_ProductShipPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_12ace19720724d6eabd0e6170c5d4cff.Execute() in C:\inetpub\solutions\Goecker-2022-Staging\Files\Templates\Designs\Swift\Paragraph\Swift_ProductShipPrice_Custom.cshtml:line 44
   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 @using NORRIQ.CustomCode.Razor 5 6 @* CUSTOM TEMPLATE SUPPORTED BY SWIFT (v1.15.0) *@ 7 8 @{ 9 ProductViewModel product = new ProductViewModel(); 10 11 ProductViewModelSettings productSetting = new ProductViewModelSettings 12 { 13 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 14 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 15 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 16 ShopId = Pageview.Area.EcomShopId 17 }; 18 19 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 20 { 21 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 22 } 23 else if (Pageview.Item["DummyProduct"] != null) 24 { 25 string dummyProductId = ""; 26 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 27 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 28 if (productList.Products != null) 29 { 30 foreach (var p in productList.Products) { dummyProductId = p.Id; } 31 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 32 product = dummyProduct; 33 } 34 else 35 { 36 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 37 } 38 } 39 else if (Pageview.Item["DummyProduct"] == null) 40 { 41 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 42 } 43 44 var disablePrice = product.ProductFields.ContainsKey("Custom_DisablePrice") ? Convert.ToBoolean(product.ProductFields["Custom_DisablePrice"].Value) : false; //CUSTOM 45 } 46 47 @if (product.Id != null && !disablePrice) //CUSTOM 48 { 49 <div class="position-relative js-shipping-container shipping-container"> 50 <p class="cursor-pointer mb-0 fs-7 text-decoration-underline-hover" onclick="calculateShipping(this.getAttribute('data-product-key'))" data-product-key=@product.GetJsonPriceKey(Dynamicweb.Ecommerce.Common.Context.Currency.Code)>@Translate("Beregn pris inkl. fragt")</p> 51 <div class="js-shipping-info shipping-info d-none position-absolute shadow bg-white"> 52 <div class="d-flex justify-content-between p-2 fs-7 border-bottom"> 53 <span>@Translate("Produktpris")</span> 54 <span class="js-shipping-product-price"></span> 55 </div> 56 <div class="d-flex justify-content-between p-2 fs-7 border-bottom"> 57 <span>@Translate("Fragt")</span> 58 <span class="js-shipping-cost"></span> 59 </div> 60 <div class="d-flex justify-content-between p-2 fs-7 border-bottom"> 61 <span>@Translate("Moms")</span> 62 <span class="js-shipping-vat"></span> 63 </div> 64 <div class="d-flex justify-content-between p-2 fs-7 border-bottom"> 65 <span class="fw-bold">@Translate("I alt")</span> 66 <span class="js-shipping-total fw-bold"></span> 67 </div> 68 </div> 69 </div> 70 } 71
Error executing template "Designs/Swift/Paragraph/Swift_ProductLeasingButton_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at NORRIQ.CustomCode.Razor.ProductViewModelExtensions.GetAutoId(ProductViewModel product) in D:\a\1\s\NORRIQ.CustomCode\Razor\ProductViewModelExtensions.cs:line 47
   at CompiledRazorTemplates.Dynamic.RazorEngine_35abf81ea04a46b6bb5cb584602c3c04.Execute() in C:\inetpub\solutions\Goecker-2022-Staging\Files\Templates\Designs\Swift\Paragraph\Swift_ProductLeasingButton_Custom.cshtml:line 51
   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 @using ProductExtensions = NORRIQ.CustomCode.Razor.ProductViewModelExtensions; 5 @using NLWI.Platforms.Dynamicweb9.Specs.Services 6 @using NORRIQ.Common8.Factory 7 @using NORRIQ.CustomCode.Pricing 8 @using NORRIQ.CustomCode.Razor 9 @using System.Web 10 11 @* CUSTOM TEMPLATE SUPPORTED BY SWIFT (v1.15.0) *@ 12 13 @{ 14 ProductViewModel product = new ProductViewModel(); 15 16 ProductViewModelSettings productSetting = new ProductViewModelSettings 17 { 18 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 19 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 20 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 21 ShopId = Pageview.Area.EcomShopId 22 }; 23 24 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 25 { 26 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 27 } 28 else if (Pageview.Item["DummyProduct"] != null) 29 { 30 string dummyProductId = ""; 31 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 32 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 33 if (productList.Products != null) 34 { 35 foreach (var p in productList.Products) { dummyProductId = p.Id; } 36 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 37 product = dummyProduct; 38 } 39 else 40 { 41 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 42 } 43 } 44 else if (Pageview.Item["DummyProduct"] == null) 45 { 46 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 47 } 48 49 //Using old norriq code, is specificationService is removed from the project, change where we get the data from 50 var specificationService = ObjectFactory.GetInstance<ProductSpecificationService>(); 51 var productSpecs = specificationService.GetProductSpecifications(ProductExtensions.GetAutoId(product)); 52 53 var showPricesWithVat = HttpContext.Current.Session["Smartpage:ShowPricesWithVat"] != null ? Convert.ToString(HttpContext.Current.Session["Smartpage:ShowPricesWithVat"]) : Pageview.Area.EcomPricesWithVat.ToLower(); 54 55 var productPrices = ObjectFactory.GetInstance<PriceService>().GetPrices(new[] { product.GetAutoId() }); 56 var productPrice = productPrices[product.GetAutoId()]; 57 58 var leasingPrice = product.GetLeasingPrice(productPrice); 59 var leasingAllowed = productSpecs.GetAllByKey("AllowLeasing").Any(a => a.Value.IsYes()) && showPricesWithVat == "false" && leasingPrice.HasValue; 60 } 61 62 @if (product.Id != null) 63 { 64 if (leasingAllowed) 65 { 66 <div class="d-flex flex-column"> 67 @if (Model.Item.GetBoolean("ShowLeasingPrice")) 68 { 69 <p class="mb-2 product-leasing-price">@Translate("Leasing 36 mnd:") <span class="fw-bold">@Dynamicweb.Ecommerce.Services.Currencies.FormatCurrency(Dynamicweb.Ecommerce.Common.Context.Currency, leasingPrice.Value, true)</span> @Translate("eksl. moms pr.mnd.")</p>} 70 @if (Model.Item.GetBoolean("ShowLeasingButton")) 71 { 72 <button class="btn btn-outline-primary" onclick="Form(this).addData('@HttpUtility.HtmlEncode(product.Name)', '@product.Id')" data-bs-toggle="modal" data-bs-target="#leasingModal">@Translate("Ansøg leasing (uforpligtende)")</button> 73 } 74 </div> 75 } 76 else if (Pageview.IsVisualEditorMode) 77 { 78 <div class="d-flex flex-column"> 79 @if (Model.Item.GetBoolean("ShowLeasingPrice")) 80 { 81 <p class="mb-2 product-leasing-price">@Translate("Leasing 36 mnd:") <span class="fw-bold">xxxx.xx</span> @Translate("eksl. moms pr.mnd.")</p> 82 } 83 @if (Model.Item.GetBoolean("ShowLeasingButton")) 84 { 85 <button class="btn btn-outline-primary">@Translate("Visual Editor Mode: Placeholder, no leasing on product")</button> 86 } 87 @if (!Model.Item.GetBoolean("ShowLeasingButton") && !Model.Item.GetBoolean("ShowLeasingPrice")) 88 { 89 <button class="btn btn-outline-primary">@Translate("Visual Editor Mode: Placeholder, neither price or button turned selected")</button> 90 } 91 </div> 92 } 93 } 94 else if (Pageview.IsVisualEditorMode) 95 { 96 <div class="alert alert-dark m-0">@Translate("No products available")</div> 97 } 98
Error executing template "Designs/Swift/Paragraph/Swift_ProductAddToCart_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_3eff7ca29ace4439b4fedd4cd40f89c9.Execute() in C:\inetpub\solutions\Goecker-2022-Staging\Files\Templates\Designs\Swift\Paragraph\Swift_ProductAddToCart_Custom.cshtml:line 58
   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 @using NLWI.Core.Factory 5 @using NLWI.Platforms.Dynamicweb9.Specs.Services 6 @using NORRIQ.CustomCode.Razor 7 @using System.Web 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.15.0) TEMPLATE *@ 10 @* NOTE: Item contains unsupported itemfields: ShowAddToFavorites, ShowFavoritesSelectorMasterProduct, ShowQuantitySelector, ShowUnitsSelector, WhenVariantsExist, HideButtonText, Icon, ButtonSize, HideInventory, HideStockState, VariantSelectorServicePageId *@ 11 12 @{ 13 ProductViewModel product = new ProductViewModel(); 14 15 ProductViewModelSettings productSetting = new ProductViewModelSettings 16 { 17 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 18 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 19 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 20 ShopId = Pageview.Area.EcomShopId 21 }; 22 23 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 24 { 25 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 26 } 27 else if (Pageview.Item["DummyProduct"] != null) 28 { 29 30 string dummyProductId = ""; 31 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 32 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 33 if (productList.Products != null) 34 { 35 foreach (var p in productList.Products) { dummyProductId = p.Id; } 36 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 37 product = dummyProduct; 38 } 39 else 40 { 41 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 42 } 43 } 44 else if (Pageview.Item["DummyProduct"] == null) 45 { 46 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 47 } 48 49 string fullWidth = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "w-100" : ""; 50 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 51 horizontalAlign = horizontalAlign == "center" ? "justify-content-center" : horizontalAlign; 52 horizontalAlign = horizontalAlign == "end" ? "justify-content-end" : horizontalAlign; 53 horizontalAlign = horizontalAlign == "full" ? "" : horizontalAlign; 54 55 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 56 bool anonymousUser = Pageview.User == null; 57 bool hideAddToCart = anonymousUsersLimitations.Contains("cart") && anonymousUser; 58 hideAddToCart = product.VariantInfo.VariantInfo != null && Model.Item.GetBoolean("CustomHideVariantSelector") ? true : hideAddToCart; 59 hideAddToCart = product.ProductFields.ContainsKey("Custom_DisablePurchase") ? Convert.ToBoolean(product.ProductFields["Custom_DisablePurchase"].Value) : hideAddToCart; //CUSTOM 60 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser; 61 bool hideFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("CustomHideFavoritesSelector")) ? Model.Item.GetBoolean("CustomHideFavoritesSelector") : false; 62 63 var favoriteParameters = new Dictionary<string, object>(); 64 if (!anonymousUser && !hideFavoritesSelector) 65 { 66 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 67 int defaultFavoriteListId = 0; 68 69 if (favoreiteLists.Count() == 1) 70 { 71 foreach (FavoriteList list in favoreiteLists) 72 { 73 defaultFavoriteListId = list.ListId; 74 } 75 } 76 77 favoriteParameters.Add("ListId", defaultFavoriteListId); 78 } 79 } 80 81 @if (!hideAddToCart && product.Id != null) 82 { 83 string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 84 if (!url.Contains("LayoutTemplate")) 85 { 86 url += url.Contains("?") ? "&LayoutTemplate=Swift_MiniCart.cshtml" : "?LayoutTemplate=Swift_MiniCart.cshtml"; 87 } 88 89 var productSpecificationService = ObjectFactory.GetInstance<IProductSpecificationService>(); 90 var productSpecs = productSpecificationService.GetProductSpecifications(product.GetAutoId()); 91 92 string flexFill = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "flex-fill" : ""; 93 94 string minQty = product.PurchaseMinimumQuantity != 1 ? "min=\"" + product.PurchaseMinimumQuantity.ToString() + "\"" : "min=\"1\""; 95 string stepQty = product.PurchaseQuantityStep > 1 ? product.PurchaseQuantityStep.ToString() : "1"; 96 string valueQty = product.PurchaseMinimumQuantity > product.PurchaseQuantityStep ? product.PurchaseMinimumQuantity.ToString() : stepQty; 97 string qtyValidCheck = stepQty != "1" ? "onkeyup=\"swift.Cart.QuantityValidate(event)\"" : ""; 98 99 <div class="d-flex @horizontalAlign @fullWidth item_@Model.Item.SystemName.ToLower()"> 100 <form method="post" action="@url" class="@fullWidth"> 101 <input type="hidden" name="redirect" value="false" /> 102 <input type="hidden" name="ProductId" value="@product.Id" /> 103 <input type="hidden" name="cartcmd" value="add" /> 104 105 <input type="hidden" class="js-product-id" value="@product.Id" /> 106 107 @if (!string.IsNullOrEmpty(product.VariantId)) 108 { 109 <input type="hidden" name="VariantId" value="@product.VariantId" /> 110 } 111 @if (!Model.Item.GetBoolean("CustomUseQuantitySelector")) 112 { 113 <input id="Quantity_@product.Id" name="Quantity" value="@valueQty" type="hidden"> 114 115 if (!productSpecs.GetByKey("Preorder").Value.IsYes()) 116 { 117 <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary w-100 js-add-to-cart-button" title="@HttpUtility.HtmlEncode(Translate("Add to cart"))" id="AddToCartButton@(product.Id)">@Translate("Add to cart")</button> 118 } 119 else 120 { 121 <button type="button" class="btn btn-secondary w-100 text-uppercase" onclick="Form(this).addData('@HttpUtility.HtmlEncode(product.Name)', '@product.Id')" data-bs-toggle="modal" data-bs-target="#preorderModal"> 122 @Translate("Preorder") 123 </button> 124 } 125 } 126 else 127 { 128 <div class="input-group input-primary-button-group js-input-group d-flex flex-row flex-nowrap"> 129 <label for="Quantity_@(product.Id)" class="visually-hidden">@Translate("Quantity")</label> 130 <input id="Quantity_@product.Id" name="Quantity" value="@valueQty" step="@stepQty" @minQty class="form-control" style="max-width: 96px; min-width:64px;" type="number"> 131 <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary flex-fill js-add-to-cart-button" title="@Translate("Add to cart")" id="AddToCartButton@(product.Id)">@Translate("Add to cart")</button> 132 </div> 133 134 if (stepQty != "1") 135 { 136 <div class="invalid-feedback d-none"> 137 @Translate("Please select a quantity that is dividable by") @stepQty 138 </div> 139 } 140 } 141 </form> 142 @if (!anonymousUser && !hideFavoritesSelector) 143 { 144 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 145 } 146 </div> 147 } 148 else if (!anonymousUser && !hideFavoritesSelector) 149 { 150 <div class="d-flex @horizontalAlign @fullWidth item_@Model.Item.SystemName.ToLower()"> 151 <div class="flex-fill"> 152 @Translate("Add to favorites") @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 153 </div> 154 </div> 155 } 156 else if (Pageview.IsVisualEditorMode) 157 { 158 <div class="alert alert-dark m-0">@Translate("No products available")</div> 159 } 160
Error executing template "Designs/Swift/Paragraph/Swift_StockStatus.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_8184e193a97b46ee9980ae8b587d6291.Execute() in C:\inetpub\solutions\Goecker-2022-Staging\Files\Templates\Designs\Swift\Paragraph\Swift_StockStatus.cshtml:line 46
   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 @* CUSTOMIZED SWIFT TEMPLATE *@ 5 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.GetAllProducts(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.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 41 } 42 43 bool IsNeverOutOfStock = product.NeverOutOfstock; 44 var stockLocations = product.StockUnits; 45 46 var disableStock = product.ProductFields.ContainsKey("Custom_DisableStock") ? Convert.ToBoolean(product.ProductFields["Custom_DisableStock"].Value) : false; //CUSTOM 47 48 if (!Model.Item.GetBoolean("HideStockState") && !disableStock) //CUSTOM 49 { 50 if (!IsNeverOutOfStock) 51 { 52 <div class="mt-3 js-stock-state d-flex flex-column gap-2"> 53 <ul class="list-group"> 54 @foreach (var stockLocation in stockLocations) 55 { 56 if (stockLocation != null) 57 { 58 var locationName = stockLocation.StockLocationName; 59 var qty = stockLocation.StockLevel; 60 <li class="list-group-item"> 61 62 <div class="product-stock-item d-flex justify-content-between"> 63 <span class="product-stock-location fs-7"> 64 @locationName 65 </span> 66 <span class="product-stock-status fs-7"> 67 <span class="icon-stock @(qty > 0 ? "icon-green" : "icon-red") position-relative"></span> 68 @(qty > 0 ? Translate("label_in_Stock", "På lager") : Translate("label_not_in_stock", "Ikke på lager")) 69 </span> 70 </div> 71 </li> 72 } 73 } 74 </ul> 75 </div> 76 } 77 } 78 }