Lagervarer bestilt inden kl. 12 - Afsendes samme dag. Salg kun til erhverv   Gratis levering ved køb over 1.500 kr. - Levering 1-3 dage   Nememballage.dk er en del af KD Emballage. Dansk leverandør af emballage

Error executing template "Designs/Nememballage/eCom/ProductCatalog/ProductViewList.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_d5b348b94f2f4184bb3af51f66327a68.Execute() in D:\web\kde.dk\Website\Files\Templates\Designs\Nememballage\eCom\ProductCatalog\ProductViewList.cshtml:line 524
   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.b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @using Dynamicweb.Rendering 2 @using Dynamicweb.Ecommerce.ProductCatalog 3 @using System.Linq; 4 @inherits ViewModelTemplate<ProductListViewModel> 5 6 @using Dynamicweb.Rendering 7 @using Dynamicweb.Ecommerce.ProductCatalog 8 @using System; 9 @using System.Collections.Generic; 10 @using System.Linq; 11 12 @helper HelperRenderProductList(IList<ProductViewModel> products, string groupCategoryname = "") 13 { 14 int webshopPageId = GetPageIdByNavigationTag("Shop"); 15 16 for (int i = 0; i < products.Count; i++) 17 { 18 var productApi = new Dynamicweb.Ecommerce.Products.ProductService().GetProductById(products[i].Id, "", products[i].LanguageId); 19 if (productApi == null) 20 { 21 continue; 22 } 23 24 var group = productApi.GetDefaultGroupByShopId("SHOP2"); 25 var title = new Website.Helpers.Product().GetTitle(products[i]); 26 var resizedImage = VestjyskMarketing.Helpers.ImageHelper.ResizeImage(products[i].DefaultImage.Value, 600, 500); 27 if (group == null) 28 { 29 continue; 30 } 31 32 33 string productLink = "/Default.aspx?ID=" + webshopPageId + "&amp;GroupID=" + group.Id + "&amp;ProductID=" + products[i].Id; 34 double productPrice = new Website.Helpers.Prices().GetCheapestPrice("", products[i].Number, true); 35 FieldValueViewModel hideBuy; 36 FieldValueViewModel oldprice; 37 FieldValueViewModel environmentLogoEnable; 38 products[i].ProductFields.TryGetValue("HideBuy", out hideBuy); 39 products[i].ProductFields.TryGetValue("Gl_salgspris", out oldprice); 40 products[i].ProductFields.TryGetValue("MiljoeVenligtValg", out environmentLogoEnable); 41 42 //get height, lenght and width productinfoL: 190 MM B: 100 MM H: 70 MM 43 List<Tuple<string, string>> dimensionsList = new Website.Helpers.Product().GetProductFieldsDimensions(products[i]); 44 45 string fscLogo = VestjyskMarketing.Helpers.ImageHelper.ResizeImage("/Files/Images/Logoer/FSC_Logo.png", 50, 50,6); 46 bool fscApproved = new Website.Helpers.Product().GetProductCategoryField("FSC_godkendt", products[i]) == "True" ? true : false; 47 48 <div class="productlist__item bg-light"> 49 <div class="row no-gutters"> 50 <div class="col-lg-3 col-xl-2 productlist__item__image" style="background-image: url(@resizedImage);"> 51 52 </div> 53 <div class="col-lg-5 col-xl-6"> 54 <div class="productlist__item__content"> 55 <h2><a href="@productLink" title="@Translate(" Gå til:") @title">@title</a></h2> 56 @if (dimensionsList.Count > 0) 57 { 58 <div class="productlist__item__fields text-primary font-weight-bold"> 59 @foreach (var dimension in dimensionsList) 60 { 61 <span> 62 @dimension.Item1.Substring(0, 1): @dimension.Item2 63 @if (dimension.Item1.ToLower().Contains("(m)")) 64 { 65 <text>M</text> 66 } 67 else 68 { 69 <text>MM</text> 70 } 71 </span> 72 } 73 </div> 74 } 75 <div class="productlist__item__number font-weight-bold">@Translate("Varenummer"): @products[i].Number</div> 76 77 @if (fscApproved) 78 { 79 <a class="productlist-miljø-link" href="Default.aspx?ID=@GetPageIdByNavigationTag("environmentpage")"> 80 <img src="@fscLogo" class="img-fluid productlist__item__fsc " alt="FSC logo" title="FSC Godkendt" /> 81 </a> 82 } 83 @if (Dynamicweb.Core.Converter.ToBoolean(environmentLogoEnable.Value)) 84 { 85 string environmentLogo = VestjyskMarketing.Helpers.ImageHelper.ResizeImage("/Files/Images/Logoer/Nem_Logo_miljø_FINAL.png", 50, 50,6); 86 <a class="productlist-miljø-link" href="Default.aspx?ID=@GetPageIdByNavigationTag("environmentpage")"> 87 <img src="@environmentLogo" class="img-fluid productlist__item__fsc " alt="Miljøvenligt valg" title="Miljøvenligt valg" /> 88 </a> 89 } 90 </div> 91 </div> 92 <div class="col-lg-4 text-right"> 93 <div class="productlist__item__price__container "> 94 @if (Convert.ToBoolean(hideBuy.Value) == false) 95 { 96 <div class="productlist__item__price"> 97 98 Priser fra&nbsp; &nbsp;<span class="productlist__item__price__highlight">@string.Format("{0:0.00}", productPrice) DKK</span> 99 <div class="productlist__item__price__vat">eksl. moms</div> 100 @if (Dynamicweb.Core.Converter.ToDecimal(oldprice.Value) > 0) 101 { 102 <span class="productlist__item__oldprice">@string.Format("{0:0.00}", oldprice.Value) DKK</span> 103 } 104 </div> 105 } 106 <a class="btn btn-outline-primary rounded-pill btn-round btn-block" href="@productLink" title="@Translate(" Gå til:") @products[i].Title ">Se produkt</a> 107 </div> 108 </div> 109 </div> 110 </div> 111 } 112 } 113 114 @helper HelperRenderProductSpotList(List<ProductViewModel> products) 115 { 116 int webshopPageId = GetPageIdByNavigationTag("Shop"); 117 118 119 <div class="row"> 120 121 @foreach (var product in products) 122 { 123 var productApi = new Dynamicweb.Ecommerce.Products.ProductService().GetProductById(product.Id, "", product.LanguageId); 124 if (productApi == null) 125 { 126 continue; 127 } 128 129 var resizedImage = VestjyskMarketing.Helpers.ImageHelper.ResizeImage(product.DefaultImage.Value, 433, 353); 130 string productLink = "/Default.aspx?ID=" + webshopPageId + "&amp;GroupID=" + product.PrimaryOrDefaultGroup.Id + "&amp;ProductID=" + product.Id; 131 string productPrice = new Website.Helpers.Prices().GetOnePiecePrice("", productApi.Number, Convert.ToInt32(productApi.PurchaseMinimumQuantity), true, false, true); 132 FieldValueViewModel hideBuy; 133 product.ProductFields.TryGetValue("HideBuy", out hideBuy); 134 135 <div class="col-12 col-lg-6 col-xl-3 px-0 px-lg-2 mb-5 mb-lg-3"> 136 <div class="productlist-spot__item"> 137 <div class="row h-100"> 138 <div class="col-3 col-lg-12"> 139 <div class="productlist-spot__item__img" style="background-image: url(@resizedImage)"></div> 140 </div> 141 <div class="col-9 col-lg-12"> 142 <div class="productlist-spot__item__description"> 143 <p class="productlist-spot__item__title"><a href="@productLink" title="@Translate(" Gå til:") @product.Title ">@product.Title</a></p> 144 <p class="productlist-spot__item__number">Varenummer: @product.Number</p> 145 </div> 146 </div> 147 148 <div class="col-12 mt-auto "> 149 <div class="productlist-spot__item__content"> 150 <div class="row"> 151 <div class="col-7 p-0 pl-4 pl-lg-0 pr-lg-3"> 152 @if (Convert.ToBoolean(hideBuy.Value) == false) 153 { 154 <p class="productlist-spot__item__price">Priser fra <br /> <strong> @productPrice DDK</strong></p> 155 <p class="productlist-spot__item__tax">ekskl. moms</p> 156 } 157 158 </div> 159 <div class="col-5 d-flex justify-content-end pr-2 p-0 p-lg-2"> 160 <a class="btn btn-round align-self-end rounded-pill productlist-spot__item__link " href="@productLink" title="@Translate(" Gå til:") @product.Title">Se produkt</a> 161 </div> 162 </div> 163 </div> 164 </div> 165 </div> 166 </div> 167 </div> 168 } 169 </div> 170 171 } 172 173 174 @using Dynamicweb.Rendering 175 @using Dynamicweb.Ecommerce.ProductCatalog 176 @using System; 177 @using System.Linq; 178 @inherits ViewModelTemplate<ProductListViewModel> 179 180 181 @helper RenderFacetRange(FacetGroupViewModel facetGroup, FacetViewModel facetItem) 182 { 183 var queryParameter = facetItem.QueryParameter; 184 var queryParameterSelected = Dynamicweb.Context.Current.Request.QueryString[queryParameter]; 185 186 int rangeStart = 0; 187 int rangeEnd = Dynamicweb.Core.Converter.ToInt32(facetItem.MaximumFacetValue); 188 189 if (rangeEnd > 0) 190 { 191 int rangeStartSelected = rangeStart; 192 int rangeEndSelected = rangeEnd; 193 int queryParameterSelectedActive = 0; 194 if (queryParameterSelected != null) 195 { 196 queryParameterSelectedActive = 1; 197 rangeStartSelected = Dynamicweb.Core.Converter.ToInt32(queryParameterSelected.Split(',')[0]); 198 rangeEndSelected = Dynamicweb.Core.Converter.ToInt32(queryParameterSelected.Split(',')[1]); 199 } 200 201 <div class="productlist__filter__facetgroup"> 202 <div class="row"> 203 <div class="col text-uppercase font-weight-bold">@facetItem.Name:</div> 204 <div class="col text-right"> 205 <span id="slider-@queryParameter-value-min"></span> - 206 <span id="slider-@queryParameter-value-max"></span> 207 </div> 208 </div> 209 <div class="slider" data-update="slider-@queryParameter" data-start="@rangeStart" data-end="@rangeEnd" data-selected-start="@rangeStartSelected" data-selected-end="@rangeEndSelected"></div> 210 <input type="hidden" name="@queryParameter" id="slider-@queryParameter-input-min" value="@rangeStartSelected" /> 211 <input type="hidden" name="@queryParameter" id="slider-@queryParameter-input-max" value="@rangeEndSelected" /> 212 <input type="hidden" id="slider-@queryParameter-active" value="@queryParameterSelectedActive" /> 213 </div> 214 } 215 } 216 217 @helper RenderFacetCheckboxes(FacetGroupViewModel facetGroup, FacetViewModel facetItem) 218 { 219 var queryParameter = facetItem.QueryParameter; 220 221 if (queryParameter == "Color" || queryParameter == "Tapetype") 222 { 223 facetItem.Options = facetItem.Options.OrderByDescending(x => x.Count); 224 } 225 226 <div class="productlist__filter__facetgroup"> 227 <div class="text-uppercase font-weight-bold">@facetItem.Name:</div> 228 <div class="productlist__filter__checkboxes"> 229 @foreach (var facetOption in facetItem.Options) 230 { 231 var label = queryParameter == "Color" ? Translate(facetOption.Label) : facetOption.Label; 232 var name = facetOption.Name; 233 var value = facetOption.Value; 234 var count = facetOption.Count; 235 var selected = facetOption.Selected ? "checked" : ""; 236 var disabled = count <= 0 ? "disabled" : ""; 237 238 <div class="productlist__filter__checkboxes__item"> 239 <input class="styled-checkbox" type="checkbox" id="@queryParameter-@value" value="@value" name="@queryParameter" @selected @disabled> 240 <label for="@queryParameter-@value">@label (@(count))</label> 241 </div> 242 } 243 </div> 244 245 @if (facetItem.OptionActiveCount > 2) 246 { 247 <button class="reset-button font-weight-bold js-show-allfilters"><i class="fas fa-plus"></i> Se alle</button> 248 } 249 250 </div> 251 } 252 253 @helper RenderFacets(ProductListViewModel model) 254 { 255 var facetsUsed = Dynamicweb.Core.Converter.ToString(Model.Group?.GroupFields.Where(x => x.SystemName.Equals("FacetsUsed")).Select(x => x.Value).FirstOrDefault()).Split(',').ToList(); 256 257 //for topgroups 258 if (string.IsNullOrEmpty(facetsUsed[0])) 259 { 260 string groupIds = Dynamicweb.Context.Current.Request["GroupID"] ?? ""; 261 if (!string.IsNullOrEmpty(groupIds)) 262 { 263 string groupId = groupIds.Split(',')[0]; 264 var group = Dynamicweb.Ecommerce.Products.Group.GetGroupById(groupId); 265 if (group != null && group.IsTopGroup) 266 { 267 268 facetsUsed = Dynamicweb.Core.Converter.ToString(group.ProductGroupFieldValues.GetProductGroupFieldValue("FacetsUsed").Value).Split(',').ToList(); 269 } 270 } 271 } 272 273 <form id="js-productlist-filter"> 274 275 <div class="text-right d-xl-none"> 276 <button class="reset-button productlist__filter__close js-filter-trigger" title="Luk"><i class="fa fa-times"></i></button> 277 </div> 278 279 <div class="row"> 280 <div class="col"> 281 <div class="h2 font-weight-bold">Filtré</div> 282 </div> 283 <div class="col text-right"> 284 <button class="btn btn-sm btn-primary rounded-pill productlist__filter__reset"><span class="fas fa-times"></span> Nulstil</button> 285 </div> 286 </div> 287 288 @foreach (var facetGroup in model.FacetGroups) 289 { 290 foreach (var facetItem in facetGroup.Facets) 291 { 292 var optionActiveCount = facetItem.OptionActiveCount; 293 var facetOptionResultTotalCount = facetItem.OptionResultTotalCount; 294 var template = facetItem.RenderType; 295 296 if (optionActiveCount > 0 && facetOptionResultTotalCount > 0 && facetsUsed.Contains(facetItem.FacetField)) 297 { 298 switch (template) 299 { 300 case "Range": 301 @RenderFacetRange(facetGroup, facetItem) 302 break; 303 304 default: 305 @RenderFacetCheckboxes(facetGroup, facetItem) 306 break; 307 } 308 309 } 310 } 311 } 312 313 <button class="btn btn-primary rounded-pill d-xl-none js-filter-trigger mt-3 mb-3">Anvend</button> 314 315 </form> 316 317 318 319 320 321 } 322 323 324 325 @{ 326 var product = new Dynamicweb.Ecommerce.Products.Product(); //@fake for breadcrumb. Dumb hack; 327 int webshopPageId = GetPageIdByNavigationTag("Shop"); 328 string groupId = Dynamicweb.Context.Current.Request["GroupID"] ?? ""; 329 string groupIdQueryParameter = string.IsNullOrEmpty(groupId) 330 ? string.Empty 331 : "&GroupID=" + Dynamicweb.Context.Current.Request["GroupID"]; 332 333 if (!String.IsNullOrEmpty(groupId)) 334 { 335 var group = Dynamicweb.Ecommerce.Products.Group.GetGroupById(groupId); 336 if (group != null && group.IsTopGroup) 337 { 338 foreach (var subgroup in group.Subgroups) 339 { 340 groupIdQueryParameter += "," + subgroup.Id; 341 } 342 } 343 } 344 345 string sortGroup = Dynamicweb.Core.Converter.ToString(Model.Group?.GroupFields.Where(x => x.SystemName.Equals("SortGroup")).Select(x => x.Value).FirstOrDefault()); 346 string sortGroupParameter = string.IsNullOrEmpty(sortGroup) 347 ? string.Empty 348 : "&SortBy=" + sortGroup + "&SortOrder=ASC"; 349 350 string search = Dynamicweb.Context.Current.Request["Search"] ?? ""; 351 string searchQueryParameter = string.IsNullOrEmpty(search) 352 ? string.Empty 353 : "&Search=" + Dynamicweb.Context.Current.Request["Search"]; 354 355 int productCatalogId = GetPageIdByNavigationTag("ProductsFeed"); 356 string feedPageUrl = "/Default.aspx?ID=" + productCatalogId + groupIdQueryParameter + searchQueryParameter + sortGroupParameter; 357 358 //Paging 359 360 int maxPageNumber = Model.PageCount; 361 int PageNumber = 1; 362 363 if (Dynamicweb.Context.Current.Request["page"] != null) 364 { 365 int _parsedPageNumber; 366 int.TryParse(Dynamicweb.Context.Current.Request["page"], out _parsedPageNumber); 367 if (_parsedPageNumber > 0) 368 { 369 PageNumber = _parsedPageNumber <= maxPageNumber ? _parsedPageNumber : maxPageNumber; 370 } 371 372 } 373 374 string _baseURL = "/Default.aspx?ID=" + Pageview.Page.ID + groupIdQueryParameter; 375 376 string NextPageUrl = String.Empty; 377 string PrevPageUrl = String.Empty; 378 379 if (maxPageNumber > 1) 380 { 381 int _nextPageNumber = (PageNumber + 1); 382 int _prevPageNumber = (PageNumber - 1); 383 384 385 // there is more than one page, perfomr paging 386 if (PageNumber < maxPageNumber) 387 { 388 NextPageUrl = _baseURL + "&page=" + _nextPageNumber; 389 } 390 if (PageNumber > 2) 391 { 392 PrevPageUrl = _baseURL + "&page=" + _prevPageNumber; 393 } 394 if (PageNumber == 2) 395 { 396 PrevPageUrl = _baseURL; 397 } 398 399 } 400 //Paging End 401 402 403 } 404 405 @SnippetStart("script") 406 407 @if (!string.IsNullOrEmpty(PrevPageUrl)) 408 { 409 <link href="@PrevPageUrl" rel="prev" /> 410 } 411 @if (!string.IsNullOrEmpty(NextPageUrl)) 412 { 413 <link href="@NextPageUrl" rel="next" /> 414 } 415 416 @SnippetEnd("script") 417 418 <input id="js_page_number" type="hidden" value="1" /> 419 <div id="ecom-container" style="position: relative;"> 420 <div class="productlist"> 421 <div class="container-fluid p-0"> 422 <div class="row no-gutters"> 423 <div class="col-3 d-none d-xl-block" id="ecom-filter-parent"> 424 <div class="productlist__filter" id="ecom-filter"> 425 </div> 426 </div> 427 428 <div class="col col-xl-9 bg-gray-theme"> 429 430 431 <div class="productlist__content"> 432 @{ 433 string groupIdBreadcrumb = Dynamicweb.Context.Current.Request["GroupID"] ?? ""; 434 string productIdBreadcrumb = Dynamicweb.Context.Current.Request["ProductID"] ?? ""; 435 var listBreadcrumbGroups = new List<Dynamicweb.Ecommerce.Products.Group>(); 436 var shop = Dynamicweb.Ecommerce.Services.Shops.GetShop("SHOP2"); 437 if (shop != null) 438 { 439 var topLevelGroups = shop.TopLevelGroups; 440 441 foreach (var topLevelGroup in topLevelGroups) 442 { 443 if (topLevelGroup.Id == groupIdBreadcrumb) 444 { 445 listBreadcrumbGroups.Add(topLevelGroup); 446 447 } 448 else 449 { 450 if (topLevelGroup.HasChildGroups) 451 { 452 foreach (var subgroup in topLevelGroup.Subgroups) 453 { 454 if (subgroup.Id == groupIdBreadcrumb) 455 { 456 listBreadcrumbGroups.Add(subgroup); 457 foreach (var parentGroup in subgroup.ParentGroups) 458 { 459 listBreadcrumbGroups.Insert(0, parentGroup); 460 } 461 } 462 } 463 } 464 } 465 } 466 } 467 } 468 469 <nav> 470 <ol class="breadcrumb"> 471 @if (String.IsNullOrEmpty(productIdBreadcrumb)) 472 { 473 <li class="breadcrumb__content__item js-breadcrumb-on-mobile d-lg-none"> 474 <a href="/"><i class="fal fa-chevron-left"> <span></span></i></a> 475 </li> 476 } 477 478 <li class="breadcrumb__content__item js-breadcrumb-off-mobile"> 479 <a href="/">Forside <span>|</span></a> 480 </li> 481 @* <li class="breadcrumb__content__item js-breadcrumb-off-mobile"> *@ 482 @* <a href="/webshop">Webshop <span>|</span></a> *@ 483 @* </li> *@ 484 485 486 @foreach (var groupBreadcrumb in listBreadcrumbGroups) 487 { 488 string activeClass = groupBreadcrumb.Id == groupIdBreadcrumb && String.IsNullOrEmpty(productIdBreadcrumb) ? "active d-block" : ""; ; 489 490 <li class="breadcrumb__content__item "> 491 <a href="/Default.aspx?ID=@Pageview.ID&GroupID=@groupBreadcrumb.Id" class="@activeClass js-breadcrumb-off-mobile"> 492 @groupBreadcrumb.Name 493 @if (groupBreadcrumb.Subgroups.Count > 0 || !String.IsNullOrEmpty(productIdBreadcrumb)) 494 { 495 <span>|</span> 496 } 497 </a> 498 </li> 499 } 500 501 502 @if (!String.IsNullOrEmpty(productIdBreadcrumb)) 503 { 504 string titleBreadcrumb = new Website.Helpers.Product().GetTitle(product); 505 <li class="breadcrumb__content__item js-breadcrumb-on-mobile d-lg-none"> 506 <a href="/Default.aspx?ID=@Pageview.ID&GroupID=@groupIdBreadcrumb"><i class="fal fa-chevron-left"> <span></span></i></a> 507 </li> 508 <li class="breadcrumb__content__item"> 509 <a href="/Default.aspx?ID=@Pageview.ID&GroupID=@groupIdBreadcrumb&ProductID=@productIdBreadcrumb" class="active"> 510 @titleBreadcrumb 511 </a> 512 </li> 513 } 514 515 </ol> 516 </nav> 517 <div class="productlist__group bg-light"> 518 <button class="productlist__filter__trigger reset-button d-xl-none js-filter-trigger"> 519 <i class="fas fa-sliders-h"></i> 520 <div>Filtré</div> 521 </button> 522 @if (!String.IsNullOrEmpty(groupId)) 523 { 524 @Model.Group.Description 525 526 List<FieldValueViewModel> seoDescription = new List<FieldValueViewModel>(); 527 seoDescription = (List<FieldValueViewModel>)Model.Group.GroupFields; 528 var seoDescriptiontext = ""; 529 foreach (var item in seoDescription) 530 { 531 if (item.SystemName == "BottomDescription") 532 { 533 seoDescriptiontext = @item.Value.ToString(); 534 } 535 } 536 537 if (seoDescriptiontext != "") 538 { 539 <div class="js-seotext-foldout hidden-seotext"> 540 @seoDescriptiontext 541 </div> 542 <a class="js-read-more"><p>Læs mere</p></a> 543 } 544 } 545 else if (Pageview.Page.ID == webshopPageId) 546 { 547 <h1>Søgeside</h1> 548 if (!String.IsNullOrEmpty(search)) 549 { 550 <h2 class="font-weight-bold">Viser resultater for "@search"</h2> 551 } 552 553 } 554 </div> 555 556 <div id="ecom-productlist"> 557 558 </div> 559 560 </div> 561 </div> 562 </div> 563 </div> 564 </div> 565 <div class="productlist__loader"></div> 566 </div> 567 568 @SnippetStart("JavaScriptBottom") 569 <script> 570 $(function () { 571 572 var $win = $(window); 573 var itemsLoaded = true; 574 var $productsListPageContainer = $('#ecom-container'); 575 var $productsContainer = $('#ecom-productlist'); 576 var $filterContainer = $('#ecom-filter'); 577 var urlAjax = "@feedPageUrl"; 578 579 var appendLoader = '<div class="productlist__loader__append text-center">'; 580 appendLoader += ' <span class="fas fa-spinner fa-pulse"></span>'; 581 appendLoader += ' </div>'; 582 583 $('.js-seotext-foldout').hide('fast'); 584 585 $('body').on('click', '.productlist__filter__reset', function (e) { 586 e.preventDefault(); 587 var urlBasic = "@feedPageUrl"; 588 GetAjax(urlBasic,1,false); 589 }); 590 591 $('body').on('click', '.js-show-allfilters', function (e) { 592 e.preventDefault(); 593 $(this).prev().toggleClass('selected'); 594 if ($(this).prev().hasClass('selected')) { 595 $(this).html("<i class='fas fa-minus'></i> Se mindre"); 596 } 597 else { 598 $(this).html("<i class='fas fa-plus'></i> Se alle"); 599 } 600 601 }); 602 603 $('body').on('click', '.js-filter-trigger', function (e) { 604 e.preventDefault(); 605 $('.productlist__filter').toggleClass('fixed'); 606 $('#ecom-filter-parent').toggleClass('d-none'); 607 $('body').toggleClass('noscroll'); 608 }); 609 610 $('.js-read-more').on('click', function (e) { 611 if ($('.js-seotext-foldout').hasClass("hidden-seotext")) { 612 $('.js-seotext-foldout').show('fast'); 613 $('.js-seotext-foldout').removeClass("hidden-seotext"); 614 $(this).children("p").text(" Læs mindre"); 615 } 616 else { 617 $('.js-seotext-foldout').hide('fast'); 618 $('.js-seotext-foldout').addClass("hidden-seotext"); 619 $(this).children("p").text("Læs mere "); 620 } 621 }); 622 623 624 function triggerFixed() { 625 var width = $(window).width(); 626 var activeateScroll = width > 1024 ? false : true; 627 if (!activeateScroll) { 628 return; 629 } 630 631 var distanceToTop = $(document).scrollTop(); 632 var trigger = $('.productlist__filter__trigger'); 633 if (distanceToTop > 135) { 634 trigger.addClass('fixed'); 635 } 636 else { 637 trigger.removeClass('fixed'); 638 } 639 } 640 641 triggerFixed(); 642 $(window).scroll(function () { 643 triggerFixed(); 644 }); 645 $(window).resize(function () { 646 triggerFixed(); 647 }); 648 window.addEventListener("orientationchange", function () { 649 triggerFixed(); 650 }); 651 652 $('body').on('click', '.productlist__filter input', function () { 653 var filters = GetFilters(); 654 GetAjax(filters,1, false); 655 }); 656 657 $('#js_page_number').val(@PageNumber); 658 GetAjax("@feedPageUrl", @PageNumber, false); 659 660 $win.scroll(function () { 661 var windowBottom = $win.scrollTop() + $win.height(); 662 var itemsContainerBottom = $productsListPageContainer.offset().top + $productsListPageContainer.outerHeight(); 663 var pageNumber = $('#js_page_number').val(); 664 665 if (windowBottom >= itemsContainerBottom && itemsLoaded) { 666 itemsLoaded = false; 667 pageNumber++; 668 669 $('#js_page_number').val(pageNumber); 670 $("#ecom-append").append(appendLoader); 671 $('.productlist__loader__wrapper').show(); 672 673 var url = GetFilters(url); 674 675 GetAjax(url, pageNumber, true); 676 } 677 }); 678 679 function GetAjax(url, pageNumber, appendData) { 680 681 //nake sure it is boolean 682 if (typeof (appendData) == "undefined") { 683 appendData = false; 684 } 685 686 if (!appendData) { 687 $productsListPageContainer.find('.productlist__loader').show(); 688 } 689 690 //reset pagenum 691 if (pageNumber == 1) { 692 $('#js_page_number').val(1); 693 } 694 695 var urlAjax = url; 696 url = url + "&PageNum=" + pageNumber; 697 if (appendData) { 698 url = url + "&AppendData=1"; 699 } 700 701 $('#js__products__counter__container').hide(); 702 $.ajax({ 703 url: url, 704 success: function (result) { 705 706 if (appendData) { 707 $('.productlist__loader__append').remove(); 708 $('#ecom-append').append(result); 709 } else { 710 711 var filterHtml = $(result).find('#ecom-filter-ajax').html(); 712 var productlistHtml = $(result).find('#ecom-productlist-ajax').html(); 713 $productsContainer.html(productlistHtml); 714 $filterContainer.html(filterHtml); 715 716 $productsListPageContainer.find('.productlist__loader').hide(); 717 718 Array.prototype.forEach.call(document.querySelectorAll('.slider'), createSlider); 719 } 720 721 var $scrollStop = $(result).find('#js_scroll_stop'); 722 if ($scrollStop.length == 0) { 723 itemsLoaded = true; 724 } 725 } 726 }); 727 } 728 729 function GetFilters() { 730 var urlBasic = "@feedPageUrl"; 731 var formData = $("#js-productlist-filter").find(":input:not(:hidden)").serialize(); 732 Array.prototype.forEach.call(document.querySelectorAll('.slider'), function (elSlider) { 733 var element = getDataFacet(elSlider, 'update'); 734 var activeSliderId = element + "-active"; 735 736 if (document.getElementById(activeSliderId).value == "1") { 737 var minInputId = element + "-input-min"; 738 var maxInputId = element + "-input-max"; 739 740 if (formData) { 741 formData = formData + "&"; 742 } 743 formData = formData + document.getElementById(minInputId).getAttribute('name') + "=" + parseInt(document.getElementById(minInputId).value); 744 formData = formData + "&" + document.getElementById(maxInputId).getAttribute('name') + "=" + parseInt(document.getElementById(maxInputId).value); 745 } 746 }); 747 748 return urlBasic + '&' + formData; 749 } 750 751 function getDataFacet(element, key) { 752 return element.getAttribute('data-' + key); 753 } 754 755 function createSlider(slider) { 756 noUiSlider.create(slider, { 757 start: [Number(getDataFacet(slider, 'selected-start')), Number(getDataFacet(slider, 'selected-end'))], 758 connect: true, 759 tooltips: true, 760 step: 10, 761 762 format: wNumb({ 763 decimals: 0, 764 suffix: ' mm' 765 }), 766 767 range: { 768 'min': Number(getDataFacet(slider, 'start')), 769 'max': Number(getDataFacet(slider, 'end')) 770 } 771 }); 772 773 slider.noUiSlider.on("update", function (values, handle) { 774 var element = getDataFacet(slider, 'update'); 775 if (handle) { 776 var minInputId = element + "-input-max"; 777 var minSpanId = element + "-value-max"; 778 document.getElementById(minInputId).value = parseInt(values[handle]); 779 document.getElementById(minSpanId).innerHTML = values[handle]; 780 } else { 781 var maxInputId = element + "-input-min"; 782 var maxSpanId = element + "-value-min"; 783 document.getElementById(maxInputId).value = parseInt(values[handle]); 784 document.getElementById(maxSpanId).innerHTML = values[handle]; 785 } 786 }); 787 788 slider.noUiSlider.on("change", function (values, handle) { 789 var element = getDataFacet(slider, 'update'); 790 var activeSliderId = element + "-active"; 791 document.getElementById(activeSliderId).value = 1; 792 793 var filters = GetFilters(); 794 GetAjax(filters, 1, false); 795 }); 796 797 798 799 } 800 }); 801 802 803 </script> 804 @SnippetEnd("JavaScriptBottom") 805