Error executing template "Designs/Swift/Paragraph/Swift_ProductHeader.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_c3d50f69b0d548d197ffdecb069ea855.Execute() in H:\Solutions\Hamonoya\Files\Templates\Designs\Swift\Paragraph\Swift_ProductHeader.cshtml:line 30
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 = new ProductViewModel();
6
7 ProductViewModelSettings productSetting = new ProductViewModelSettings
8 {
9 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID,
10 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code,
11 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2,
12 ShopId = Pageview.Area.EcomShopId
13 };
14
15 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
16 {
17 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
18 }
19 else if (Pageview.Item["DummyProduct"] != null)
20 {
21 string dummyProductId = "";
22 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page);
23 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel();
24 if (productList.Products != null)
25 {
26 foreach (var p in productList.Products) { dummyProductId = p.Id; }
27 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel();
28 product = dummyProduct;
29 } else {
30 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id);
31 }
32 } else if (Pageview.Item["DummyProduct"] == null) {
33 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id);
34 }
35
36 string titleFontSize = Model.Item.GetRawValueString("FontSize", "fs-6");
37 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", "");
38 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign;
39 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign;
40
41 string headingLevel = Model.Item.GetString("HeadingLevel", "h2");
42 string headingLevelStart = $"<{headingLevel} class=\"{titleFontSize} {horizontalAlign} m-0 item_{Model.Item.SystemName.ToLower()}\" itemprop=\"name\">";
43 string headingLevelStop = $"</{headingLevel}>";
44 }
45
46
47 @if (product.Id != null) {
48 @headingLevelStart
49 @product.Name
50 @headingLevelStop
51 } else if (Pageview.IsVisualEditorMode) {
52 <div class="alert alert-dark m-0">@Translate("No products available")</div>
53 }
54