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_81af79fb978e421fb8b72cbb038ce569.Execute() in E:\Domains\Sites\portal.keystonerv.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 @* START CUSTOM CODE *@
71 var displayUnits = "";
72 if (Model.Item.GetBoolean("ShowDisplayUnits"))
73 {
74 product.ProductFields.TryGetValue("DisplayUnits", out FieldValueViewModel displayUnitsObject);
75 if (displayUnitsObject != null)
76 {
77 displayUnits = Dynamicweb.Core.Converter.ToString(displayUnitsObject.Value);
78 }
79 }
80 @* END CUSTOM CODE *@
81
82 if (isLazyLoadingForProductInfoEnabled)
83 {
84 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed"))
85 {
86 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString();
87 if (!string.IsNullOrEmpty(productInfoFeed))
88 {
89 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\"";
90 }
91 }
92 liveInfoClass = "js-live-info";
93 }
94
95 <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>
96 @if (showInformativePrice && product.PriceInformative.Price != 0)
97 {
98 <div class="opacity-50">
99 <span>@Translate("RRP") </span>
100 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span>
101 </div>
102 }
103 <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">
104 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span>
105
106
107 @if (showPricesWithVat == "false" && !neverShowVat)
108 {
109 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
110 {
111 <span itemprop="price" content="" class="d-none"></span>
112 <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>
113 }
114 else
115 {
116 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted;
117
118 <span itemprop="price" content="@product.Price.PriceWithoutVat" class="d-none"></span>
119 if (product.Price.Price != product.PriceBeforeDiscount.Price)
120 {
121 <span class="text-decoration-line-through opacity-75 @order">@beforePrice</span>
122 }
123 }
124 }
125 else
126 {
127 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
128 {
129 <span itemprop="price" content="" class="d-none"></span>
130 <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>
131 }
132 else
133 {
134 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted;
135
136 <span itemprop="price" content="@product.Price.Price" class="d-none"></span>
137
138 if (product.Price.Price != product.PriceBeforeDiscount.Price)
139 {
140 <span class="text-decoration-line-through opacity-75 @order">
141 <span class="text-price">@beforePrice</span>
142 </span>
143 }
144 }
145 }
146
147 @if (showPricesWithVat == "false" && !neverShowVat)
148 {
149 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
150 {
151 <span class="text-price js-text-price">
152 <span class="spinner-border" role="status"></span>
153 </span>
154 }
155 else
156 {
157 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted;
158
159 if (product?.VariantInfo?.VariantInfo != null)
160 {
161 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : "";
162 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : "";
163 }
164 if (priceMin != priceMax)
165 {
166 price = priceMin + " - " + priceMax;
167 }
168 <span class="@theme @contentPadding">
169 <span class="text-price">@price</span>
170 </span>
171 }
172 }
173 else
174 {
175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
176 {
177 <span class="text-price js-text-price">
178 <span class="spinner-border" role="status"></span>
179 </span>
180 }
181 else
182 {
183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted;
184
185 if (product?.VariantInfo?.VariantInfo != null)
186 {
187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : "";
188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : "";
189 }
190 if (priceMin != priceMax)
191 {
192 price = priceMin + " - " + priceMax;
193 }
194 <span class="@theme @contentPadding">
195 @* START CUSTOM CODE *@
196 <span class="text-price">
197 @price
198 @if (!string.IsNullOrEmpty(displayUnits))
199 {
200 <small>@displayUnits</small>
201 }
202 </span>
203 @* END CUSTOM CODE *@
204 </span>
205 }
206 }
207
208 @* Stock state for Schema.org, start *@
209 @{
210 Uri url = Dynamicweb.Context.Current.Request.Url;
211 }
212
213 <link itemprop="url" href="@url">
214
215 @{
216 bool IsNeverOutOfStock = product.NeverOutOfstock;
217 }
218
219 @if (IsNeverOutOfStock)
220 {
221 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span>
222 }
223 else
224 {
225 if (product.StockLevel > 0)
226 {
227 <span itemprop="availability" class="d-none">InStock</span>
228 }
229 else
230 {
231 <span itemprop="availability" class="d-none">OutOfStock</span>
232 }
233 }
234 @* Stock state for Schema.org, stop *@
235
236 </div>
237
238 @if (showPricesWithVat == "false" && !neverShowVat)
239 {
240 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
241 {
242 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small>
243 }
244 else
245 {
246 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted;
247
248 if (product?.VariantInfo?.VariantInfo != null)
249 {
250 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : "";
251 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : "";
252 }
253 if (priceMin != priceMax)
254 {
255 price = priceMin + " - " + priceMax;
256 }
257 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small>
258 }
259 }
260 </div>
261 }
262 else if (!string.IsNullOrEmpty(zeroPriceMessage))
263 {
264 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", "");
265 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty;
266 textAlign = horizontalAlign == "end" ? "text-end" : textAlign;
267
268 <div class="@textAlign item_@Model.Item.SystemName.ToLower()">@zeroPriceMessage</div>
269 }
270 else if (Pageview.IsVisualEditorMode)
271 {
272 <div class="alert alert-dark m-0" role="alert">
273 <span>@Translate("No products available")</span>
274 </div>
275 }
276