Component builder for: Product detail

Error executing template "Designs/Swift/Paragraph/Swift_ProductPriceTable.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_8724cc9db83d41f891ff7d7ea0ba5d43.Execute() in F:\Domains\Sites\qa-qos.mydwsite3.com\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPriceTable.cshtml:line 26
   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 = null; 6 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 7 { 8 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 9 } 10 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 11 { 12 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 13 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 14 15 if (productList?.Products is object) 16 { 17 product = productList.Products[0]; 18 } 19 } 20 21 bool showZeroPrice = Model.Item.GetString("ShowPrice") == "show"; 22 23 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 24 bool anonymousUser = Pageview.User == null; 25 bool isLazyLoadingForProductInfoEnabled = Dna.Ecommerce.LiveIntegration.TemplatesHelper.IsLazyLoadingForProductInfoEnabled; 26 bool hidePrice = (anonymousUsersLimitations.Contains("price") && anonymousUser) || (product.Price.Price <= 0 && !isLazyLoadingForProductInfoEnabled); 27 hidePrice = Pageview.IsVisualEditorMode ? false : hidePrice; 28 } 29 30 @if (product is object && !hidePrice) 31 { 32 if (Pageview.IsVisualEditorMode && product.Prices.Count == 0) 33 { 34 product.Prices.Add(new PriceListViewModel { Price = new PriceViewModel { Price = 95, PriceFormatted = "€95" }, Quantity = 1 }); 35 product.Prices.Add(new PriceListViewModel { Price = new PriceViewModel { Price = 85, PriceFormatted = "€85" }, Quantity = 2 }); 36 } 37 38 string layout = Model.Item.GetRawValueString("Layout", "list"); 39 bool showPriceUnit = Model.Item.GetBoolean("ShowPriceUnit"); 40 string uoMLabel = product.DefaultUnitId != null && showPriceUnit ? Dynamicweb.Ecommerce.Services.VariantOptions.GetVariantOption(product.DefaultUnitId)?.GetName(product.LanguageId) : string.Empty; 41 string uoMLabelPrefix = !string.IsNullOrEmpty(uoMLabel) ? Translate(" pr. ") : ""; 42 43 if (!hidePrice && product.Id != null) 44 { 45 if (isLazyLoadingForProductInfoEnabled) 46 { 47 <div class="product-prices-container js-live-info d-none" data-show-if="LiveProductInfo.product.Prices.length > 0" data-product-id="@product.Id" data-variant-id="@product.VariantId" data-default-unit-id="@uoMLabel" data-show-unit="@showPriceUnit" data-show-zero-price="@showZeroPrice"> 48 @if (layout == "list") 49 { 50 <div class="product-prices item_@Model.Item.SystemName.ToLower() list"> 51 <small class="d-block opacity-75 product-prices-template"><span><span class="js-text-price-quantity"></span><span class="d-none" data-show-if="LiveProductInfo.productPrice.Quantity > 1">@uoMLabelPrefix</span></span> - <span class="fw-bold"><span class="js-text-price-price"></span> <span class="d-none js-text-price-unitId" data-show-if="LiveProductInfo.productPrice.Quantity > 1"><span class="d-none" data-show-if="LiveProductInfo.productPrice.Quantity > 1">@uoMLabelPrefix</span></span></span></small> 52 </div> 53 } 54 else if (layout == "table") 55 { 56 <div class="item_@Model.Item.SystemName.ToLower() grid"> 57 <table class="table table-sm mt-3 g-col-12 g-col-lg-6"> 58 <thead> 59 <tr> 60 <td>@Translate("QTY")</td> 61 <td>@Translate("pr. PCS")</td> 62 </tr> 63 </thead> 64 <tbody class="product-prices"> 65 <tr class="product-prices-template"> 66 <td class="js-text-price-quantity"></td> 67 <td><span class="js-text-price-price"></span><span class="d-none" data-show-if="LiveProductInfo.productPrice.Quantity > 1">@uoMLabelPrefix</span><span class="js-text-price-unitId d-none" data-show-if="LiveProductInfo.productPrice.Quantity > 1"></span></td> 68 </tr> 69 </tbody> 70 </table> 71 </div> 72 } 73 </div> 74 } 75 else 76 { 77 var productPrices = showZeroPrice ? product.Prices : product.Prices.Where(price => price.Price.Price > 0); 78 79 if (layout == "list") 80 { 81 <div class="item_@Model.Item.SystemName.ToLower() list"> 82 @foreach (PriceListViewModel quantityPrice in productPrices) 83 { 84 string quantityPricePrefix = quantityPrice.Quantity > 1 ? uoMLabelPrefix : ""; 85 @*START CUSTOM CODE*@ 86 <small class="d-block opacity-75"><span>@quantityPrice.Quantity @uoMLabel</span> - <span class="fw-bold">@(Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, quantityPrice.Price.Price))@quantityPricePrefix@uoMLabel</span></small> 87 @*END CUSTOM CODE*@ 88 } 89 </div> 90 } 91 else if (layout == "table") 92 { 93 <div class="item_@Model.Item.SystemName.ToLower() grid"> 94 <table class="table table-sm mt-3 g-col-12 g-col-lg-6"> 95 <thead> 96 <tr> 97 <td>@Translate("QTY")</td> 98 <td>@Translate("pr. PCS")</td> 99 </tr> 100 </thead> 101 <tbody> 102 @foreach (PriceListViewModel quantityPrice in productPrices) 103 { 104 string quantityPricePrefix = quantityPrice.Quantity > 1 ? uoMLabelPrefix : ""; 105 106 <tr> 107 <td>@quantityPrice.Quantity</td> 108 @*START CUSTOM CODE*@ 109 <td>@(Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, quantityPrice.Price.Price))@quantityPricePrefix@uoMLabel</td> 110 @*END CUSTOM CODE*@ 111 </tr> 112 } 113 </tbody> 114 </table> 115 </div> 116 } 117 } 118 } 119 else if (Pageview.IsVisualEditorMode) 120 { 121 <div class="alert alert-dark m-0" role="alert"> 122 <span>@Translate("No products available")</span> 123 </div> 124 } 125 } 126 else if (Pageview.IsVisualEditorMode) 127 { 128 <div class="alert alert-dark m-0" role="alert"> 129 <span>@Translate("No products available")</span> 130 </div> 131 } 132
By clicking 'Accept All' you consent that we may collect information about you for various purposes, including: Statistics and Marketing