Error executing template "Designs/Swift/Paragraph/Custom_MixMatchSlider.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_c2ff7b02af6440feb8ecf6662da877d8.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.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.DynamicWrapperService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, 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 RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String templateSource, 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 @using Dynamicweb.Ecommerce.International
4 @using CustomServices.Services
5 @using CustomServices.Models
6 @using Newtonsoft.Json
7 @{
8 ProductViewModel product = null;
9 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
10 {
11 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
12 }
13 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode)
14 {
15 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page);
16 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel();
17
18 if (productList?.Products is object)
19 {
20 product = productList.Products[0];
21 }
22 }
23 ProductViewModelSettings productSetting = new ProductViewModelSettings
24 {
25 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID,
26 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code,
27 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2,
28 ShopId = Pageview.Area.EcomShopId
29 };
30 int itemCount = Model.Item.GetInt32("Product_Count");
31 }
32
33 @if (product is object)
34 {
35 DiscountService discountService = new DiscountService();
36 List<MixAndMatchProductInfo> mixAndMatchProductInfos = new List<MixAndMatchProductInfo>();
37 mixAndMatchProductInfos = discountService.ReturnDiscountsMixAndMatch(product.Id, product.VariantId);
38 string title = "";
39 if (mixAndMatchProductInfos.Count > 0)
40 {
41 title = mixAndMatchProductInfos[0].discountName;
42 }
43
44 string detailPageId = GetPageIdByNavigationTag("ProductDetailPage") != 0 ? GetPageIdByNavigationTag("ProductDetailPage").ToString() : "";
45 string productDetailUrl = "/Default.aspx?ID=" + detailPageId;
46 @if (mixAndMatchProductInfos.Count > 0)
47 {
48 <div class="detail-discount__products">
49 <div class="detail-discounts">
50 <h3 class="detail-discounttitle">@title</h3>
51 <div id="slider_@(Model.ID)" class="swiffy-slider slider-item-show@(itemCount) slider-nav-chevron-default slider-nav-on-slides slider-nav-visible slider-indicators-dash">
52 <ul class="slider-container">
53 @foreach (var mixAndMatchProductInfo in mixAndMatchProductInfos)
54 {
55 ProductViewModel productModel = new ProductViewModel();
56 productModel = ViewModelFactory.CreateView(productSetting, mixAndMatchProductInfo.productId);
57 string productDetailPage = productDetailUrl + "&productId=" + mixAndMatchProductInfo.productId;
58 if (mixAndMatchProductInfo.variantId != "")
59 {
60 productDetailPage += "&variantid=" + mixAndMatchProductInfo.variantId;
61 }
62 <li class="detail-discountproduct__content" style="cursor:pointer;">
63 <a href="@productDetailPage" class="text-decoration-none d-block h-100 text-xl-center">
64 <div class="h-100 d-flex flex-column justify-content-between">
65 <div class="" style="border: 1px solid transparent;">
66 <div class="ratio position-relative" style="--bs-aspect-ratio: 75%">
67 <img src="/Admin/Public/GetImage.ashx?image=@(productModel.DefaultImage.Value)&width=350&Format=WebP&Quality=70" class="h-100 w-100 " style="object-fit: contain;">
68 </div>
69 </div>
70 <div class="flex-fill d-flex flex-column justify-content-between cust-slider-mbinfo">
71 <div style="height:2.5em; text-align:center;">
72 <h3 class="h6 opacity-85" style="word-break:break-all;">@mixAndMatchProductInfo.productName</h3>
73 </div>
74 <div style="text-align:center;">
75 <p class="h6 m-0">
76 <span class="text-price fw-bold slideractiveprice">@mixAndMatchProductInfo.productPrice</span>
77 </p>
78 </div>
79 </div>
80 </div>
81 </a>
82 </li>
83 }
84 </ul>
85 <button type="button" title="@Translate("Previous slide")" class="slider-nav cusdiscount-slider__nav" style="z-index:2;"></button>
86 <button type="button" title="@Translate("Next slide")" class="slider-nav slider-nav-next cusdiscount-slider__nav" style="z-index:2;"></button>
87 </div>
88 </div>
89 </div>
90 <link rel="stylesheet" href="/Files/Templates/Designs/Swift/Assets/css/swiffy-slider.min.css">
91 <script src="/Files/Templates/Designs/Swift/Assets/js/swiffy-slider.js"></script>
92 <script>
93 swiffyslider.initSlider(document.querySelector('#slider_@(Model.ID)'));
94 </script>
95 }
96 }
97 else if (Pageview.IsVisualEditorMode)
98 {
99 <div class="alert alert-warning">@Translate("No products available")</div>
100 }
101