Total Items: 55
Sort By
Error executing template "/Designs/Swift/Paragraph/Custom_Swift_ProductListItemRepeater.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.DynamicwebLiveIntegration_ZB.Products.ProductPriceProvider.PreparePrices(PriceContext context, IEnumerable`1 selections)
   at Dynamicweb.Ecommerce.Prices.PriceManager.PreparePrices(PriceContext context, IEnumerable`1 selections)
   at Dynamicweb.Ecommerce.Prices.PriceManager.PreparePrices(PriceContext context, IEnumerable`1 products, Int64 stockLocationId)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.PreparePrices(PriceContext context, Boolean& pricesHasBeenPrepared, Object lock, IList`1 products, Int64 stockLocationId)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetPrice(PriceViewModelSettings settings, IList`1 products, Boolean& pricesHasBeenPrepared, Object lock, Lazy`1 priceInfo)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass11_2.<BulkCreateView>b__50()
   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_e735cd7220a441abae857a6425b6a430.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 @using Dynamicweb.Core 4 @using Dynamicweb.Ecommerce 5 6 @{ 7 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 8 int productsCount = 0; 9 int maxProductsCounter = 0; 10 11 string productInfoFeed = ""; 12 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 13 if (isLazyLoadingForProductInfoEnabled) 14 { 15 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 16 { 17 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 18 if (!string.IsNullOrEmpty(productInfoFeed)) 19 { 20 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 21 } 22 } 23 } 24 25 ProductListViewModel productList = null; 26 if (Dynamicweb.Context.Current.Items.Contains("ProductList")) 27 { 28 productList = (ProductListViewModel)Dynamicweb.Context.Current.Items["ProductList"]; 29 } 30 else if (Pageview.Page.Item["DummyProductGroup"] != null && Pageview.IsVisualEditorMode) 31 { 32 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 33 ProductListViewModel groupList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 34 35 if (groupList?.Products is object) 36 { 37 productList = groupList; 38 } 39 } 40 } 41 42 @if (productList is object) 43 { 44 <div class="h-100@(theme) product-list item_@Model.Item.SystemName.ToLower()" @productInfoFeed> 45 @{ 46 bool isVisualEditor = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("VisualEdit")) ? Convert.ToBoolean(Dynamicweb.Context.Current.Request.QueryString.Get("VisualEdit")) : false; 47 48 string groupId = productList?.Group?.Id != null ? productList.Group.Id : ""; 49 string url = Dynamicweb.Context.Current.Request.RawUrl; 50 Dynamicweb.Ecommerce.Products.Group currgroup = Services.ProductGroups.GetGroup(groupId); 51 var subGroups = currgroup != null ? Services.ProductGroups.GetSubgroups(currgroup) : null; 52 int subGroupsCount = subGroups != null ? subGroups.Count() : 0; 53 54 if(subGroupsCount == 0) 55 { 56 if (productList.TotalProductsCount > 0) 57 { 58 int pageSizeSetting = Converter.ToInt32(Dynamicweb.Context.Current.Request.QueryString.Get("OriginalPageSize")) > 0 ? Converter.ToInt32(Dynamicweb.Context.Current.Request.QueryString.Get("OriginalPageSize")) : productList.PageSize; 59 int pageNumber = Converter.ToInt32(Dynamicweb.Context.Current.Request.QueryString.Get("PageNum")) > 0 ? Converter.ToInt32(Dynamicweb.Context.Current.Request.QueryString.Get("PageNum")) : productList.CurrentPage; 60 int pageSize = Converter.ToInt32(Dynamicweb.Context.Current.Request.QueryString.Get("PageSize")) > 0 ? Converter.ToInt32(Dynamicweb.Context.Current.Request.QueryString.Get("PageSize")) : productList.PageSize; 61 pageNumber = pageSize != pageSizeSetting ? (pageSize / pageSizeSetting) : pageNumber; 62 int loadedProducts = productList.PageSize > productList.TotalProductsCount ? productList.TotalProductsCount : pageSizeSetting * pageNumber; 63 loadedProducts = loadedProducts > productList.TotalProductsCount ? productList.TotalProductsCount : loadedProducts; 64 65 pageNumber += 1; 66 67 string searchQuery = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("q")) ? Dynamicweb.Context.Current.Request.QueryString.Get("q") : string.Empty; 68 searchQuery = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("q")) ? Dynamicweb.Context.Current.Request.Form.Get("q") : searchQuery; 69 string searchLayout = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("SearchLayout")) ? Dynamicweb.Context.Current.Request.QueryString.Get("SearchLayout") : string.Empty; 70 71 int itemSourcePageId = Convert.ToInt32(Model.Item.GetRawValueString("ListComponentSource", "0")); 72 int itemListSourcePageId = GetPageIdByNavigationTag("ProductListViewComponent"); 73 74 var pageService = new Dynamicweb.Content.PageService(); 75 itemSourcePageId = itemSourcePageId > 0 && pageService.GetPageOrLanguage(itemSourcePageId, Pageview.AreaID) != null ? pageService.GetPageOrLanguage(itemSourcePageId, Pageview.AreaID).ID : itemSourcePageId; 76 77 var page = Dynamicweb.Content.Services.Pages.GetPage(itemSourcePageId); 78 var listpage = Dynamicweb.Content.Services.Pages.GetPage(itemListSourcePageId); 79 string listView = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("ListView")) ? Dynamicweb.Context.Current.Request.QueryString.Get("ListView") : "Yes"; 80 81 if (page != null && listpage != null) 82 { 83 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page); 84 85 string gridColumnSize = Model.Item.GetRawValueString("GridLayoutDesktop", "3-columns"); 86 gridColumnSize = gridColumnSize == "2-columns" ? "g-col-lg-6" : gridColumnSize; 87 gridColumnSize = gridColumnSize == "3-columns" ? "g-col-lg-4" : gridColumnSize; 88 gridColumnSize = gridColumnSize == "4-columns" ? "g-col-lg-3" : gridColumnSize; 89 gridColumnSize = gridColumnSize == "6-columns" ? "g-col-lg-2" : gridColumnSize; 90 gridColumnSize = gridColumnSize == "list" ? "g-col-lg-12" : gridColumnSize; 91 92 string gridColumnMobileSize = Model.Item.GetRawValueString("GridLayoutMobile", "2-columns"); 93 gridColumnMobileSize = gridColumnMobileSize == "list" ? "g-col-12" : gridColumnMobileSize; 94 gridColumnMobileSize = gridColumnMobileSize == "2-columns" ? "g-col-6" : gridColumnMobileSize; 95 96 var listpageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page); 97 98 string listColumnSize = listpageViewModel.Item.GetRawValueString("GridLayoutDesktop", "3-columns"); 99 gridColumnSize = gridColumnSize == "2-columns" ? "g-col-lg-6" : gridColumnSize; 100 gridColumnSize = gridColumnSize == "3-columns" ? "g-col-lg-4" : gridColumnSize; 101 gridColumnSize = gridColumnSize == "4-columns" ? "g-col-lg-3" : gridColumnSize; 102 gridColumnSize = gridColumnSize == "6-columns" ? "g-col-lg-2" : gridColumnSize; 103 gridColumnSize = gridColumnSize == "list" ? "g-col-lg-12" : gridColumnSize; 104 105 string listColumnMobileSize = listpageViewModel.Item.GetRawValueString("GridLayoutMobile", "2-columns"); 106 gridColumnMobileSize = gridColumnMobileSize == "list" ? "g-col-12" : gridColumnMobileSize; 107 gridColumnMobileSize = gridColumnMobileSize == "2-columns" ? "g-col-6" : gridColumnMobileSize; 108 109 110 string listItemTheme = " theme " + pageViewModel.Item.GetRawValueString("Theme", string.Empty).Replace(" ", "").Trim().ToLower(); 111 string listItemPadding = pageViewModel.Item.GetRawValueString("ContentPadding", string.Empty); 112 string listItemPaddingClass = string.Empty; 113 114 switch (listItemPadding) 115 { 116 case "small": 117 listItemPaddingClass = " p-2 p-xl-3"; 118 break; 119 case "large": 120 listItemPaddingClass = " p-3 p-xl-4"; 121 break; 122 case "small-x": 123 listItemPaddingClass = " px-2 px-md-3"; 124 break; 125 case "large-x": 126 listItemPaddingClass = " px-3 px-md-4"; 127 break; 128 } 129 130 <div class="grid pb-3 cus-productgridview" @(listView=="Yes"?"style='display:none;'":"")> 131 <script> 132 gtag("event", "view_item_list", { 133 item_list_id: "product_list_item_repeater", 134 item_list_name: "Product list (Item Repeater)", 135 items: [ 136 @foreach (ProductViewModel product in productList.Products) 137 { 138 <text>{ 139 item_id: "@product.Number", 140 item_name: "@Dynamicweb.Core.Encoders.HtmlEncoder.JavaScriptStringEncode(product.Name)", 141 currency: "@product.Price.CurrencyCode", 142 price: @product.Price.ToStringInvariant(), 143 discount: @product.Discount.ToStringInvariant() 144 },</text> 145 } 146 ] 147 }); 148 </script> 149 150 @foreach (ProductViewModel product in productList.Products) 151 { 152 if (maxProductsCounter == 0 || (productsCount < maxProductsCounter)) 153 { 154 string link = product.GetProductLink(GetPageIdByNavigationTag("Shop"), false); 155 156 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 157 { 158 Dynamicweb.Context.Current.Items["ProductDetails"] = product; 159 } 160 else 161 { 162 Dynamicweb.Context.Current.Items.Add("ProductDetails", product); 163 } 164 165 if (Model.Item.GetString("ListComponentSource") != null) 166 { 167 double? maxQty = null; 168 if (product.ProductType == Dynamicweb.Ecommerce.Products.ProductType.Stock && !product.NeverOutOfstock) 169 { 170 maxQty = product.StockLevel; 171 } 172 173 var callforprice = product.ProductFields.Values.FirstOrDefault(x => x.SystemName == "Call_for_Price")?.Value; 174 string callforpricestr=""; 175 if (callforprice != null) 176 { 177 if (callforprice.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) 178 { 179 var callpriceopt=callforprice as System.Collections.Generic.List<FieldOptionValueViewModel>; 180 foreach(FieldOptionValueViewModel opt in callpriceopt) 181 { 182 callforpricestr=opt.Value.ToString(); 183 } 184 } 185 else 186 { 187 callforpricestr=callforprice.ToString(); 188 } 189 } 190 191 <article class="@gridColumnMobileSize @gridColumnSize @listItemTheme d-flex flex-column position-relative product cus-plist__container cus-plist__gridcontainer @(callforpricestr != "Yes" && maxQty == 0 ? "" : "cus-plist__gridemptycontainer") js-product" data-product-id="@product.Id" data-variant-id="@product.VariantId" itemscope itemtype="https://schema.org/Product"> 192 @{ 193 string clickProductLink = "onclick=\"return clickProductLink('" + @product.Id + "', '" + @product.Name + "', '" + @product.VariantName + "', '" + @product.Price.CurrencyCode + "', '" + @product.Price.ToStringInvariant() + "', '" + @product.Discount.ToStringInvariant() + "')\""; 194 } 195 <a href="@link" class="stretched-link" onmouseover="swift.Image.swapImage(event)" onmouseout="swift.Image.swapImage(event)" @clickProductLink> 196 <span class="visually-hidden">@product.Name</span> 197 </a> 198 199 <script> 200 function clickProductLink(productId, productName, productVariant, productCurrency, productPrice, productDiscount) { 201 if (typeof gtag !== "undefined") { 202 gtag("event", "select_item", { 203 item_list_id: "product_list_item_repeater", 204 item_list_name: "Product list (Item Repeater)", 205 items: [ 206 { 207 item_id: productId, 208 item_name: productName, 209 currency: productCurrency, 210 item_list_id: "product_list_item_repeater", 211 item_list_name: "Product list (Item Repeater)", 212 item_variant: productVariant, 213 price: productPrice, 214 discount: productDiscount 215 } 216 ] 217 }); 218 } 219 } 220 </script> 221 222 @RenderGrid(itemSourcePageId) 223 </article> 224 } 225 226 productsCount++; 227 } 228 } 229 </div> 230 231 <div class="grid pb-3 cus-productlistview" @(listView=="Yes"?"":"style='display:none;'")> 232 233 @foreach (ProductViewModel product in productList.Products) 234 { 235 if (maxProductsCounter == 0 || (productsCount < maxProductsCounter)) 236 { 237 string link = product.GetProductLink(GetPageIdByNavigationTag("Shop"), false); 238 239 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 240 { 241 Dynamicweb.Context.Current.Items["ProductDetails"] = product; 242 } 243 else 244 { 245 Dynamicweb.Context.Current.Items.Add("ProductDetails", product); 246 } 247 248 if (Model.Item.GetString("ListComponentSource") != null) 249 { 250 <article class="g-col-12 g-col-lg-12 @listItemTheme d-flex flex-column cus-plist__container cus-plist__listcontainer position-relative product js-product" data-product-id="@product.Id" data-variant-id="@product.VariantId" itemscope itemtype="https://schema.org/Product"> 251 @{ 252 string clickProductLink = "onclick=\"return clickProductLink('" + @product.Id + "', '" + @product.Name + "', '" + @product.VariantName + "', '" + @product.Price.CurrencyCode + "', '" + @product.Price.ToStringInvariant() + "', '" + @product.Discount.ToStringInvariant() + "')\""; 253 } 254 <a href="@link" class="stretched-link" onmouseover="swift.Image.swapImage(event)" onmouseout="swift.Image.swapImage(event)" @clickProductLink> 255 <span class="visually-hidden">@product.Name</span> 256 </a> 257 258 <script> 259 function clickProductLink(productId, productName, productVariant, productCurrency, productPrice, productDiscount) { 260 if (typeof gtag !== "undefined") { 261 gtag("event", "select_item", { 262 item_list_id: "product_list_item_repeater", 263 item_list_name: "Product list (Item Repeater)", 264 items: [ 265 { 266 item_id: productId, 267 item_name: productName, 268 currency: productCurrency, 269 item_list_id: "product_list_item_repeater", 270 item_list_name: "Product list (Item Repeater)", 271 item_variant: productVariant, 272 price: productPrice, 273 discount: productDiscount 274 } 275 ] 276 }); 277 } 278 } 279 </script> 280 281 @RenderGrid(itemListSourcePageId) 282 </article> 283 } 284 285 productsCount++; 286 } 287 } 288 </div> 289 290 <div class="my-3" id="ProductListLoadMore"> 291 <div class="text-center"> 292 <div class="opacity-85 mb-3">@loadedProducts @Translate("out of") @productList.TotalProductsCount @Translate("products")</div> 293 @if (productList.PageCount != 1 && maxProductsCounter == 0 && loadedProducts < productList.TotalProductsCount) 294 { 295 string sortBySelection = Dynamicweb.Context.Current.Request?.Form["SortBy"] ?? ""; 296 sortBySelection = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("SortBy")) ? Dynamicweb.Context.Current.Request.QueryString.Get("SortBy") : sortBySelection; 297 string mainProductId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("MainProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("MainProductID") : ""; 298 299 <form method="get" action="@url" data-response-target-element=".product-list" data-swap="afterend" class="w-100"> 300 @if (productList?.FacetGroups != null) 301 { 302 foreach (FacetGroupViewModel facetGroup in productList.FacetGroups) 303 { 304 foreach (FacetViewModel facetItem in facetGroup.Facets) 305 { 306 foreach (FacetOptionViewModel facetOption in facetItem.Options) 307 { 308 if (facetOption.Selected) 309 { 310 <input type="hidden" name="@facetItem.QueryParameter" value="[@facetOption.Value]"> 311 } 312 } 313 } 314 } 315 } 316 317 @if (!string.IsNullOrEmpty(searchQuery)) 318 { 319 <input type="hidden" name="q" value="@searchQuery"> 320 <input type="hidden" name="SearchLayout" value="@searchLayout"> 321 } 322 323 @if (!string.IsNullOrEmpty(mainProductId)) 324 { 325 <input type="hidden" name="MainProductID" value="@mainProductId"> 326 } 327 328 @if (productList?.Group?.Id != null) 329 { 330 <input type="hidden" name="GroupId" value="@groupId"> 331 } 332 333 <input type="hidden" name="OriginalPageSize" value="@pageSizeSetting"> 334 <input type="hidden" name="PageSize" value="@(loadedProducts + pageSizeSetting)"> 335 <input type="hidden" name="PageNum" value="@pageNumber"> 336 <input type="hidden" name="SortBy" value="@sortBySelection"> 337 <input type="hidden" name="RequestType" value="UpdateList"> 338 <input type="hidden" name="ParagraphID" value="@Model.ID"> 339 <input type="hidden" name="ListView" class="ProductListView" value="@listView"> 340 341 @if (productList?.FacetGroups is object) 342 { 343 string nextPageLink = $"/Default.aspx?ID={Pageview.Page.ID}&PageNum={pageNumber}&SortBy={sortBySelection}"; 344 345 foreach (FacetGroupViewModel facetGroup in productList.FacetGroups) 346 { 347 foreach (FacetViewModel facetItem in facetGroup.Facets) 348 { 349 foreach (FacetOptionViewModel facetOption in facetItem.Options) 350 { 351 if (facetOption.Selected) 352 { 353 nextPageLink += "&" + facetItem.QueryParameter + "=[" + facetOption.Value + "]"; 354 } 355 } 356 } 357 } 358 359 nextPageLink += !string.IsNullOrEmpty(searchQuery) ? "&q=" + searchQuery : ""; 360 string disableLoadMore = isLazyLoadingForProductInfoEnabled ? "d-none" : ""; 361 362 <a href="@nextPageLink" class="btn btn-primary cus-plist__loadbtn swift_load_more_button @disableLoadMore" onclick="swift.ProductList.Update(event)" id="LoadMoreButton_@Model.ID">@Translate("Load more products")</a> 363 } 364 </form> 365 } 366 </div> 367 </div> 368 369 <script> 370 function switchVariantProduct(id, price, imagesrc) { 371 var productImageElement = document.querySelector("#ProductImage_" + id); 372 var productPriceElement = document.querySelector("#ProductPrice_" + id + " .text-price"); 373 374 if (productPriceElement) { 375 productPriceElement.innerText = price; 376 } 377 378 if (productImageElement) { 379 productImageElement.src = imagesrc; 380 381 var imageSrcset = productImageElement.srcset; 382 imageSrcset = imageSrcset.replace(/image=.*?&/g, 'image=' + imagesrc + "&"); 383 384 productImageElement.srcset = imageSrcset; 385 } 386 } 387 // $(".cus-plist__listcontainer .item_swift_4columnscomponentedit").next().addClass("flex-wrap"); 388 </script> 389 } 390 else if (Pageview.IsVisualEditorMode) 391 { 392 <div class="alert alert-dark m-0" role="alert"> 393 <span>@Translate("The selected component does not exist anymore")</span> 394 </div> 395 } 396 } 397 else 398 { 399 string noProductsFoundMessage = !string.IsNullOrEmpty(Model.Item.GetString("NoProductsFoundMessage")) ? Model.Item.GetString("NoProductsFoundMessage") : Translate("We did not find anything matching your search result"); 400 bool hasSubgroups = false; 401 402 if (productList.SubGroups != null) 403 { 404 hasSubgroups = productList.SubGroups.Any(); 405 } 406 407 if (!Model.Item.GetBoolean("HideNoProductsFoundMessage")) 408 { 409 if (!isVisualEditor) 410 { 411 <div class="alert alert-dark m-0" role="alert"> 412 @noProductsFoundMessage 413 </div> 414 } 415 else 416 { 417 <div class="alert alert-dark m-0" role="alert"> 418 @Translate("Product list: The list will be shown here, if any") 419 </div> 420 } 421 } 422 else if (!hasSubgroups) 423 { 424 <div class="alert alert-dark m-0" role="alert"> 425 @noProductsFoundMessage 426 </div> 427 } 428 } 429 } 430 } 431 </div> 432 } 433 else if (Pageview.IsVisualEditorMode) 434 { 435 <div class="alert alert-dark m-0" role="alert"> 436 <span>@Translate("Product list item repeater: The repeater paragraph will be shown here, if any products are available")</span> 437 </div> 438 } 439
By clicking 'Accept All' you consent that we may collect information about you for various purposes, including: Statistics and Marketing