Component builder for: Product list card (Custom)

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_b9092bc701d84ed8bf481f3ad16be783.Execute() in F:\Domains\Sites\qa-qos.mydwsite3.com\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice.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 = 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 string zeroPriceMessage = Model.Item.GetString("Message"); 23 24 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 25 bool anonymousUser = Pageview.User == null; 26 bool isErpConnectionDown = !Dna.Ecommerce.LiveIntegration.TemplatesHelper.IsWebServiceConnectionAvailable(); 27 bool isLazyLoadingForProductInfoEnabled = Dna.Ecommerce.LiveIntegration.TemplatesHelper.IsLazyLoadingForProductInfoEnabled; 28 bool hidePrice = (anonymousUsersLimitations.Contains("price") && anonymousUser) || (Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown) || (!showZeroPrice && product.Price.Price <= 0 && !isLazyLoadingForProductInfoEnabled); 29 30 bool productIsDiscontinued = product is object && product.Discontinued; 31 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 32 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 33 } 34 35 @if (product is object && !hidePrice && !isDiscontinued) { 36 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 37 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 38 39 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "fs-2"); 40 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 41 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 42 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 43 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 44 45 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 46 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 47 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 48 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 49 50 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 51 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 52 string order = layout == "horizontal" ? string.Empty : "order-2"; 53 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 54 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 55 56 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 57 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 58 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 59 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 60 61 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 62 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 63 64 string priceMin = ""; 65 string priceMax = ""; 66 67 string liveInfoClass = ""; 68 string productInfoFeed = ""; 69 70 if (isLazyLoadingForProductInfoEnabled) 71 { 72 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 73 { 74 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 75 if (!string.IsNullOrEmpty(productInfoFeed)) 76 { 77 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 78 } 79 } 80 liveInfoClass = "js-live-info"; 81 } 82 83 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" data-show-zero-price="@showZeroPrice" data-zero-price-message="@zeroPriceMessage" @productInfoFeed> 84 @if (showInformativePrice && product.PriceInformative.Price != 0) 85 { 86 <div class="opacity-50"> 87 <span>@Translate("RRP") </span> 88 @*START CUSTOM CODE*@ 89 <span class="text-decoration-line-through text-price">@Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.PriceInformative.Price)</span> 90 @*END CUSTOM CODE*@ 91 </div> 92 } 93 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 94 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 95 96 97 @if (showPricesWithVat == "false" && !neverShowVat) 98 { 99 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 100 { 101 <span itemprop="price" content="" class="d-none"></span> 102 <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> 103 } 104 else 105 { 106 @*START CUSTOM CODE*@ 107 string beforePrice = !string.IsNullOrEmpty(unitId) ? 108 Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVat) : 109 Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.PriceBeforeDiscount.PriceWithoutVat); 110 @*END CUSTOM CODE*@ 111 112 <span itemprop="price" content="@product.Price.PriceWithoutVat" class="d-none"></span> 113 if (product.Price.Price != product.PriceBeforeDiscount.Price) 114 { 115 <span class="text-decoration-line-through opacity-75 @order">@beforePrice</span> 116 } 117 } 118 } 119 else 120 { 121 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 122 { 123 <span itemprop="price" content="" class="d-none"></span> 124 <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> 125 } 126 else 127 { 128 @*START CUSTOM CODE*@ 129 string beforePrice = !string.IsNullOrEmpty(unitId) ? 130 Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.GetPrice(unitId).PriceBeforeDiscount.Price) : 131 Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.PriceBeforeDiscount.Price); 132 @*END CUSTOM CODE*@ 133 134 <span itemprop="price" content="@product.Price.Price" class="d-none"></span> 135 136 if (product.Price.Price != product.PriceBeforeDiscount.Price) 137 { 138 <span class="text-decoration-line-through opacity-75 @order"> 139 <span class="text-price">@beforePrice</span> 140 </span> 141 } 142 } 143 } 144 145 @if (showPricesWithVat == "false" && !neverShowVat) 146 { 147 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 148 { 149 <span class="text-price js-text-price"> 150 <span class="spinner-border" role="status"></span> 151 </span> 152 } 153 else 154 { 155 @*START CUSTOM CODE*@ 156 string price = !string.IsNullOrEmpty(unitId) ? 157 Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.GetPrice(unitId).Price.PriceWithoutVat) : 158 Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.Price.PriceWithoutVat); 159 @*END CUSTOM CODE*@ 160 161 if (product?.VariantInfo?.VariantInfo != null) 162 { 163 @*START CUSTOM CODE*@ 164 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.VariantInfo.PriceMin.PriceWithoutVat) : ""; 165 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.VariantInfo.PriceMax.PriceWithoutVat) : ""; 166 @*END CUSTOM CODE*@ 167 } 168 if (priceMin != priceMax) 169 { 170 price = priceMin + " - " + priceMax; 171 } 172 <span class="@theme @contentPadding"> 173 <span class="text-price">@price</span> 174 </span> 175 } 176 } 177 else 178 { 179 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 180 { 181 <span class="text-price js-text-price"> 182 <span class="spinner-border" role="status"></span> 183 </span> 184 } 185 else 186 { 187 @*START CUSTOM CODE*@ 188 string price = !string.IsNullOrEmpty(unitId) ? 189 Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.GetPrice(unitId).Price.Price) : 190 Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.Price.Price); 191 @*END CUSTOM CODE*@ 192 193 if (product?.VariantInfo?.VariantInfo != null) 194 { 195 @*START CUSTOM CODE*@ 196 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.VariantInfo.PriceMin.Price) : ""; 197 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.VariantInfo.PriceMax.Price) : ""; 198 @*END CUSTOM CODE*@ 199 } 200 if (priceMin != priceMax) 201 { 202 price = priceMin + " - " + priceMax; 203 } 204 <span class="@theme @contentPadding"> 205 <span class="text-price">@price</span> 206 </span> 207 } 208 } 209 210 @* Stock state for Schema.org, start *@ 211 @{ 212 Uri url = Dynamicweb.Context.Current.Request.Url; 213 } 214 215 <link itemprop="url" href="@url"> 216 217 @{ 218 bool IsNeverOutOfStock = product.NeverOutOfstock; 219 } 220 221 @if (IsNeverOutOfStock) 222 { 223 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 224 } 225 else 226 { 227 if (product.StockLevel > 0) 228 { 229 <span itemprop="availability" class="d-none">InStock</span> 230 } 231 else 232 { 233 <span itemprop="availability" class="d-none">OutOfStock</span> 234 } 235 } 236 @* Stock state for Schema.org, stop *@ 237 238 </div> 239 240 @if (showPricesWithVat == "false" && !neverShowVat) 241 { 242 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 243 { 244 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 245 } 246 else 247 { 248 @*START CUSTOM CODE*@ 249 string price = !string.IsNullOrEmpty(unitId) ? 250 Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.GetPrice(unitId).Price.PriceWithVat) : 251 Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.Price.PriceWithVat); 252 @*END CUSTOM CODE*@ 253 254 if (product?.VariantInfo?.VariantInfo != null) 255 { 256 @*START CUSTOM CODE*@ 257 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.VariantInfo.PriceMin.PriceWithVat) : ""; 258 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? Dna.Qosina.Prices.Helpers.GetPriceFormatted(Dynamicweb.Ecommerce.Common.Context.Currency, product.VariantInfo.PriceMax.PriceWithVat) : ""; 259 @*END CUSTOM CODE*@ 260 } 261 if (priceMin != priceMax) 262 { 263 price = priceMin + " - " + priceMax; 264 } 265 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 266 } 267 } 268 </div> 269 } 270 else if (!string.IsNullOrEmpty(zeroPriceMessage)) 271 { 272 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 273 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 274 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 275 276 <div class="@textAlign item_@Model.Item.SystemName.ToLower()">@zeroPriceMessage</div> 277 } 278 else if (Pageview.IsVisualEditorMode) 279 { 280 <div class="alert alert-dark m-0" role="alert"> 281 <span>@Translate("No products available")</span> 282 </div> 283 } 284
By clicking 'Accept All' you consent that we may collect information about you for various purposes, including: Statistics and Marketing