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_ea0cf638955a48b7901b54ad84d20ea5.Execute() in F:\Domains\Sites\uat-ic.mydwsite.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 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span>
89 </div>
90 }
91 <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">
92 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span>
93
94
95 @if (showPricesWithVat == "false" && !neverShowVat)
96 {
97 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
98 {
99 <span itemprop="price" content="" class="d-none"></span>
100 <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>
101 }
102 else
103 {
104 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted;
105
106 <span itemprop="price" content="@product.Price.PriceWithoutVat" class="d-none"></span>
107 if (product.Price.Price != product.PriceBeforeDiscount.Price)
108 {
109 <span class="text-decoration-line-through opacity-75 @order">@beforePrice</span>
110 }
111 }
112 }
113 else
114 {
115 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
116 {
117 <span itemprop="price" content="" class="d-none"></span>
118 <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>
119 }
120 else
121 {
122 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted;
123
124 <span itemprop="price" content="@product.Price.Price" class="d-none"></span>
125
126 if (product.Price.Price != product.PriceBeforeDiscount.Price)
127 {
128 <span class="text-decoration-line-through opacity-75 @order">
129 <span class="text-price">@beforePrice</span>
130 </span>
131 }
132 }
133 }
134
135 @if (showPricesWithVat == "false" && !neverShowVat)
136 {
137 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
138 {
139 <span class="text-price js-text-price">
140 <span class="spinner-border" role="status"></span>
141 </span>
142 }
143 else
144 {
145 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted;
146
147 if (product?.VariantInfo?.VariantInfo != null)
148 {
149 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : "";
150 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : "";
151 }
152 if (priceMin != priceMax)
153 {
154 price = priceMin + " - " + priceMax;
155 }
156 <span class="@theme @contentPadding">
157 <span class="text-price">@price</span>
158 </span>
159 }
160 }
161 else
162 {
163 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
164 {
165 <span class="text-price js-text-price">
166 <span class="spinner-border" role="status"></span>
167 </span>
168 }
169 else
170 {
171 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted;
172
173 if (product?.VariantInfo?.VariantInfo != null)
174 {
175 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : "";
176 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : "";
177 }
178 if (priceMin != priceMax)
179 {
180 price = priceMin + " - " + priceMax;
181 }
182 <span class="@theme @contentPadding">
183 <span class="text-price">@price</span>
184 </span>
185 }
186 }
187
188 @* Stock state for Schema.org, start *@
189 @{
190 Uri url = Dynamicweb.Context.Current.Request.Url;
191 }
192
193 <link itemprop="url" href="@url">
194
195 @{
196 bool IsNeverOutOfStock = product.NeverOutOfstock;
197 }
198
199 @if (IsNeverOutOfStock)
200 {
201 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span>
202 }
203 else
204 {
205 if (product.StockLevel > 0)
206 {
207 <span itemprop="availability" class="d-none">InStock</span>
208 }
209 else
210 {
211 <span itemprop="availability" class="d-none">OutOfStock</span>
212 }
213 }
214 @* Stock state for Schema.org, stop *@
215
216 </div>
217
218 @if (showPricesWithVat == "false" && !neverShowVat)
219 {
220 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
221 {
222 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small>
223 }
224 else
225 {
226 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted;
227
228 if (product?.VariantInfo?.VariantInfo != null)
229 {
230 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : "";
231 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : "";
232 }
233 if (priceMin != priceMax)
234 {
235 price = priceMin + " - " + priceMax;
236 }
237 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small>
238 }
239 }
240 </div>
241 }
242 else if (!string.IsNullOrEmpty(zeroPriceMessage))
243 {
244 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", "");
245 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty;
246 textAlign = horizontalAlign == "end" ? "text-end" : textAlign;
247
248 <div class="@textAlign item_@Model.Item.SystemName.ToLower()">@zeroPriceMessage</div>
249 }
250 else if (Pageview.IsVisualEditorMode)
251 {
252 <div class="alert alert-dark m-0" role="alert">
253 <span>@Translate("No products available")</span>
254 </div>
255 }
256