Error executing template "Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at Smartpage.PhilipsonWine.Ecommerce.ProductInformation.ProductInformation..ctor(ProductViewModel product) in D:\a\1\s\Smartpage.PhilipsonWine.Ecommerce\ProductInformation\ProductInformation.cs:line 89
at CompiledRazorTemplates.Dynamic.RazorEngine_113961ff37d9412db0e09d473ab46c9d.Execute() in D:\dynamicweb.net\Solutions\Wineshop\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 32
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 @using Smartpage.PhilipsonWine.Ecommerce.ProductInformation
4 @using Smartpage.PhilipsonWine.EcomPrices
5 @using Smartpage.PhilipsonWine.EcomPrices.Models
6 @using Dynamicweb.Core
7
8 @* CUSTOMIZED STANDARD SWIFT (1.21.0) TEMPLATE *@
9
10 @{
11 ProductViewModel product = null;
12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
13 {
14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
15 }
16 else if (Pageview.Item["DummyProduct"] != null)
17 {
18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page);
19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel();
20
21 if (productList?.Products is object)
22 {
23 product = productList.Products[0];
24 }
25 }
26
27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", "");
28 bool anonymousUser = Pageview.User == null;
29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]);
30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown;
31
32 ProductInformation productInformation = new ProductInformation(product);
33 var currentUser = Dynamicweb.Security.UserManagement.User.GetCurrentFrontendUser();
34 //Get customer specific price and quantity
35 CustomPrice customPrice = null;
36 CustomPriceService.GetCustomPriceProducts(currentUser)?.TryGetValue(product.Id, out customPrice);
37 int kolli = productInformation.CurrentPriceQuantity;
38
39 int priceQuantity = customPrice?.PriceQuantity != null && customPrice?.PriceQuantity > 0 ? Converter.ToInt32(customPrice?.PriceQuantity) : productInformation.MaxPriceBasedOn;
40 var priceObject = new Smartpage.PhilipsonWine.Ecommerce.Prices.PriceObject(product.Id, priceQuantity, 0, productInformation.OnSale, Dynamicweb.Ecommerce.Common.Context.Currency, Dynamicweb.Ecommerce.Common.Context.Country, product.LanguageId, Pageview.Area.EcomShopId);
41 }
42
43 @if (product is object && !hidePrice)
44 {
45 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice");
46 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty;
47
48 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "fs-2");
49 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", "");
50 string layout = Model.Item.GetRawValueString("Layout", "horizontal");
51 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty;
52 textAlign = horizontalAlign == "end" ? "text-end" : textAlign;
53
54 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign;
55 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign;
56 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign;
57 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign;
58
59 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column";
60 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty;
61 string order = layout == "horizontal" ? string.Empty : "order-0";
62 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : "";
63 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme;
64
65 string contentPadding = Model.Item.GetRawValueString("ContentPadding", "");
66 contentPadding = contentPadding == "none" ? "p-0" : contentPadding;
67 contentPadding = contentPadding == "small" ? "p-3 p-md-3" : contentPadding;
68 contentPadding = contentPadding == "large" ? "p-5 p-md-5" : contentPadding;
69
70 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower();
71 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat);
72
73 string priceMin = "";
74 string priceMax = "";
75
76 string liveInfoClass = "";
77 string productInfoFeed = "";
78 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]);
79 if (isLazyLoadingForProductInfoEnabled)
80 {
81 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed"))
82 {
83 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString();
84 if (!string.IsNullOrEmpty(productInfoFeed))
85 {
86 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\"";
87 }
88 }
89 liveInfoClass = "js-live-info";
90 }
91
92 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower() custom" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed>
93 @if (showInformativePrice && product.PriceInformative.Price != 0)
94 {
95 <div>
96 <span class="@priceFontSize text-price">@product.PriceInformative.PriceFormatted</span>
97 </div>
98 }
99 <div class="@priceFontSize m-0 d-flex @flexDirection @flexGap @horizontalAlign @contentPadding" itemprop="offers" itemscope itemtype="https://schema.org/Offer">
100 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span>
101
102 @if (showPricesWithVat == "false" && !neverShowVat)
103 {
104 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
105 {
106 <span class="text-price js-text-price">
107 <span class="spinner-border" role="status"></span>
108 </span>
109 }
110 else
111 {
112 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted;
113
114 if (product?.VariantInfo?.VariantInfo != null)
115 {
116 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : "";
117 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : "";
118 }
119 if (priceMin != priceMax)
120 {
121 price = priceMin + " - " + priceMax;
122 }
123 <div class="@theme">
124 <p class="text-price">@priceObject.DiscountPriceFormatted</p>
125 <p class="text-price-kolli">@Translate("Custom:KolliPrice", "pr. fl. v/")@kolli</p>
126 </div>
127 }
128 }
129 else
130 {
131 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
132 {
133 <span class="text-price js-text-price">
134 <span class="spinner-border" role="status"></span>
135 </span>
136 }
137 else
138 {
139 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted;
140
141 if (product?.VariantInfo?.VariantInfo != null)
142 {
143 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : "";
144 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : "";
145 }
146 if (priceMin != priceMax)
147 {
148 price = priceMin + " - " + priceMax;
149 }
150 <div class="@theme">
151 <p class="text-price">@priceObject.DiscountPriceFormatted</p>
152 <p class="text-price-kolli">@Translate("Custom:KolliPrice", "pr. fl. v/")@kolli</p>
153 </div>
154 }
155 }
156
157 @if (showPricesWithVat == "false" && !neverShowVat)
158 {
159 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
160 {
161 <span itemprop="price" content="" class="d-none"></span>
162 <span class="opacity-75 me-3 text-price js-text-price d-none" data-show-if="LiveProductInfo.product.Price.Price != LiveProductInfo.product.PriceBeforeDiscount.Price"></span>
163 }
164 else
165 {
166 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted;
167
168 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(System.Globalization.CultureInfo.InvariantCulture)" class="d-none"></span>
169 if (priceObject.NormalPrice != priceObject.DiscountPrice)
170 {
171 <span class="text-normal-price-text-before">@Translate("Custom:BeforePrice", "F�r pris:")</span>
172 <span class="text-normal-price @order">@priceObject.NormalPrice</span>
173 <span class="text-normal-price-single-bottle">@Translate("Custom:OneBottlePrice", "pr. fl.")</span>
174 }
175 }
176 }
177 else
178 {
179 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
180 {
181 <span itemprop="price" content="" class="d-none"></span>
182 <span class="opacity-75 me-3 text-price js-text-price d-none" data-show-if="LiveProductInfo.product.Price.Price != LiveProductInfo.product.PriceBeforeDiscount.Price"></span>
183 }
184 else
185 {
186 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted;
187
188 <span itemprop="price" content="@product.Price.Price.ToString(System.Globalization.CultureInfo.InvariantCulture)" class="d-none"></span>
189
190 if (priceObject.NormalPrice != priceObject.DiscountPrice)
191 {
192 <div class="d-flex gap-1 @order">
193 <span class="text-normal-price-text-before">@Translate("Custom:BeforePrice", "F�r pris:")</span>
194 <span class="text-normal-price">@priceObject.NormalPrice</span>
195 <span class="text-normal-price-single-bottle">@Translate("Custom:OneBottlePrice", "pr. fl.")</span>
196 </div>
197 }
198 }
199 }
200
201 @* Stock state for Schema.org, start *@
202 @{
203 Uri url = Dynamicweb.Context.Current.Request.Url;
204 }
205
206 <link itemprop="url" href="@url">
207
208 @{
209 bool IsNeverOutOfStock = product.NeverOutOfstock;
210 }
211
212 @if (IsNeverOutOfStock)
213 {
214 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span>
215 }
216 else
217 {
218 if (product.StockLevel > 0)
219 {
220 <span itemprop="availability" class="d-none">InStock</span>
221 }
222 else
223 {
224 <span itemprop="availability" class="d-none">OutOfStock</span>
225 }
226 }
227 @* Stock state for Schema.org, stop *@
228
229 </div>
230
231 @if (showPricesWithVat == "false" && !neverShowVat)
232 {
233 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
234 {
235 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(Translate("Incl. VAT"))"></small>
236 }
237 else
238 {
239 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted;
240
241 if (product?.VariantInfo?.VariantInfo != null)
242 {
243 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : "";
244 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : "";
245 }
246 if (priceMin != priceMax)
247 {
248 price = priceMin + " - " + priceMax;
249 }
250 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small>
251 }
252 }
253 </div>
254 }
255 else if (Pageview.IsVisualEditorMode)
256 {
257 <div class="alert alert-dark m-0" role="alert">
258 <span>@Translate("No products available")</span>
259 </div>
260 }
261