Error executing template "Designs/Swift/Paragraph/Swift_ProductPrice.cshtml"
System.InvalidOperationException: ValueFactory attempted to access the Value property of this instance.
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Dynamicweb.Ecommerce.ProductCatalog.VariantInfoViewModel.CalculatePrice()
at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass36_1.<CreateView>b__1()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Dynamicweb.Ecommerce.ProductCatalog.VariantInfoViewModel.CalculatePriceMin()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at CompiledRazorTemplates.Dynamic.RazorEngine_aec7a915730e469da81f16ff384ea329.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 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 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", "");
22 bool anonymousUser = Pageview.User == null;
23 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]);
24 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown;
25
26 bool productIsDiscontinued = product is object && product.Discontinued;
27 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued");
28 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued;
29 }
30
31 @if (product is object && !hidePrice && !isDiscontinued) {
32 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice");
33 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty;
34
35 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "fs-2");
36 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", "");
37 string layout = Model.Item.GetRawValueString("Layout", "horizontal");
38 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty;
39 textAlign = horizontalAlign == "end" ? "text-end" : textAlign;
40
41 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign;
42 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign;
43 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign;
44 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign;
45
46 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column";
47 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty;
48 string order = layout == "horizontal" ? string.Empty : "order-2";
49 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : "";
50 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme;
51
52 string contentPadding = Model.Item.GetRawValueString("ContentPadding", "");
53 contentPadding = contentPadding == "none" ? "p-0" : contentPadding;
54 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding;
55 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding;
56
57 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower();
58 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat);
59
60 string priceMin = "";
61 string priceMax = "";
62
63 string liveInfoClass = "";
64 string productInfoFeed = "";
65 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]);
66 if (isLazyLoadingForProductInfoEnabled)
67 {
68 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed"))
69 {
70 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString();
71 if (!string.IsNullOrEmpty(productInfoFeed))
72 {
73 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\"";
74 }
75 }
76 liveInfoClass = "js-live-info";
77 }
78
79 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed>
80 @if (showInformativePrice && product.PriceInformative.Price != 0)
81 {
82 <div class="opacity-50">
83 <span>@Translate("RRP") </span>
84 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span>
85 </div>
86 }
87 <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">
88 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span>
89
90
91 @if (showPricesWithVat == "false" && !neverShowVat)
92 {
93 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
94 {
95 <span itemprop="price" content="" class="d-none"></span>
96 <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>
97 }
98 else
99 {
100 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted;
101
102 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture)" class="d-none"></span>
103 if (product.Price.Price != product.PriceBeforeDiscount.Price)
104 {
105 <span class="text-decoration-line-through opacity-75 @order">@beforePrice</span>
106 }
107 }
108 }
109 else
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 = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted;
119
120 <span itemprop="price" content="@product.Price.Price.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture)" class="d-none"></span>
121
122 if (product.Price.Price != product.PriceBeforeDiscount.Price)
123 {
124 <span class="text-decoration-line-through opacity-75 @order">
125 <span class="text-price">@beforePrice</span>
126 </span>
127 }
128 }
129 }
130
131 @if (showPricesWithVat == "false" && !neverShowVat)
132 {
133 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
134 {
135 <span class="text-price js-text-price">
136 <span class="spinner-border" role="status"></span>
137 </span>
138 }
139 else
140 {
141 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted;
142
143 if (product?.VariantInfo?.VariantInfo != null)
144 {
145 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : "";
146 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : "";
147 }
148 if (priceMin != priceMax)
149 {
150 price = priceMin + " - " + priceMax;
151 }
152 <span class="@theme @contentPadding">
153 @if (product.Price.PriceWithoutVat == 0)
154 {
155 <span class="text-price">Log ind for pris</span>
156 }
157 else
158 {
159 <span class="text-price">@price</span>
160 }
161 </span>
162 }
163 }
164 else
165 {
166 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
167 {
168 <span class="text-price js-text-price">
169 <span class="spinner-border" role="status"></span>
170 </span>
171 }
172 else
173 {
174 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted;
175
176 if (product?.VariantInfo?.VariantInfo != null)
177 {
178 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : "";
179 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : "";
180 }
181 if (priceMin != priceMax)
182 {
183 price = priceMin + " - " + priceMax;
184 }
185 <span class="@theme @contentPadding">
186 <span class="text-price">@price</span>
187 </span>
188 }
189 }
190
191 @* Stock state for Schema.org, start *@
192 @{
193 Uri url = Dynamicweb.Context.Current.Request.Url;
194 }
195
196 <link itemprop="url" href="@url">
197
198 @{
199 bool IsNeverOutOfStock = product.NeverOutOfstock;
200 }
201
202 @if (IsNeverOutOfStock)
203 {
204 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span>
205 }
206 else
207 {
208 if (product.StockLevel > 0)
209 {
210 <span itemprop="availability" class="d-none">InStock</span>
211 }
212 else
213 {
214 <span itemprop="availability" class="d-none">OutOfStock</span>
215 }
216 }
217 @* Stock state for Schema.org, stop *@
218
219 </div>
220
221 @if (showPricesWithVat == "false" && !neverShowVat)
222 {
223 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode)
224 {
225 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small>
226 }
227 else
228 {
229 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted;
230
231 if (product?.VariantInfo?.VariantInfo != null)
232 {
233 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : "";
234 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : "";
235 }
236 if (priceMin != priceMax)
237 {
238 price = priceMin + " - " + priceMax;
239 }
240 @if (product.Price.PriceWithoutVat != 0) {
241 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small>
242 }
243 }
244 }
245 </div>
246 }
247 else if (Pageview.IsVisualEditorMode)
248 {
249 <div class="alert alert-dark m-0" role="alert">
250 <span>@Translate("No products available")</span>
251 </div>
252 }
253