Error executing template "/Designs/Swift/Paragraph/Swift_ProductListItemRepeater_custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_64a19bb2e33245e09f62867ed1a299e5.Execute() in D:\Solution\BKI LIVE\Files\Templates\Designs\Swift\Paragraph\Swift_ProductListItemRepeater_custom.cshtml:line 45
   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> @using Dynamicweb.Ecommerce.ProductCatalog @using Dynamicweb.Core @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites @using Dynamicweb.Environment @using System.Linq @using S_DW_BKI_Swift.CustomModules.Extensions @{ string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; int productsCount = 0; int maxProductsCounter = 0; string productInfoFeed = ""; bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); if (isLazyLoadingForProductInfoEnabled) { if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) { productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); if (!string.IsNullOrEmpty(productInfoFeed)) { productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; } } } ProductListViewModel productList = null; if (Dynamicweb.Context.Current.Items.Contains("ProductList")) { productList = (ProductListViewModel)Dynamicweb.Context.Current.Items["ProductList"]; } else if (Pageview.Item["DummyProductGroup"] != null && Pageview.IsVisualEditorMode) { var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); ProductListViewModel groupList = pageViewModel.Item.GetValue("DummyProductGroup") != null ? pageViewModel.Item.GetValue("DummyProductGroup") as ProductListViewModel : new ProductListViewModel(); if (groupList?.Products is object) { productList = groupList; } } var noindexdofollow = productList.Group.GroupFields.Where(x => x.SystemName == "NoIndexDoFollow"); if (noindexdofollow.Count() > 0) { if (noindexdofollow.FirstOrDefault().Value.ToString() == "True") { @SnippetStart("robotsProductList") <meta name="robots" content="noindex,dofollow"> @SnippetEnd("robotsProductList") } } } @if (productList is object) { <div class="h-100@(theme) item_@Model.Item.SystemName.ToLower()" @productInfoFeed> @{ bool isVisualEditor = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("VisualEdit")) ? Convert.ToBoolean(Dynamicweb.Context.Current.Request.QueryString.Get("VisualEdit")) : false; string googleTagManagerID = Pageview.AreaSettings.GetString("GoogleTagManagerID"); string googleAnalyticsMeasurementID = Pageview.AreaSettings.GetString("GoogleAnalyticsMeasurementID"); var cookieOptInLevel = CookieManager.GetCookieOptInLevel(); bool allowTracking = true; string groupId = productList?.Group?.Id != null ? productList.Group.Id : ""; string url = Dynamicweb.Context.Current.Request.RawUrl; if (productList.TotalProductsCount > 0) { int pageSizeSetting = 12; int pageSize = productList.PageSize; pageSize += pageSizeSetting; int loadedProducts = productList.PageSize > productList.TotalProductsCount ? productList.TotalProductsCount : productList.PageSize; string searchQuery = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("q")) ? Dynamicweb.Context.Current.Request.QueryString.Get("q") : ""; string searchLayout = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("SearchLayout")) ? Dynamicweb.Context.Current.Request.QueryString.Get("SearchLayout") : ""; int listItemSourcePageId = Model.Item.GetInt32("ListComponentSource"); var page = Dynamicweb.Content.Services.Pages.GetPage(listItemSourcePageId); if (page != null) { var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page); string gridColumnSize = Model.Item.GetRawValueString("GridLayoutDesktop", "3-columns"); gridColumnSize = gridColumnSize == "2-columns" ? "g-col-lg-6" : gridColumnSize; gridColumnSize = gridColumnSize == "3-columns" ? "g-col-lg-4" : gridColumnSize; gridColumnSize = gridColumnSize == "4-columns" ? "g-col-lg-3" : gridColumnSize; gridColumnSize = gridColumnSize == "6-columns" ? "g-col-lg-2" : gridColumnSize; gridColumnSize = gridColumnSize == "list" ? "" : gridColumnSize; string gridColumnMobileSize = Model.Item.GetRawValueString("GridLayoutMobile", "2-columns"); gridColumnMobileSize = gridColumnMobileSize == "list" ? "g-col-12" : gridColumnMobileSize; gridColumnMobileSize = gridColumnMobileSize == "2-columns" ? "g-col-6" : gridColumnMobileSize; string listItemTheme = " theme " + pageViewModel.Item.GetRawValueString("Theme", string.Empty).Replace(" ", "").Trim().ToLower(); string listItemPadding = pageViewModel.Item.GetRawValueString("ContentPadding", string.Empty); string listItemPaddingClass = string.Empty; switch (listItemPadding) { case "small": listItemPaddingClass = " p-2 p-xl-3"; break; case "large": listItemPaddingClass = " p-3 p-xl-4"; break; case "small-x": listItemPaddingClass = " px-2 px-md-3"; break; case "large-x": listItemPaddingClass = " px-3 px-md-4"; break; } <div class="grid"> @if ((!string.IsNullOrWhiteSpace(googleAnalyticsMeasurementID) || !string.IsNullOrWhiteSpace(googleTagManagerID)) && allowTracking) { <script> gtag("event", "view_item_list", { item_list_id: "product_list_item_repeater", item_list_name: "Product list (Item Repeater)", items: [ @foreach (ProductViewModel product in productList.Products) { //custom edit start var isvariantfield = product.ProductFields.Where(x => x.Key == "IsVariant").FirstOrDefault().Value.Value.ToString(); if (isvariantfield != null && isvariantfield == "False") { <text>{ item_id: "@product.Number", item_name: "@Dynamicweb.Core.Encoders.HtmlEncoder.JavaScriptStringEncode(product.Name)", currency: "@product.Price.CurrencyCode", price: @PriceViewModelExtensions.ToStringInvariant(product.Price) },</text> } } //custom edit end ] }); </script> } @{ string[] userAssortmentProductIds = S_DW_BKI_Swift.CustomModules.Services.AssortmentService.GetProductIdsInUserAssortment(Pageview.User, System.Web.HttpContext.Current); var productsInAssortment = productList.Products.OrderByDescending(x => userAssortmentProductIds.Contains(x.Id)).ToList(); } @*Custom edit start*@ @{bool isSearch = System.Web.HttpContext.Current.Request["q"] != "" ? true : false; } @foreach (ProductViewModel product in productsInAssortment) { //custom edit start var isvariantfield = product.ProductFields.Where(x => x.Key == "IsVariant").FirstOrDefault().Value.Value.ToString(); if (maxProductsCounter == 0 || (productsCount < maxProductsCounter)) { int productsPageId = Pageview.GetProductPageId(); // CUSTOM string groupIdFromQuery = System.Web.HttpContext.Current.Request["GroupID"]; string link = isSearch ? S_DW_BKI_Swift.CustomModules.Extensions.ProductViewModelExtensions.GetProductLinkInSearch(product, productsPageId, Pageview.Page.NavigationSettings.ShopID, false) : S_DW_BKI_Swift.CustomModules.Extensions.ProductViewModelExtensions.GetProductLink(product, productsPageId, groupIdFromQuery, false); // CUSTOM EDIT if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) { Dynamicweb.Context.Current.Items["ProductDetails"] = product; } else { Dynamicweb.Context.Current.Items.Add("ProductDetails", product); } if (Model.Item.GetString("ListComponentSource") != null) { <article class="@gridColumnMobileSize @gridColumnSize @listItemTheme @listItemPaddingClass d-flex flex-column position-relative product js-product" data-product-id="@product.Id" data-variant-id="@product.VariantId" itemscope itemtype="https://schema.org/Product"> @{ string clickProductLink = string.Empty; if ((!string.IsNullOrWhiteSpace(googleAnalyticsMeasurementID) || !string.IsNullOrWhiteSpace(googleTagManagerID)) && allowTracking) { clickProductLink = "onclick=\"return clickProductLink('" + @product.Id + "', '" + @product.Name + "', '" + @product.VariantName + "', '" + @product.Price.CurrencyCode + "', '" + @PriceViewModelExtensions.ToStringInvariant(product.Price) + "')\""; } } <a href="@link" class="stretched-link" onmouseover="swift.Image.swapImage(event)" onmouseout="swift.Image.swapImage(event)" @clickProductLink> <span class="visually-hidden">@product.Name</span> </a> @if ((!string.IsNullOrWhiteSpace(googleAnalyticsMeasurementID) || !string.IsNullOrWhiteSpace(googleTagManagerID)) && allowTracking) { <script> function clickProductLink(productId, productName, productVariant, productCurrency, productPrice) { if (typeof gtag !== "undefined") { gtag("event", "select_item", { item_list_id: "product_list_item_repeater", item_list_name: "Product list (Item Repeater)", items: [ { item_id: productId, item_name: productName, currency: productCurrency, item_list_id: "product_list_item_repeater", item_list_name: "Product list (Item Repeater)", item_variant: productVariant, price: productPrice } ] }); } } </script> } @RenderGrid(listItemSourcePageId) </article> } productsCount++; } @*Custom edit end*@ } @*Custom edit end*@ </div> <div class="my-3"> <div class="text-center"> <div class="opacity-85 mb-3">@loadedProducts @Translate("out of") @productList.TotalProductsCount @Translate("products")</div> @if (productList.PageCount != 1 && maxProductsCounter == 0) { string sortBySelection = Dynamicweb.Context.Current.Request?.Form["SortBy"] ?? ""; sortBySelection = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("SortBy")) ? Dynamicweb.Context.Current.Request.QueryString.Get("SortBy") : sortBySelection; string mainProductId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("MainProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("MainProductID") : ""; <form method="get" action="@url" data-response-target-element="content" class="w-100"> @if (productList?.FacetGroups != null) { foreach (FacetGroupViewModel facetGroup in productList.FacetGroups) { foreach (FacetViewModel facetItem in facetGroup.Facets) { foreach (FacetOptionViewModel facetOption in facetItem.Options) { if (facetOption.Selected) { <input type="hidden" name="@facetItem.QueryParameter" value="[@facetOption.Value]"> } } } } } @if (!string.IsNullOrEmpty(searchQuery)) { <input type="hidden" name="q" value="@searchQuery"> <input type="hidden" name="SearchLayout" value="@searchLayout"> } @if (!string.IsNullOrEmpty(mainProductId)) { <input type="hidden" name="MainProductID" value="@mainProductId"> } @if (productList?.Group?.Id != null) { <input type="hidden" name="GroupId" value="@productList.Group.Id"> } <input type="hidden" name="PageSize" value="@pageSize"> <input type="hidden" name="SortBy" value="@sortBySelection"> <input type="hidden" name="RequestType" value="UpdateList"> @if (productList?.FacetGroups is object) { string nextPageLink = "/Default.aspx?ID=" + Pageview.Page.ID + "&PageSize=" + pageSize + "&SortBy=" + sortBySelection; foreach (FacetGroupViewModel facetGroup in productList.FacetGroups) { foreach (FacetViewModel facetItem in facetGroup.Facets) { foreach (FacetOptionViewModel facetOption in facetItem.Options) { if (facetOption.Selected) { nextPageLink += "&" + facetItem.QueryParameter + "=[" + facetOption.Value + "]"; } } } } nextPageLink += productList?.Group?.Id != null ? "&GroupID=" + productList.Group.Id : ""; nextPageLink += !string.IsNullOrEmpty(searchQuery) ? "&q=" + searchQuery : ""; <a href="@nextPageLink" class="btn btn-primary" onclick="swift.ProductList.Update(event)" id="LoadMoreButton_@Model.ID">@Translate("Load more products")</a> } else { string nextPageLink = "/Default.aspx?ID=" + Pageview.Page.ID + "&PageSize=" + pageSize + "&SortBy=" + sortBySelection; nextPageLink += productList?.Group?.Id != null ? "&GroupID=" + productList.Group.Id : ""; nextPageLink += !string.IsNullOrEmpty(searchQuery) ? "&q=" + searchQuery : ""; <a href="@nextPageLink" class="btn btn-primary" onclick="swift.ProductList.Update(event)" id="LoadMoreButton_@Model.ID">@Translate("Load more products")</a> } </form> } </div> </div> <script> function switchVariantProduct(id, price, imagesrc) { var productImageElement = document.querySelector("#ProductImage_" + id); var productPriceElement = document.querySelector("#ProductPrice_" + id + " .text-price"); if (productPriceElement) { productPriceElement.innerText = price; } if (productImageElement) { productImageElement.src = imagesrc; var imageSrcset = productImageElement.srcset; imageSrcset = imageSrcset.replace(/image=.*?&/g, 'image=' + imagesrc + "&"); productImageElement.srcset = imageSrcset; } } </script> } else if (Pageview.IsVisualEditorMode) { <div class="alert alert-dark m-0" role="alert"> <span>@Translate("The selected component does not exist anymore")</span> </div> } } else { string noProductsFoundMessage = !string.IsNullOrEmpty(Model.Item.GetString("NoProductsFoundMessage")) ? Model.Item.GetString("NoProductsFoundMessage") : Translate("We did not find anything matching your search result"); bool hasSubgroups = false; if (productList.SubGroups != null) { hasSubgroups = productList.SubGroups.Any(); } if (!Model.Item.GetBoolean("HideNoProductsFoundMessage")) { if (!isVisualEditor) { <div class="alert alert-dark m-0" role="alert"> @noProductsFoundMessage </div> } else { <div class="alert alert-dark m-0" role="alert"> @Translate("Product list: The list will be shown here, if any") </div> } } else if (!hasSubgroups) { <div class="alert alert-dark m-0" role="alert"> @noProductsFoundMessage </div> } } } </div> } else if (Pageview.IsVisualEditorMode) { <div class="alert alert-dark m-0" role="alert"> <span>@Translate("Product list item repeater: The repeater paragraph will be shown here, if any products are available")</span> </div> }