Component builder for: Detail info Spares (Flexo)

Error executing template "Designs/Swift/Paragraph/Swift_ProductReplacement.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_d21cc39f37ce4cf5acf2aa1bb25ef52c.ExecuteAsync()
   at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.DynamicWrapperService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass23_0.<Run>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
   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 System.Collections.Generic 3 @using Dynamicweb.Ecommerce.ProductCatalog 4 @using Dynamicweb.Frontend 5 6 @{ 7 ProductViewModel product = null; 8 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 9 { 10 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 11 } 12 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 13 { 14 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 15 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 16 17 if (productList?.Products is object) 18 { 19 product = productList.Products[0]; 20 } 21 } 22 } 23 24 @if (product.Discontinued && product.ReplacementProduct is object) 25 { 26 ProductViewModel replacementProduct = new ProductViewModel(); 27 if (!string.IsNullOrEmpty(product.ReplacementProduct.ProductId)) 28 { 29 replacementProduct = product.ReplacementProduct.GetProduct(); 30 } 31 32 bool hideReplacementProductPrice = Model.Item.GetBoolean("HideReplacementProductPrice") != null ? Model.Item.GetBoolean("HideReplacementProductPrice") : false; 33 bool hideReplacementProductImage = Model.Item.GetBoolean("HideReplacementProductImage") != null ? Model.Item.GetBoolean("HideReplacementProductImage") : false; 34 bool hideReplacementProductName = Model.Item.GetBoolean("HideReplacementProductName") != null ? Model.Item.GetBoolean("HideReplacementProductName") : false; 35 string message = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Message")) ? Model.Item.GetRawValueString("Message") : string.Empty; 36 string link = replacementProduct?.GetProductLink(GetPageIdByNavigationTag("Shop"), false); 37 38 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 39 bool anonymousUser = Pageview.User == null; 40 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 41 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 42 43 bool hasReplacementProduct = (product.DiscontinuedAction == 0 || product.DiscontinuedAction == 1) && product.ReplacementProduct.ProductId is object && !string.IsNullOrEmpty(product.ReplacementProduct.ProductId); 44 bool hasReplacementProductContent = !hideReplacementProductImage || (!hidePrice && !hideReplacementProductPrice) || !hideReplacementProductName || !string.IsNullOrEmpty(link) || !string.IsNullOrEmpty(message); 45 46 if (hasReplacementProduct && hasReplacementProductContent) { 47 48 string priceMin = ""; 49 string priceMax = ""; 50 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 51 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 52 53 string imagePath = replacementProduct?.DefaultImage?.Value != null ? replacementProduct.DefaultImage.Value : ""; 54 var parms = new Dictionary<string, object>(); 55 parms.Add("cssClass", "d-block mw-100 mh-100 m-auto"); 56 parms.Add("fullwidth", true); 57 parms.Add("columns", Model.GridRowColumnCount); 58 59 string liveInfoClass = ""; 60 string productInfoFeed = ""; 61 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 62 if (isLazyLoadingForProductInfoEnabled) 63 { 64 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 65 { 66 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 67 if (!string.IsNullOrEmpty(productInfoFeed)) 68 { 69 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 70 } 71 } 72 liveInfoClass = "js-live-info"; 73 } 74 75 <div class="h-100 @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@replacementProduct.Id" data-variant-id="@replacementProduct.VariantId" @productInfoFeed> 76 <div class="d-flex flex-column gap-4"> 77 <div class="d-flex flex-row flex-nowrap gap-2"> 78 <div class="w-100"> 79 @if (!string.IsNullOrEmpty(message)) 80 { 81 <div>@message</div> 82 } 83 84 @if (!hideReplacementProductImage) 85 { 86 if (string.IsNullOrEmpty(link)) 87 { 88 @RenderPartial("Components/Image.cshtml", new FileViewModel { Path = imagePath }, parms) 89 } 90 else 91 { 92 <a href="@link"> 93 @RenderPartial("Components/Image.cshtml", new FileViewModel { Path = imagePath }, parms) 94 </a> 95 } 96 } 97 98 @if (!hideReplacementProductName) 99 { 100 <div> 101 <h5>@replacementProduct.Name</h5> 102 </div> 103 } 104 105 @if (!hidePrice && !hideReplacementProductPrice) 106 { 107 <div class="mb-3"> 108 <div class="h4" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 109 @if (showPricesWithVat == "false" && !neverShowVat) 110 { 111 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 112 { 113 <span itemprop="price" content="" class="d-none"></span> 114 <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> 115 } 116 else 117 { 118 string beforePrice = replacementProduct.PriceBeforeDiscount.PriceWithoutVatFormatted; 119 120 <span itemprop="price" content="@replacementProduct.Price.PriceWithoutVat" class="d-none"></span> 121 if (replacementProduct.Price.Price != replacementProduct.PriceBeforeDiscount.Price) 122 { 123 <span class="text-decoration-line-through opacity-75 text-price">@beforePrice</span> 124 } 125 } 126 } 127 else 128 { 129 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 130 { 131 <span itemprop="price" content="" class="d-none"></span> 132 <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> 133 } 134 else 135 { 136 string beforePrice = replacementProduct.PriceBeforeDiscount.PriceFormatted; 137 138 <span itemprop="price" content="@replacementProduct.Price.Price" class="d-none"></span> 139 if (replacementProduct.Price.Price != replacementProduct.PriceBeforeDiscount.Price) 140 { 141 <span class="text-decoration-line-through opacity-75"> 142 <span class="text-price">@beforePrice</span> 143 </span> 144 } 145 } 146 } 147 148 @if (showPricesWithVat == "false" && !neverShowVat) 149 { 150 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 151 { 152 <span class="text-price js-text-price"> 153 <span class="spinner-border" role="status"></span> 154 </span> 155 } 156 else 157 { 158 string price = replacementProduct.Price.PriceWithoutVatFormatted; 159 if (replacementProduct?.VariantInfo?.VariantInfo != null) 160 { 161 priceMin = replacementProduct?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? replacementProduct.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 162 priceMax = replacementProduct?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? replacementProduct.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 163 } 164 if (priceMin != priceMax) 165 { 166 price = priceMin + " - " + priceMax; 167 } 168 <span class="text-price">@price</span> 169 } 170 } 171 else 172 { 173 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 174 { 175 <span class="text-price js-text-price"> 176 <span class="spinner-border" role="status"></span> 177 </span> 178 } 179 else 180 { 181 string price = replacementProduct.Price.PriceFormatted; 182 if (replacementProduct?.VariantInfo?.VariantInfo != null) 183 { 184 priceMin = replacementProduct?.VariantInfo?.PriceMin?.PriceFormatted != null ? replacementProduct.VariantInfo.PriceMin.PriceFormatted : ""; 185 priceMax = replacementProduct?.VariantInfo?.PriceMax?.PriceFormatted != null ? replacementProduct.VariantInfo.PriceMax.PriceFormatted : ""; 186 } 187 if (priceMin != priceMax) 188 { 189 price = priceMin + " - " + priceMax; 190 } 191 <span class="text-price">@price</span> 192 } 193 } 194 </div> 195 196 @if (showPricesWithVat == "false" && !neverShowVat) 197 { 198 if (isLazyLoadingForProductInfoEnabled) 199 { 200 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 201 } 202 else 203 { 204 string price = replacementProduct.Price.PriceWithVatFormatted; 205 if (replacementProduct?.VariantInfo?.VariantInfo != null) 206 { 207 priceMin = replacementProduct?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? replacementProduct.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 208 priceMax = replacementProduct?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? replacementProduct.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 209 } 210 if (priceMin != priceMax) 211 { 212 price = priceMin + " - " + priceMax; 213 } 214 <small class="opacity-85 fst-normal text-price">@price @Translate("Incl. VAT")</small> 215 } 216 } 217 </div> 218 } 219 220 @if (!string.IsNullOrEmpty(link)) 221 { 222 <a href="@link" class="btn btn-primary w-100">@Translate("Go to the replacement")</a> 223 } 224 </div> 225 </div> 226 </div> 227 </div> 228 229 } 230 } 231 else if (Pageview.IsVisualEditorMode) 232 { 233 <div class="alert alert-dark m-0" role="alert"> 234 <span>@Translate("Discontinued product container")</span> 235 </div> 236 } 237
Product Specification will be shown here if any
By clicking 'Accept All' you consent that we may collect information about you for various purposes, including: Statistics and Marketing