Logo
Error executing template "Designs/Dwsimple/eCom/Productlist/ProductListPageNoPagination.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_b9a881f914f64ae38467decf137c3d6e.Execute() in C:\inetpub\Dynamicweb\KBH ListeFabrik\Files\Templates\Designs\Dwsimple\eCom\Productlist\ProductListPageNoPagination.cshtml:line 389
   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 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 2 @using System; 3 @using System.Web; 4 @using ListeFabrik.CustomModules.Classes; 5 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 6 @using System; 7 @using System.Web; 8 @using ListeFabrik.CustomModules; 9 @using ListeFabrik.CustomModules.Classes; 10 11 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 12 @using System; 13 @using System.Web; 14 @using System.Text.RegularExpressions 15 16 17 @functions{ 18 public class WrapMethods 19 { 20 //Gets the contrasting color 21 public static string getContrastYIQ(string hexcolor) 22 { 23 if (hexcolor != "") 24 { 25 hexcolor = Regex.Replace(hexcolor, "[^0-9a-zA-Z]+", ""); 26 27 int r = Convert.ToByte(hexcolor.Substring(0, 2), 16); 28 int g = Convert.ToByte(hexcolor.Substring(2, 2), 16); 29 int b = Convert.ToByte(hexcolor.Substring(4, 2), 16); 30 int yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000; 31 32 if (yiq >= 128) 33 { 34 return "black"; 35 } 36 else 37 { 38 return "white"; 39 } 40 } 41 else 42 { 43 return "black"; 44 } 45 } 46 47 48 //Truncate text 49 public static string Truncate (string value, int count, bool strip=true) 50 { 51 if (strip == true){ 52 value = StripHtmlTagByCharArray(value); 53 } 54 55 if (value.Length > count) 56 { 57 value = value.Substring(0, count - 1) + "..."; 58 } 59 60 return value; 61 } 62 63 64 //Strip text from HTML 65 public static string StripHtmlTagByCharArray(string htmlString) 66 { 67 char[] array = new char[htmlString.Length]; 68 int arrayIndex = 0; 69 bool inside = false; 70 71 for (int i = 0; i < htmlString.Length; i++) 72 { 73 char let = htmlString[i]; 74 if (let == '<') 75 { 76 inside = true; 77 continue; 78 } 79 if (let == '>') 80 { 81 inside = false; 82 continue; 83 } 84 if (!inside) 85 { 86 array[arrayIndex] = let; 87 arrayIndex++; 88 } 89 } 90 return new string(array, 0, arrayIndex); 91 } 92 93 //Make the correct count of columns 94 public static string ColumnMaker(int Col, string ScreenSize) 95 { 96 string Columns = ""; 97 98 switch (Col) 99 { 100 case 1: 101 Columns = "col-"+ScreenSize+"-12"; 102 break; 103 104 case 2: 105 Columns = "col-"+ScreenSize+"-6"; 106 break; 107 108 case 3: 109 Columns = "col-"+ScreenSize+"-4"; 110 break; 111 112 case 4: 113 Columns = "col-"+ScreenSize+"-3"; 114 break; 115 116 default: 117 Columns = "col-"+ScreenSize+"-3"; 118 break; 119 } 120 121 return Columns; 122 } 123 124 125 private string Custom(string firstoption, string secondoption) 126 { 127 if (firstoption == "custom") 128 { 129 return secondoption; 130 } 131 else 132 { 133 return firstoption; 134 } 135 } 136 } 137 } 138 139 140 @helper GetProductList(dynamic Loop, int ColMD = 3, int ColSM = 3, int ColXS = 1) 141 { 142 var area = Dynamicweb.Services.Areas.GetArea(Pageview.Area.ID); 143 144 string searchWords = HttpContext.Current.Request.QueryString["search"]; 145 bool isSearch = (!string.IsNullOrWhiteSpace(searchWords)) ? true : false; 146 147 int Count = 0; 148 149 string ColumnsMD = WrapMethods.ColumnMaker(ColMD, "md"); 150 string ColumnsSM = WrapMethods.ColumnMaker(ColSM, "sm"); 151 string ColumnsXS = WrapMethods.ColumnMaker(ColXS, "xs"); 152 153 154 foreach (LoopItem product in Loop) 155 { 156 var standardPrice = product.GetDouble("Ecom:Product.DBPrice"); 157 var customerPrice = product.GetDouble("Ecom:Product.Price.Price"); 158 string perUnitText = "/" + product.GetString("Ecom:Product:Field.ProductUnit"); 159 bool soldByLength = perUnitText == "/M"; 160 var currency = product.GetString("Ecom:Product.Price.Currency.Code"); 161 string Image = product.GetString("Ecom:Product:Field.MainProductImage"); 162 string Picto = product.GetString("Ecom:Product:Field.ProductPictogram"); 163 string GroupLink = product.GetString("Ecom:Product.LinkGroup.Clean"); 164 string Name = product.GetString("Ecom:Product.Name"); 165 string Description = product.GetString("Ecom:Product.ShortDescription"); 166 string Discount = product.GetString("Ecom:Product.Discount.Price"); 167 string Price = product.GetString("Ecom:Product.Price"); 168 string RawPrice = product.GetString("Ecom:Product.Price.PricePIP"); 169 string Filters = product.GetString("Ecom:Product:Field.FilterValues"); 170 string filterClasses = string.Empty; 171 string imagealttext = product.GetString("Ecom:Product:Field.ProductImageAltText"); 172 173 if (!string.IsNullOrWhiteSpace(Filters)) 174 { 175 filterClasses = "filter-" + Filters.Trim().Replace(",", " filter-"); 176 } 177 178 if (isSearch) 179 { 180 // If the primary group is not in the current shop, we have to take the group link to the first group that's in the shop 181 // Otherwise DW takes the first group regardless if it belongs to the area or not 182 bool isPrimaryGroupInShop = false; 183 184 string primaryGroupID = product.GetString("Ecom:Product.PrimaryGroupID"); 185 186 if (!string.IsNullOrEmpty(primaryGroupID)) 187 { 188 var primaryGroup = Dynamicweb.Ecommerce.Products.Group.GetGroupById(primaryGroupID); 189 isPrimaryGroupInShop = primaryGroup.Shops.Any(x => x.Id == area.EcomShopId); 190 } 191 192 if (!isPrimaryGroupInShop) 193 { 194 foreach (var loopGroup in product.GetLoop("AssociatedGroups")) 195 { 196 var group = Dynamicweb.Ecommerce.Products.Group.GetGroupById(loopGroup.GetString("Ecom:Group.ID")); 197 if (group.ShopId == area.EcomShopId) 198 { 199 GroupLink = loopGroup.GetString("Ecom:Group.Link.Clean") + "&ProductID=" + product.GetString("Ecom:Product.ID.UrlEncoded"); 200 break; 201 } 202 } 203 } 204 } 205 206 <div class="productlist grid-item @ColumnsMD @ColumnsSM @ColumnsXS @filterClasses" 207 data-name="@HttpUtility.HtmlEncode(Name.ToLower())" 208 data-price="@RawPrice" 209 data-filter-classes="@filterClasses"> 210 211 <div class="boxproduct wp-block product"> 212 <div class="listproductright"> 213 <a href="@GroupLink" title="@HttpUtility.HtmlEncode(Name)"> 214 <figure style="" class="productfigure"> 215 @if (!string.IsNullOrEmpty(Image)) 216 { 217 <img alt="@HttpUtility.HtmlEncode(imagealttext)" src="@PIMCommerceUtilities.GetPerfionImageUrl(Image,"250x250")" class="img-responsive img-center"> 218 } 219 </figure> 220 @if (!string.IsNullOrEmpty(Picto)) 221 { 222 <span class="product-picto"><img alt="" src="@PIMCommerceUtilities.GetPerfionImageUrl(Picto, "50x50")" /></span> 223 } 224 </a> 225 </div> 226 <div class="extracolumn"> 227 <p class="product-title"><a href="@GroupLink">@Name.Replace("/", " / ")</a></p> 228 <p>@Translate("Product number", "Product number"): <span>@product.GetString("Ecom:Product.Number")</span></p> 229 </div> 230 <div class="listproductleft wp-block-footer"> 231 @if (customerPrice < standardPrice) 232 { 233 <span class="productprice price pull-right" style=" font-size: 16px !important" content="@product.GetString("Ecom:Product.Price.Price").Replace(",", ".")"><strong>@product.GetString("Ecom:Product.Price.Price")&nbsp;@currency@perUnitText</strong></span><span>&nbsp;&nbsp;</span> 234 <span class="productpricebr"></span> 235 <p class="productoldprice price" style="margin-top: -15px !important; padding-top: 0px !important; color: #AAAAAA !important; font-size: 12px !important; text-align: right; text-decoration: line-through">@standardPrice.ToString("F")&nbsp;@currency@perUnitText</p> 236 } 237 else 238 { 239 <span class="productprice price pull-right" style="font-size: 16px !important" content="@product.GetString("Ecom:Product.Price.Price").Replace(",", ".")"><strong>@product.GetString("Ecom:Product.Price.Price")&nbsp;@currency@perUnitText</strong></span><span>&nbsp;&nbsp;</span> 240 } 241 </div> 242 </div> 243 244 </div> 245 246 Count++; 247 248 if (Count == ColMD) 249 { 250 <div class="row"></div> 251 Count = 0; 252 } 253 } 254 } 255 256 257 @{ 258 string searchWords = HttpContext.Current.Request.QueryString["search"]; 259 bool isSearch = (!string.IsNullOrWhiteSpace(searchWords)) ? true : false; 260 string grouplink = ""; 261 262 var products = GetLoop("Products"); 263 var groupId = GetString("Ecom:ProductList:Page.GroupID"); 264 265 if (!string.IsNullOrWhiteSpace(groupId)) 266 { 267 products = (from LoopItem product in products 268 orderby Dynamicweb.Ecommerce.Services.ProductGroups.GetProductGroupRelation(product.GetString("Ecom:Product.ID"), groupId).Sorting 269 select product).ToList(); 270 grouplink = "/Default.aspx?ID=" + GetString("Ecom:ProductList:Page.ID") + "&amp;GroupID=" + groupId; 271 } 272 else 273 { 274 grouplink = "/Default.aspx?ID=" + GetString("Ecom:ProductList:Page.ID") + "&amp;search=" + GetString("Ecom:ProductList:Search.Query"); 275 } 276 277 278 var distinctFilters = (from LoopItem product in products select product.GetString("Ecom:Product:Field.FilterValues").Split(',')).SelectMany(x => x).Distinct(); 279 } 280 281 <div class="row"> 282 <div class="col-md-4 col-sm-4 col-xs-4"> 283 @if (isSearch) 284 { 285 <h3 class="section-title">@searchWords</h3> 286 } 287 else 288 { 289 <h1 class="section-title"> 290 @GetString("Ecom:ProductList:Page.GroupName") 291 </h1> 292 <h2 class="section-title">@GetString("Ecom:Group:Field.WebCategoryTextH2.Value")</h2> 293 if (!string.IsNullOrEmpty(GetString("Ecom:Group:Field.CategoryImage.Value"))) 294 { 295 <img src="@PIMCommerceUtilities.GetPerfionImageUrl(GetString("Ecom:Group:Field.CategoryImage.Value"), "600x200")" alt="@GetString("Ecom:Group:Field.WebCategoryAltText.Value")" class="group-img img-center" /> 296 } 297 } 298 </div> 299 300 <div class="col-md-4 col-sm-4 col-xs-4 hidden-xs"></div> 301 302 <div class="col-md-4 col-sm-4 col-xs-4 pull-right"> 303 <div class="btn-group pull-right hidden-xs" style="" id="viewbtns"> 304 <button type="button" class="btn btn-xs btn-three" onclick="ListView(true)"><span class="glyphicon glyphicon-th-list"></span></button> 305 <button type="button" class="btn btn-xs btn-three" onclick="BoxView(true)"><span class="glyphicon glyphicon-th"></span></button> 306 </div> 307 <div class="pull-right"> 308 <div class="btn-group"> 309 <button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> 310 @Translate("Sort by", "Sort by") <span class="caret"></span> 311 </button> 312 <ul class="dropdown-menu dropdown-menu-right" role="menu"> 313 <li><a class="pill-left sort-btn" data-sortby="price" data-sortorder="asc">@Translate("Price low-high", "Price low-high")</a></li> 314 <li><a class="pill-left sort-btn" data-sortby="price" data-sortorder="desc">@Translate("Price high-low", "Price high-low")</a></li> 315 </ul> 316 </div> 317 &nbsp;&nbsp; 318 </div> 319 </div> 320 </div> 321 322 323 @if (!isSearch) 324 { 325 <div class="row"> 326 <div class="col-md-12 group-description"> 327 <article> 328 <p> 329 @GetString("Ecom:Group.Description") 330 </p> 331 </article> 332 </div> 333 </div> 334 335 <div class="row"> 336 <div class="col-md-12"> 337 <ul class="filters-list"> 338 @foreach (var feature in GetLoop("FilterFeatures")) 339 { 340 int nbFilters = (from LoopItem option in feature.GetLoop("Options") select option.GetString("Option.Value")).Distinct().Count(); 341 342 if (nbFilters > 1) 343 { 344 var options = feature.GetLoop("Options"); 345 var applicableFilters = options.Count(x => distinctFilters.Contains(x.GetString("Option.Value"))); 346 347 if (applicableFilters > 1) 348 { 349 <li class="filter button-group" data-filter-group="@feature.GetString("Feature.name")"> 350 <h4>@feature.GetString("Feature.caption")</h4> 351 <select class="filter-options-list"> 352 <option class="filter-option is-checked" data-filter=""> 353 @Translate("AllFilters", "All") 354 </option> 355 @foreach (var option in options) 356 { 357 if (distinctFilters.Contains(option.GetString("Option.Value"))) 358 { 359 <option class="filter-option" data-filter=".filter-@option.GetString("Option.Value")"> 360 @option.GetString("Option.Label") 361 </option> 362 } 363 } 364 </select> 365 </li> 366 } 367 } 368 } 369 </ul> 370 371 </div> 372 </div> 373 } 374 375 <div class="row grid main-product-list"> 376 @GetProductList(products, 4) 377 </div> 378 379 380 <script> 381 @{ 382 string banner = string.Empty; 383 384 if (!isSearch) 385 { 386 if (string.IsNullOrEmpty(GetString("Ecom:Group:Field.Banner"))) 387 { 388 // if no banner, we take the parent group banner 389 var parents = Dynamicweb.Ecommerce.Products.Group.GetGroupById(GetString("Ecom:Group.ID")).ParentGroups; 390 if (parents.Count > 0) 391 { 392 string parentBanner = parents[0].ProductGroupFieldValues.GetProductGroupFieldValue("CategoryImage").Value.ToString(); 393 if (!string.IsNullOrEmpty(parentBanner)) 394 { 395 banner = PIMCommerceUtilities.GetPerfionImageUrl(parentBanner); 396 } 397 } 398 } 399 else 400 { 401 banner = PIMCommerceUtilities.GetPerfionImageUrl(GetString("Ecom:Group:Field.CategoryImage")); 402 } 403 } 404 } 405 406 ProductListSettings = { 407 GroupLink: '@grouplink', 408 GroupBanner: '@banner', 409 EcommerceProductListForm: '@Pageview.Area.Item["EcommerceProductListForm"].ToString()', 410 SortSettings: { sortBy: 'original-order' }, 411 IsSearch: @isSearch.ToString().ToLower() 412 }; 413 </script> 414 415 <script src="/Files/Templates/Designs/Dwsimple/js/pages/productlist.js" defer="defer"></script> 416 <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 417 <script src="/Files/Templates/Designs/Dwsimple/js/vendor/readmore.js"></script> 418 419 <script> 420 $('article').readmore({ 421 speed: 500, 422 collapsedHeight: 60, 423 heightMargin: 16, 424 moreLink: '<a class="btn btn btn-sm btn-dw-secondary" href="#">@Translate("ReadMore", "Læs mere")</a>', 425 lessLink: '<a class="btn btn btn-sm btn-dw-secondary" href="#">@Translate("Close", "Luk")</a>', 426 }); 427 </script>