Favorite list updated
Error executing template "Designs/Swift/Paragraph/VariantOrderMatrix_Custom.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at CompiledRazorTemplates.Dynamic.RazorEngine_18b66947d6db44fb80d3c758240b6896.Execute() in D:\web\OttoSchachner\Files\Templates\Designs\Swift\Paragraph\VariantOrderMatrix_Custom.cshtml:line 103 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> 2 @using Dynamicweb.Ecommerce.ProductCatalog 3 @using Dynamicweb.Ecommerce.Products 4 @using Dynamicweb.Core 5 @using Dynamicweb.Ecommerce.Common 6 @using System.Web; 7 @using Dynamicweb.Ecommerce.Prices 8 @using System.Web 9 @using Dynamicweb.Security.UserManagement 10 11 12 @{ 13 bool isVisualEditor = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("VisualEdit")) ? Convert.ToBoolean(Dynamicweb.Context.Current.Request.QueryString.Get("VisualEdit")) : false; 14 15 ProductViewModel product = new ProductViewModel(); 16 17 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 18 { 19 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 20 } 21 22 Dynamicweb.Ecommerce.Shops.Shop shop = new Dynamicweb.Ecommerce.Shops.ShopService().GetShop(Dynamicweb.Frontend.PageView.Current().Area.EcomShopId); 23 PriceContext priceContext = new PriceContext(Context.Currency, Context.Country, shop, User.GetCurrentExtranetUser(), false, null); 24 25 bool mobile = Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Mobile || Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Tablet; 26 var user = User.GetCurrentExtranetUser(); 27 28 if (!mobile) 29 { 30 ProductService productService = new ProductService(); 31 Product ecomProduct = productService.GetProductById(product.Id, product.VariantId, true); 32 var productFieldStatusMatches = Model.Item.GetString("ProductFieldStatusMatches").ToLower().Split(','); 33 double purchaseQuantityStep = Converter.ToDouble(productService.GetPropertyValue(ecomProduct, "PurchaseQuantityStep")); 34 purchaseQuantityStep = purchaseQuantityStep > 0 ? purchaseQuantityStep : 1; 35 string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 36 if (!url.Contains("LayoutTemplate")) 37 { 38 url += url.Contains("?") ? "&LayoutTemplate=Swift_MiniCart.cshtml" : "?LayoutTemplate=Swift_MiniCart.cshtml"; 39 } 40 41 if (!string.IsNullOrEmpty(Model.Item.GetString("Title")) && !Model.Item.GetBoolean("HideTitle")) 42 { 43 string titleFontSize = Model.Item.GetRawValueString("TitleFontSize", "h3"); 44 45 <h3 class="@titleFontSize text-center mb-3">@Model.Item.GetString("Title")</h3> 46 } 47 48 <form method="post" action="@url"> 49 <div class="variant-matrix-container theme js-variant-matrix"> 50 <div class="top-button-container"> 51 <div class="search-field-container"> 52 <input type="text" class="variant-search-field js-variant-search-field" placeholder="@HttpUtility.HtmlAttributeEncode(Translate("Smartpage:VariantMatrix.SearchFunction", "Søg efter varenr., DB nr., materiale, størrelse mm.."))" /> 53 <div class="search-icon">@RenderSearchIcon()</div> 54 </div> 55 @if(user != null) 56 { 57 <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary order-btn js-add-to-cart-button"><span class="m-1">@Translate("Smartpage:VariantMatrix.AddToCart", "Læg i kurv")</span> @RenderCartIcon()</button> 58 } 59 60 </div> 61 62 <input type="hidden" name="cartcmd" value="addmulti" /> 63 <input type="hidden" name="redirect" value="false" /> 64 <table class="table table-striped variant-matrix js-variant-table"> 65 <tr class="variant-table-header"> 66 <th data-index="0"> 67 @Translate("Smartpage:VariantMatrix.ProductNo", "Varenummer") 68 <span class="sort-triangle asc js-sort-triangle"></span> 69 </th> 70 @{ 71 int index = 1; 72 foreach (var variantGroup in product.VariantGroups()) 73 { 74 <th data-index="@index"> 75 @Translate($"Smartpage:VariantGroup.Name.{variantGroup.Name}", variantGroup.Name) 76 <span class="sort-triangle none js-sort-triangle"></span> 77 </th> 78 index++; 79 } 80 } 81 <th data-index="@(index)"> 82 @Translate("Smartpage:VariantMatrix.DbNumber", "DB-nummer") 83 <span class="sort-triangle none js-sort-triangle"></span> 84 </th> 85 <th data-index="@(index + 1)"> 86 @Translate("Smartpage:VariantMatrix.EAN", "EAN/UPC") 87 <span class="sort-triangle none js-sort-triangle"></span> 88 </th> 89 <th data-index="@(index + 1)"> 90 @Translate("Smartpage:VariantMatrix.SpStatus", "Skaffevare") 91 <span class="sort-triangle none js-sort-triangle"></span> 92 </th> 93 </tr> 94 @{ 95 string languageID = Context.LanguageID; 96 int count = 0; 97 } 98 @foreach (var variantComb in ecomProduct.VariantCombinations) 99 { 100 count++; 101 102 var variantProduct = variantComb.GetProduct(languageID); 103 string dbNumber = variantProduct.ProductFieldValues.GetProductFieldValue("SpDBNumber").Value.ToString(); 104 dbNumber = !string.IsNullOrEmpty(dbNumber) ? dbNumber : Translate("Smartpage:VariantMatrix.NotAvailable", "N/A"); 105 string EAN = !string.IsNullOrEmpty(variantProduct.EAN) ? variantProduct.EAN : Translate("Smartpage:VariantMatrix.NotAvailable", "N/A"); 106 var variantFieldStatus = Convert.ToString(variantProduct.ProductFieldValues.GetProductFieldValue("SpStatus")?.Value).ToLower(); 107 var status = productFieldStatusMatches.Contains(variantFieldStatus) ? Translate("Smartpage:VariantMatrix.Status.Yes", "JA") : ""; 108 string price = variantProduct.GetPrice(priceContext).PriceWithoutVATFormatted; 109 string cartUrl = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 110 111 if (variantProduct.Active) 112 { 113 <tr> 114 <input type="hidden" name="ProductLoopCounter@(count)" id="ProductLoopCounter@(count)" value="@count" /> 115 <input type="hidden" name="ProductId@(count)" id="ProductId@(count)" value="@variantProduct.Id" /> 116 <input type="hidden" name="VariantId@(count)" id="VariantId@(count)" value="@variantComb.VariantId" /> 117 118 <td>@variantProduct.Number</td> 119 @foreach (var optionId in variantComb.GetVariantOptionIds()) 120 { 121 <td>@product.VariantGroups().Find(group => group.Options.Find(option => option.Id == optionId) != null).Options.Single(option2 => option2.Id == optionId).Name</td> 122 } 123 <td>@dbNumber</td> 124 <td>@EAN</td> 125 <td>@status</td> 126 @if (user != null) 127 { 128 <td class="text-center order-column js-dont-search"> 129 <div class="stock-level"> 130 @RenderPartial("Components/StockLevel_Custom.cshtml", product, new Dictionary<string, object>() { { "product", variantProduct } }) 131 </div> 132 <div class="price-container"> 133 <div class="price-text">@price</div> 134 <div class="quantity-text">@Translate("Smartpage:VariantMatrix.Quantity", "Bestilles i: ") @purchaseQuantityStep @product.ProductFields["SpSalesUnit"].Value</div> 135 </div> 136 <div class="quantity-selector-container"> 137 <div class="quantity-selector"> 138 <span class="quantity-symbol js-quantity-minus">−</span> 139 <input class="quantity-input js-quantity" name="Quantity@(count)" type="number" step="@purchaseQuantityStep" min="0" value="0"> 140 <span class="quantity-symbol js-quantity-plus">+</span> 141 </div> 142 </div> 143 </td> 144 } 145 146 </tr> 147 } 148 } 149 150 @if (ecomProduct.VariantCombinations.Count <= 0) //if no variants then show the current product in variantmatrix.. 151 { 152 count++; 153 154 string dbNumber = ecomProduct.ProductFieldValues.GetProductFieldValue("SpDBNumber").Value.ToString(); 155 dbNumber = !string.IsNullOrEmpty(dbNumber) ? dbNumber : Translate("Smartpage:VariantMatrix.NotAvailable", "N/A"); 156 string EAN = !string.IsNullOrEmpty(ecomProduct.EAN) ? ecomProduct.EAN : Translate("Smartpage:VariantMatrix.NotAvailable", "N/A"); 157 var productFieldStatus = Convert.ToString(ecomProduct.ProductFieldValues.GetProductFieldValue("SpStatus")?.Value).ToLower(); 158 var status = productFieldStatusMatches.Contains(productFieldStatus) ? Translate("Smartpage:VariantMatrix.Status.Yes", "JA") : ""; 159 string price = ecomProduct.GetPrice(priceContext).PriceWithoutVATFormatted; 160 string cartUrl = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 161 162 if (ecomProduct.Active) 163 { 164 <tr> 165 <input type="hidden" name="ProductLoopCounter@(count)" id="ProductLoopCounter@(count)" value="@count" /> 166 <input type="hidden" name="ProductId@(count)" id="ProductId@(count)" value="@ecomProduct.Id" /> 167 168 <td>@ecomProduct.Number</td> 169 <td>@dbNumber</td> 170 <td>@EAN</td> 171 <td>@status</td> 172 @if (user != null) 173 { 174 <td class="text-center order-column js-dont-search"> 175 <div class="stock-level"> 176 @RenderPartial("Components/StockLevel_Custom.cshtml", product) 177 </div> 178 <div class="price-container"> 179 <div class="price-text">@price</div> 180 <div class="quantity-text">@Translate("Smartpage:VariantMatrix.Quantity", "Bestilles i: ") @purchaseQuantityStep @product.ProductFields["SpSalesUnit"].Value</div> 181 </div> 182 <div class="quantity-selector-container"> 183 <div class="quantity-selector"> 184 <span class="quantity-symbol js-quantity-minus">−</span> 185 <input class="quantity-input js-quantity" name="Quantity@(count)" type="number" step="@purchaseQuantityStep" min="0" value="0"> 186 <span class="quantity-symbol js-quantity-plus">+</span> 187 </div> 188 </div> 189 </td> 190 } 191 192 </tr> 193 } 194 } 195 </table> 196 <div class="top-button-container"> 197 @if(user != null) 198 { 199 <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary order-btn js-add-to-cart-button"><span class="m-1">@Translate("Smartpage:VariantMatrix.AddToCart", "Læg i kurv")</span> @RenderCartIcon()</button> 200 } 201 202 </div> 203 </div> 204 </form> 205 } 206 } 207 208 @helper RenderSearchIcon() 209 { 210 <svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" 211 width="30" height="30" 212 viewBox="0 0 30 30" 213 style=" fill:#FFF;"> 214 <path d="M 13 3 C 7.4889971 3 3 7.4889971 3 13 C 3 18.511003 7.4889971 23 13 23 C 15.396508 23 17.597385 22.148986 19.322266 20.736328 L 25.292969 26.707031 A 1.0001 1.0001 0 1 0 26.707031 25.292969 L 20.736328 19.322266 C 22.148986 17.597385 23 15.396508 23 13 C 23 7.4889971 18.511003 3 13 3 z M 13 5 C 17.430123 5 21 8.5698774 21 13 C 21 17.430123 17.430123 21 13 21 C 8.5698774 21 5 17.430123 5 13 C 5 8.5698774 8.5698774 5 13 5 z"></path> 215 </svg> 216 } 217 218 @helper RenderCartIcon() 219 { 220 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-shopping-bag"> 221 <path d="M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z"></path> 222 <line x1="3" y1="6" x2="21" y2="6"></line> 223 <path d="M16 10a4 4 0 0 1-8 0"></path> 224 </svg> 225 } 226