Component builder for: Product Details Area
Error executing template "Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at CompiledRazorTemplates.Dynamic.RazorEngine_e7e57ad3eec5444bb67ef9458359c012.Execute() in C:\inetpub\solutions\Goecker-2022-Prod\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 76 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.CustomerExperienceCenter.Favorites 4 @using System.Linq 5 @using Dynamicweb.Core 6 @using NLWI.Core.Factory 7 @using NLWI.Platforms.Dynamicweb9.Specs.ViewModels 8 @using NLWI.Platforms.Dynamicweb9.Specs.Services 9 @using NORRIQ.CustomCode.Razor 10 @using NORRIQ.CustomCode.StockLocations 11 @using System.Text; 12 @using System.Web; 13 @using System.Globalization 14 15 @* CUSTOMIZED STANDARD SWIFT (v1.15.0) TEMPLATE *@ 16 17 @{ 18 ProductViewModel product = new ProductViewModel(); 19 20 ProductViewModelSettings productSetting = new ProductViewModelSettings 21 { 22 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 23 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 24 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 25 ShopId = Pageview.Area.EcomShopId 26 }; 27 28 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 29 { 30 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 31 } 32 else if (Pageview.Item["DummyProduct"] != null) 33 { 34 35 string dummyProductId = ""; 36 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 37 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 38 if (productList.Products != null) 39 { 40 foreach (var p in productList.Products) { dummyProductId = p.Id; } 41 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 42 product = dummyProduct; 43 } 44 else 45 { 46 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 47 } 48 } 49 else if (Pageview.Item["DummyProduct"] == null) 50 { 51 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 52 } 53 54 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 55 bool anonymousUser = Pageview.User == null; 56 bool isErpConnectionDown = false;//ynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplatesHelper.IsWebServiceConnectionAvailable(); 57 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 58 59 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "fs-2"); 60 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 61 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 62 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 63 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 64 65 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 66 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 67 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 68 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 69 70 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 71 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 72 string order = layout == "horizontal" ? string.Empty : "order-2"; 73 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "px-2 theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 74 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 75 76 var disablePrice = product.ProductFields.ContainsKey("Custom_DisablePrice") ? Convert.ToBoolean(product.ProductFields["Custom_DisablePrice"].Value) : false; //CUSTOM 77 } 78 79 @if (!hidePrice && product.Id != null && !disablePrice) //CUSTOM 80 { 81 string showPricesWithVat = HttpContext.Current.Session["Smartpage:ShowPricesWithVat"] != null ? Convert.ToString(HttpContext.Current.Session["Smartpage:ShowPricesWithVat"]) : Pageview.Area.EcomPricesWithVat.ToLower(); 82 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 83 84 string priceMin = ""; 85 string priceMax = ""; 86 87 string liveInfoClass = ""; 88 string productInfoFeed = ""; 89 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplatesHelper.IsLazyLoadingForProductInfoEnabled; 90 if (isLazyLoadingForProductInfoEnabled) 91 { 92 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 93 { 94 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 95 if (!string.IsNullOrEmpty(productInfoFeed)) 96 { 97 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 98 } 99 } 100 liveInfoClass = "js-live-info"; 101 } 102 103 FieldValueViewModel fieldValueViewModel = null; 104 product.ProductFields.TryGetValue("SchillingShowBeforePrice", out fieldValueViewModel); 105 bool showBeforePrice = fieldValueViewModel != null ? Converter.ToBoolean(fieldValueViewModel.Value) : false; 106 107 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" @productInfoFeed> 108 <div class="@priceFontSize m-0 d-flex @flexDirection @flexGap @horizontalAlign" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 109 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 110 111 @if (showPricesWithVat == "false" && !neverShowVat) 112 { 113 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 114 { 115 <span itemprop="price" content="" class="d-none"></span> 116 <span class="text-decoration-line-through js-text-decoration-line-through opacity-75 me-3 text-price js-text-price d-none" data-show-if="LiveProductInfo.product.Price.Price != LiveProductInfo.product.PriceBeforeDiscount.Price"></span> 117 } 118 else 119 { 120 string beforePrice = product.PriceBeforeDiscount.PriceWithoutVatFormatted; 121 string informativePrice = product.PriceInformative.PriceWithoutVatFormatted; 122 123 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString("0.00", CultureInfo.InvariantCulture)" class="d-none"></span> 124 if (product.Price.Price != product.PriceBeforeDiscount.Price) 125 { 126 <span class="text-decoration-line-through opacity-75 @order">@beforePrice</span> 127 } 128 else if (product.PriceInformative.Price > 0) 129 { 130 <span class="text-decoration-line-through opacity-75 @order">@informativePrice</span> 131 } 132 } 133 } 134 else 135 { 136 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 137 { 138 <span itemprop="price" content="" class="d-none"></span> 139 <span class="text-decoration-line-through js-text-decoration-line-through opacity-75 me-3 text-price js-text-price d-none" data-show-if="LiveProductInfo.product.Price.Price != LiveProductInfo.product.PriceBeforeDiscount.Price"></span> 140 } 141 else 142 { 143 string beforePrice = product.PriceBeforeDiscount.PriceFormatted; 144 string informativePrice = product.PriceInformative.PriceFormatted; 145 146 <span itemprop="price" content="@product.Price.Price.ToString("0.00", CultureInfo.InvariantCulture)" class="d-none"></span> 147 148 if (product.Price.Price != product.PriceBeforeDiscount.Price) 149 { 150 <span class="text-decoration-line-through opacity-75 @order"> 151 <span class="text-price">@beforePrice</span> 152 </span> 153 } 154 else if (product.PriceInformative.Price > 0) 155 { 156 <span class="text-decoration-line-through opacity-75 @order"> 157 <span class="text-price">@informativePrice</span> 158 </span> 159 } 160 } 161 } 162 163 @if (showPricesWithVat == "false" && !neverShowVat) 164 { 165 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 166 { 167 <span class="text-price js-text-price"> 168 <div class="spinner-border" role="status"></div> 169 </span> 170 } 171 else 172 { 173 string price = product.Price.PriceWithoutVatFormatted; 174 if (product?.VariantInfo?.VariantInfo != null) 175 { 176 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 177 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 178 } 179 if (priceMin != priceMax) 180 { 181 price = priceMin + " - " + priceMax; 182 } 183 <span class="@theme"> 184 <span class="text-price">@price</span> 185 </span> 186 } 187 } 188 else 189 { 190 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 191 { 192 <span class="text-price js-text-price"> 193 <div class="spinner-border" role="status"></div> 194 </span> 195 } 196 else 197 { 198 string price = product.Price.PriceFormatted; 199 if (product?.VariantInfo?.VariantInfo != null) 200 { 201 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 202 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 203 } 204 if (priceMin != priceMax) 205 { 206 price = priceMin + " - " + priceMax; 207 } 208 <span class="@theme"> 209 <span class="text-price">@price</span> 210 </span> 211 } 212 } 213 214 @* Stock state for Schema.org, start *@ 215 @{ 216 Uri url = Dynamicweb.Context.Current.Request.Url; 217 } 218 219 @{ 220 // Custom: ViaBill integration 221 if (Model.Item.GetBoolean("CustomActivateViaBill") && showPricesWithVat != "false") 222 { 223 <div class="viabill-pricetag" 224 data-view="product" 225 data-price="@product.Price.Price.ToString("0.00", CultureInfo.InvariantCulture)" 226 data-currency="@Dynamicweb.Ecommerce.Common.Context.Currency.Code" 227 data-dynamic-price-trigger-delay="@Model.Item.GetInt32("CustomViaBillPriceDelay")"></div> 228 @Model.Item.GetRawValueString("CustomViaBillScript") 229 } 230 231 // Custom: Anyday integration 232 if (Model.Item.GetBoolean("CustomActivateAnyday") && !String.IsNullOrEmpty(Model.Item.GetRawValueString("CustomAnydayToken")) && showPricesWithVat != "false") 233 { 234 var locale = Dynamicweb.Frontend.PageView.Current().Area.CultureInfo.ToString(); 235 <anyday-price-widget theme="@Model.Item.GetRawValueString("CustomAnydayTheme")" 236 currency="@product.Price.CurrencyCode" 237 price="@product.Price.Price" 238 price-format-locale="@locale" 239 locale="@locale" 240 token="@Model.Item.GetRawValueString("CustomAnydayToken")" 241 fully-clickable="true" 242 debug="info"> 243 </anyday-price-widget> 244 245 @Model.Item.GetRawValueString("CustomAnydayScript") 246 } 247 } 248 249 250 <link itemprop="url" href="@url"> 251 252 @{ 253 bool IsNeverOutOfStock = product.NeverOutOfstock; 254 } 255 256 @if (IsNeverOutOfStock) 257 { 258 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 259 } 260 else 261 { 262 if (product.StockLevel > 0) 263 { 264 <span itemprop="availability" class="d-none">InStock</span> 265 } 266 else 267 { 268 <span itemprop="availability" class="d-none">OutOfStock</span> 269 } 270 } 271 @* Stock state for Schema.org, stop *@ 272 273 </div> 274 275 @if (showPricesWithVat == "false" && !neverShowVat) 276 { 277 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 278 { 279 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate(" Incl. VAT")"></small> 280 } 281 else 282 { 283 string price = product.Price.PriceWithVatFormatted; 284 if (product?.VariantInfo?.VariantInfo != null) 285 { 286 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 287 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 288 } 289 if (priceMin != priceMax) 290 { 291 price = priceMin + " - " + priceMax; 292 } 293 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 294 } 295 } 296 </div> 297 } 298 else if (Pageview.IsVisualEditorMode) 299 { 300 <div class="alert alert-dark m-0" role="alert"> 301 <span>@Translate("No products available")</span> 302 </div> 303 } 304
Error executing template "Designs/Swift/Paragraph/Swift_ProductBrandImage_Custom.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at NORRIQ.CustomCode.Razor.ProductViewModelExtensions.GetAutoId(ProductViewModel product) in D:\a\1\s\NORRIQ.CustomCode\Razor\ProductViewModelExtensions.cs:line 47 at CompiledRazorTemplates.Dynamic.RazorEngine_71324d6185514ba9907d53d0281beaed.Execute() in C:\inetpub\solutions\Goecker-2022-Prod\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBrandImage_Custom.cshtml:line 49 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.CustomerExperienceCenter.Favorites 4 @using ProductExtensions = NORRIQ.CustomCode.Razor.ProductViewModelExtensions; 5 @using NLWI.Platforms.Dynamicweb9.Specs.Services 6 @using NORRIQ.Common8.Factory 7 @using System.Web 8 9 @* CUSTOM TEMPLATE SUPPORTED BY SWIFT (v1.15.0) *@ 10 11 @{ 12 ProductViewModel product = new ProductViewModel(); 13 14 ProductViewModelSettings productSetting = new ProductViewModelSettings 15 { 16 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 17 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 18 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 19 ShopId = Pageview.Area.EcomShopId 20 }; 21 22 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 23 { 24 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 25 } 26 else if (Pageview.Item["DummyProduct"] != null) 27 { 28 string dummyProductId = ""; 29 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 30 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 31 if (productList.Products != null) 32 { 33 foreach (var p in productList.Products) { dummyProductId = p.Id; } 34 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 35 product = dummyProduct; 36 } 37 else 38 { 39 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 40 } 41 } 42 else if (Pageview.Item["DummyProduct"] == null) 43 { 44 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 45 } 46 47 //Using old norriq code, is specificationService is removed from the project, change where we get the brand logo from 48 var specificationService = ObjectFactory.GetInstance<ProductSpecificationService>(); 49 var specs = specificationService.GetProductSpecifications(ProductExtensions.GetAutoId(product)); 50 51 string imagePath = specs.HasKey("Brandlogo") ? specs.GetByKey("Brandlogo").Value : ""; 52 imagePath = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 53 54 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 55 ratio = ratio != "0" ? ratio : ""; 56 string ratioCssClass = ratio != "" ? " ratio" : ""; 57 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 58 59 string width = Model.Item.GetRawValueString("Width", "auto"); 60 int smallImageSize = 640; 61 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 62 63 string imagePathXs = "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePath + "&format=webp"; 64 string imagePathS = "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePath + "&format=webp"; 65 string imagePathFallBack = "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePath + "&format=webp"; 66 } 67 68 @if (product.Id != null) 69 { 70 string fullWidth = width == "auto" ? "w-100" : ""; 71 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 72 if (!string.IsNullOrEmpty(imagePath)) 73 { 74 <div class="h-100 @fullWidth position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 75 <div class="ratio" style="@(ratioVariable)"> 76 <div class="d-flex justify-content-center align-items-center"> 77 <img id="brandlogo" 78 srcset=" 79 @imagePathXs @(smallImageSize)w, 80 @imagePathS @(largeImageSize)w" 81 sizes="(min-width: 992px) 33vw, 50vw" 82 src="@imagePathFallBack" 83 loading="lazy" 84 decoding="async" 85 class="h-100 w-100" 86 style="object-fit: contain;" 87 alt="@HttpUtility.HtmlAttributeEncode(specs.HasKey("Brandlogo") ? specs.GetByKey("Brandlogo").Caption : "")"> 88 </div> 89 </div> 90 </div> 91 } 92 } 93 else if (Pageview.IsVisualEditorMode) 94 { 95 <div class="alert alert-dark m-0">@Translate("No products available")</div> 96 } 97
Error executing template "Designs/Swift/Paragraph/Swift_ProductLeasingButton_Custom.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at NORRIQ.CustomCode.Razor.ProductViewModelExtensions.GetAutoId(ProductViewModel product) in D:\a\1\s\NORRIQ.CustomCode\Razor\ProductViewModelExtensions.cs:line 47 at CompiledRazorTemplates.Dynamic.RazorEngine_fcb1104378914bef9e3f86ecb50eb48f.Execute() in C:\inetpub\solutions\Goecker-2022-Prod\Files\Templates\Designs\Swift\Paragraph\Swift_ProductLeasingButton_Custom.cshtml:line 51 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.CustomerExperienceCenter.Favorites 4 @using ProductExtensions = NORRIQ.CustomCode.Razor.ProductViewModelExtensions; 5 @using NLWI.Platforms.Dynamicweb9.Specs.Services 6 @using NORRIQ.Common8.Factory 7 @using NORRIQ.CustomCode.Pricing 8 @using NORRIQ.CustomCode.Razor 9 @using System.Web 10 11 @* CUSTOM TEMPLATE SUPPORTED BY SWIFT (v1.15.0) *@ 12 13 @{ 14 ProductViewModel product = new ProductViewModel(); 15 16 ProductViewModelSettings productSetting = new ProductViewModelSettings 17 { 18 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 19 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 20 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 21 ShopId = Pageview.Area.EcomShopId 22 }; 23 24 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 25 { 26 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 27 } 28 else if (Pageview.Item["DummyProduct"] != null) 29 { 30 string dummyProductId = ""; 31 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 32 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 33 if (productList.Products != null) 34 { 35 foreach (var p in productList.Products) { dummyProductId = p.Id; } 36 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 37 product = dummyProduct; 38 } 39 else 40 { 41 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 42 } 43 } 44 else if (Pageview.Item["DummyProduct"] == null) 45 { 46 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 47 } 48 49 //Using old norriq code, is specificationService is removed from the project, change where we get the data from 50 var specificationService = ObjectFactory.GetInstance<ProductSpecificationService>(); 51 var productSpecs = specificationService.GetProductSpecifications(ProductExtensions.GetAutoId(product)); 52 53 var showPricesWithVat = HttpContext.Current.Session["Smartpage:ShowPricesWithVat"] != null ? Convert.ToString(HttpContext.Current.Session["Smartpage:ShowPricesWithVat"]) : Pageview.Area.EcomPricesWithVat.ToLower(); 54 55 var productPrices = ObjectFactory.GetInstance<PriceService>().GetPrices(new[] { product.GetAutoId() }); 56 var productPrice = productPrices[product.GetAutoId()]; 57 58 var leasingPrice = product.GetLeasingPrice(productPrice); 59 var leasingAllowed = productSpecs.GetAllByKey("AllowLeasing").Any(a => a.Value.IsYes()) && showPricesWithVat == "false" && leasingPrice.HasValue; 60 } 61 62 @if (product.Id != null) 63 { 64 if (leasingAllowed) 65 { 66 <div class="d-flex flex-column"> 67 @if (Model.Item.GetBoolean("ShowLeasingPrice")) 68 { 69 <p class="mb-2 product-leasing-price">@Translate("Leasing 36 mnd:") <span class="fw-bold">@Dynamicweb.Ecommerce.Services.Currencies.FormatCurrency(Dynamicweb.Ecommerce.Common.Context.Currency, leasingPrice.Value, true)</span> @Translate("eksl. moms pr.mnd.")</p>} 70 @if (Model.Item.GetBoolean("ShowLeasingButton")) 71 { 72 <button class="btn btn-outline-primary" onclick="Form(this).addData('@HttpUtility.HtmlEncode(product.Name)', '@product.Id')" data-bs-toggle="modal" data-bs-target="#leasingModal">@Translate("Ansøg leasing (uforpligtende)")</button> 73 } 74 </div> 75 } 76 else if (Pageview.IsVisualEditorMode) 77 { 78 <div class="d-flex flex-column"> 79 @if (Model.Item.GetBoolean("ShowLeasingPrice")) 80 { 81 <p class="mb-2 product-leasing-price">@Translate("Leasing 36 mnd:") <span class="fw-bold">xxxx.xx</span> @Translate("eksl. moms pr.mnd.")</p> 82 } 83 @if (Model.Item.GetBoolean("ShowLeasingButton")) 84 { 85 <button class="btn btn-outline-primary">@Translate("Visual Editor Mode: Placeholder, no leasing on product")</button> 86 } 87 @if (!Model.Item.GetBoolean("ShowLeasingButton") && !Model.Item.GetBoolean("ShowLeasingPrice")) 88 { 89 <button class="btn btn-outline-primary">@Translate("Visual Editor Mode: Placeholder, neither price or button turned selected")</button> 90 } 91 </div> 92 } 93 } 94 else if (Pageview.IsVisualEditorMode) 95 { 96 <div class="alert alert-dark m-0">@Translate("No products available")</div> 97 } 98
Error executing template "Designs/Swift/Paragraph/Swift_ProductAddToCart_Custom.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at CompiledRazorTemplates.Dynamic.RazorEngine_6f02946d78654eed881210b8c92dceac.Execute() in C:\inetpub\solutions\Goecker-2022-Prod\Files\Templates\Designs\Swift\Paragraph\Swift_ProductAddToCart_Custom.cshtml:line 60 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.CustomerExperienceCenter.Favorites 4 @using NLWI.Core.Factory 5 @using NLWI.Platforms.Dynamicweb9.Specs.Services 6 @using NORRIQ.CustomCode.Razor 7 @using System.Web 8 @using System.Globalization 9 @using Dynamicweb.Core.Encoders 10 11 @* CUSTOMIZED STANDARD SWIFT (v1.15.0) TEMPLATE *@ 12 @* NOTE: Item contains unsupported itemfields: ShowAddToFavorites, ShowFavoritesSelectorMasterProduct, ShowQuantitySelector, ShowUnitsSelector, WhenVariantsExist, HideButtonText, Icon, ButtonSize, HideInventory, HideStockState, VariantSelectorServicePageId *@ 13 14 @{ 15 ProductViewModel product = new ProductViewModel(); 16 17 ProductViewModelSettings productSetting = new ProductViewModelSettings 18 { 19 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 20 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 21 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 22 ShopId = Pageview.Area.EcomShopId 23 }; 24 25 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 26 { 27 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 28 } 29 else if (Pageview.Item["DummyProduct"] != null) 30 { 31 32 string dummyProductId = ""; 33 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 34 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 35 if (productList.Products != null) 36 { 37 foreach (var p in productList.Products) { dummyProductId = p.Id; } 38 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 39 product = dummyProduct; 40 } 41 else 42 { 43 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 44 } 45 } 46 else if (Pageview.Item["DummyProduct"] == null) 47 { 48 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 49 } 50 51 string fullWidth = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "w-100" : ""; 52 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 53 horizontalAlign = horizontalAlign == "center" ? "justify-content-center" : horizontalAlign; 54 horizontalAlign = horizontalAlign == "end" ? "justify-content-end" : horizontalAlign; 55 horizontalAlign = horizontalAlign == "full" ? "" : horizontalAlign; 56 57 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 58 bool anonymousUser = Pageview.User == null; 59 bool hideAddToCart = anonymousUsersLimitations.Contains("cart") && anonymousUser; 60 hideAddToCart = product.VariantInfo.VariantInfo != null && Model.Item.GetBoolean("CustomHideVariantSelector") ? true : hideAddToCart; 61 hideAddToCart = product.ProductFields.ContainsKey("Custom_DisablePurchase") ? Convert.ToBoolean(product.ProductFields["Custom_DisablePurchase"].Value) : hideAddToCart; //CUSTOM 62 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser; 63 bool hideFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("CustomHideFavoritesSelector")) ? Model.Item.GetBoolean("CustomHideFavoritesSelector") : false; 64 65 var favoriteParameters = new Dictionary<string, object>(); 66 if (!anonymousUser && !hideFavoritesSelector) 67 { 68 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 69 int defaultFavoriteListId = 0; 70 71 if (favoreiteLists.Count() == 1) 72 { 73 foreach (FavoriteList list in favoreiteLists) 74 { 75 defaultFavoriteListId = list.ListId; 76 } 77 } 78 79 favoriteParameters.Add("ListId", defaultFavoriteListId); 80 } 81 } 82 83 @if (!hideAddToCart && product.Id != null) 84 { 85 string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 86 if (!url.Contains("LayoutTemplate")) 87 { 88 url += url.Contains("?") ? "&LayoutTemplate=Swift_MiniCart.cshtml" : "?LayoutTemplate=Swift_MiniCart.cshtml"; 89 } 90 91 var productSpecificationService = ObjectFactory.GetInstance<IProductSpecificationService>(); 92 var productSpecs = productSpecificationService.GetProductSpecifications(product.GetAutoId()); 93 94 string flexFill = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "flex-fill" : ""; 95 96 string minQty = product.PurchaseMinimumQuantity != 1 ? "min=\"" + product.PurchaseMinimumQuantity.ToString() + "\"" : "min=\"1\""; 97 string stepQty = product.PurchaseQuantityStep > 1 ? product.PurchaseQuantityStep.ToString() : "1"; 98 string valueQty = product.PurchaseMinimumQuantity > product.PurchaseQuantityStep ? product.PurchaseMinimumQuantity.ToString() : stepQty; 99 string qtyValidCheck = stepQty != "1" ? "onkeyup=\"swift.Cart.QuantityValidate(event)\"" : ""; 100 101 string showPricesWithVat = HttpContext.Current.Session["Smartpage:ShowPricesWithVat"] != null ? Convert.ToString(HttpContext.Current.Session["Smartpage:ShowPricesWithVat"]) : Pageview.Area.EcomPricesWithVat.ToLower(); 102 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 103 104 <div class="d-flex @horizontalAlign @fullWidth item_@Model.Item.SystemName.ToLower()"> 105 <form method="post" action="@url" class="@fullWidth"> 106 <input type="hidden" name="redirect" value="false" /> 107 <input type="hidden" name="ProductId" value="@product.Id" /> 108 <input type="hidden" name="ProductName" value="@HtmlEncoder.HtmlEncode(product.Name)" /> 109 <input type="hidden" name="ProductVariantName" value="@HtmlEncoder.HtmlEncode(product.VariantName)" /> 110 <input type="hidden" name="ProductCurrency" value="@productSetting.CurrencyCode" /> 111 <input type="hidden" name="ProductPrice" value="@(showPricesWithVat == "false" && !neverShowVat ? product.Price.PriceWithoutVat.ToString("0.00", CultureInfo.InvariantCulture) : product.Price.Price.ToString("0.00", CultureInfo.InvariantCulture))" /> 112 <input type="hidden" name="ProductReferer" value="component_ProductAddToCart_Custom"> 113 <input type="hidden" name="cartcmd" value="add" /> 114 115 <input type="hidden" class="js-product-id" value="@product.Id" /> 116 117 @if (!string.IsNullOrEmpty(product.VariantId)) 118 { 119 <input type="hidden" name="VariantId" value="@product.VariantId" /> 120 } 121 @if (!Model.Item.GetBoolean("CustomUseQuantitySelector")) 122 { 123 <input id="Quantity_@product.Id" name="Quantity" value="@valueQty" type="hidden"> 124 125 if (!productSpecs.GetByKey("Preorder").Value.IsYes()) 126 { 127 <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary w-100 js-add-to-cart-button" title="@HttpUtility.HtmlEncode(Translate("Add to cart"))" id="AddToCartButton@(product.Id)">@Translate("Add to cart")</button> 128 } 129 else 130 { 131 <button type="button" class="btn btn-secondary w-100 text-uppercase" onclick="Form(this).addData('@HttpUtility.HtmlEncode(product.Name)', '@product.Id')" data-bs-toggle="modal" data-bs-target="#preorderModal"> 132 @Translate("Preorder") 133 </button> 134 } 135 } 136 else 137 { 138 <div class="input-group input-primary-button-group js-input-group d-flex flex-row flex-nowrap"> 139 <label for="Quantity_@(product.Id)" class="visually-hidden">@Translate("Quantity")</label> 140 <input id="Quantity_@product.Id" name="Quantity" value="@valueQty" step="@stepQty" @minQty class="form-control" style="max-width: 96px; min-width:64px;" type="number"> 141 <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary flex-fill js-add-to-cart-button" title="@Translate("Add to cart")" id="AddToCartButton@(product.Id)">@Translate("Add to cart")</button> 142 </div> 143 144 if (stepQty != "1") 145 { 146 <div class="invalid-feedback d-none"> 147 @Translate("Please select a quantity that is dividable by") @stepQty 148 </div> 149 } 150 } 151 </form> 152 @if (!anonymousUser && !hideFavoritesSelector) 153 { 154 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 155 } 156 </div> 157 } 158 else if (!anonymousUser && !hideFavoritesSelector) 159 { 160 <div class="d-flex @horizontalAlign @fullWidth item_@Model.Item.SystemName.ToLower()"> 161 <div class="flex-fill"> 162 @Translate("Add to favorites") @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 163 </div> 164 </div> 165 } 166 else if (Pageview.IsVisualEditorMode) 167 { 168 <div class="alert alert-dark m-0">@Translate("No products available")</div> 169 } 170
Error executing template "Designs/Swift/Paragraph/Swift_StockStatus.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at CompiledRazorTemplates.Dynamic.RazorEngine_732893cefeb34a04bf2b471dde03a575.Execute() in C:\inetpub\solutions\Goecker-2022-Prod\Files\Templates\Designs\Swift\Paragraph\Swift_StockStatus.cshtml:line 46 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 4 @* CUSTOMIZED SWIFT TEMPLATE *@ 5 6 @{ 7 ProductViewModel product = new ProductViewModel(); 8 9 ProductViewModelSettings productSetting = new ProductViewModelSettings 10 { 11 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 12 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 13 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 14 ShopId = Pageview.Area.EcomShopId 15 }; 16 17 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 18 { 19 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 20 } 21 else if (Pageview.Item["DummyProduct"] != null) 22 { 23 24 string dummyProductId = ""; 25 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 26 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 27 if (productList.Products != null) 28 { 29 foreach (var p in productList.Products) { dummyProductId = p.Id; } 30 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 31 product = dummyProduct; 32 } 33 else 34 { 35 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 36 } 37 } 38 else if (Pageview.Item["DummyProduct"] == null) 39 { 40 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 41 } 42 43 bool IsNeverOutOfStock = product.NeverOutOfstock; 44 var stockLocations = product.StockUnits; 45 46 var disableStock = product.ProductFields.ContainsKey("Custom_DisableStock") ? Convert.ToBoolean(product.ProductFields["Custom_DisableStock"].Value) : false; //CUSTOM 47 48 if (!Model.Item.GetBoolean("HideStockState") && !disableStock) //CUSTOM 49 { 50 if (!IsNeverOutOfStock) 51 { 52 var defaultOnlineStockLocationId = Model.Item.GetRawValueString("CustomDefaultStockLocation"); 53 54 //Custom: Build unified list of stock locations to display 55 var displayLocations = new List<(string Name, double Qty, bool IsDefault)>(); 56 57 //Custom: Check if default online stock location exists in the list 58 var hasDefaultLocation = !string.IsNullOrEmpty(defaultOnlineStockLocationId) && 59 stockLocations.Any(sl => sl.StockLocationId.ToString() == defaultOnlineStockLocationId); 60 61 //Custom: Add default online location first if not in the stock list 62 if (!string.IsNullOrEmpty(defaultOnlineStockLocationId) && !hasDefaultLocation) 63 { 64 var defaultOnlineStockLocation = Dynamicweb.Ecommerce.Services.StockService.GetStockLocation(Convert.ToInt32(defaultOnlineStockLocationId)); 65 var totalQty = stockLocations.Sum(sl => sl.StockLevel); 66 var defaultLocationName = defaultOnlineStockLocation.Name; 67 displayLocations.Add((defaultLocationName, totalQty, true)); 68 } 69 70 //Custom: Add existing stock locations 71 foreach (var stockLocation in stockLocations.OrderByDescending(location => defaultOnlineStockLocationId == location.StockLocationId.ToString())) 72 { 73 var locationName = stockLocation.StockLocationName; 74 var qty = stockLocation.StockLevel; 75 var isDefault = !string.IsNullOrEmpty(defaultOnlineStockLocationId) && 76 defaultOnlineStockLocationId == stockLocation.StockLocationId.ToString(); 77 78 //Custom: Sum inventory for all locations if online stock location 79 if (isDefault) 80 { 81 qty = stockLocations.Sum(sl => sl.StockLevel); 82 } 83 84 displayLocations.Add((locationName, qty, isDefault)); 85 } 86 87 <div class="mt-3 js-stock-state d-flex flex-column gap-2"> 88 <ul class="list-group"> 89 @foreach (var location in displayLocations) 90 { 91 <li class="list-group-item"> 92 <div class="product-stock-item d-flex justify-content-between"> 93 <span class="product-stock-location fs-7"> 94 @location.Name 95 </span> 96 <span class="product-stock-status fs-7"> 97 <span class="icon-stock @(location.Qty > 0 ? "icon-green" : "icon-red") position-relative"></span> 98 @(location.Qty > 0 ? Translate("label_in_Stock", "På lager") : Translate("label_not_in_stock", "Ikke på lager")) 99 </span> 100 </div> 101 </li> 102 } 103 </ul> 104 </div> 105 } 106 } 107 }
Error executing template "Designs/Swift/Paragraph/Swift_ProductDetailsCampaignAccordion_Custom.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at NORRIQ.CustomCode.Razor.ProductViewModelExtensions.GetAutoId(ProductViewModel product) in D:\a\1\s\NORRIQ.CustomCode\Razor\ProductViewModelExtensions.cs:line 47 at NORRIQ.CustomCode.Razor.ProductViewModelExtensions.GetSpecifications(ProductViewModel product) in D:\a\1\s\NORRIQ.CustomCode\Razor\ProductViewModelExtensions.cs:line 26 at CompiledRazorTemplates.Dynamic.RazorEngine_49f9606ac45c479caac38166283a96ab.Execute() in C:\inetpub\solutions\Goecker-2022-Prod\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDetailsCampaignAccordion_Custom.cshtml:line 47 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 NLWI.Core.Factory 4 @using NLWI.Platforms.Dynamicweb9.Specs.Services 5 @using NORRIQ.CustomCode.Razor 6 @using NORRIQ.CustomCode.Pricing 7 8 @* CUSTOM TEMPLATE SUPPORTED BY SWIFT (v1.15.0) *@ 9 10 @{ 11 ProductViewModel product = new ProductViewModel(); 12 13 ProductViewModelSettings productSetting = new ProductViewModelSettings 14 { 15 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 16 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 17 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 18 ShopId = Pageview.Area.EcomShopId 19 }; 20 21 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 22 { 23 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 24 } 25 else if (Pageview.Item["DummyProduct"] != null) 26 { 27 28 string dummyProductId = ""; 29 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 30 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 31 if (productList.Products != null) 32 { 33 foreach (var p in productList.Products) { dummyProductId = p.Id; } 34 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 35 product = dummyProduct; 36 } 37 else 38 { 39 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 40 } 41 } 42 else if (Pageview.Item["DummyProduct"] == null) 43 { 44 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 45 } 46 47 var specs = product.GetSpecifications(); 48 var shopId = Pageview.Area.EcomShopId; 49 var language = Dynamicweb.Ecommerce.Services.Languages.GetLanguage(Pageview.Area.EcomLanguageId); 50 var featurePostFix = language.CountryCode == "DK" ? "" : language.Culture; 51 var backgroundColor = Model.Item.GetString("BackgroundColor"); 52 var textColor = Model.Item.GetString("TextColor"); 53 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/"; 54 55 @* CAMPAIGN TEXT *@ 56 if (specs.HasKey("Kampagnetekst")) 57 { 58 @* Get the colors *@ 59 string campaignBackgroundColor = Model.Item.GetRawValueString("CustomBackgroundColor"); 60 string campaignTextColor = Model.Item.GetRawValueString("CustomTextColor"); 61 string campaignLinkColor = Model.Item.GetRawValueString("CustomLinkColor"); 62 63 <div class="accordion mt-3" id="accordion"> 64 <div class="accordion-item" style="background-color: @campaignBackgroundColor; color: @campaignTextColor;"> 65 66 <h2 class="accordion-header" id="headingOne"> 67 <button class="accordion-button fw-bold collapsed" type="button" style="background-color: @campaignBackgroundColor; color: @campaignTextColor;" data-bs-toggle="collapse" data-bs-target="#collapseCampaign" aria-expanded="false" aria-controls="collapseCampaign"> 68 @Translate("Smartpage:Product.Details.Campaigns", "Kampagner") 69 </button> 70 </h2> 71 72 <div id="collapseCampaign" class="accordion-collapse collapse" aria-labelledby="headingOne" data-bs-parent="#accordion"> 73 <div class="accordion-body d-flex justify-content-between flex-wrap"> 74 75 <div class="product-campaign clearfix" style="--background-color: @campaignBackgroundColor; --text-color: @campaignTextColor; --link-color: @campaignLinkColor;"> 76 <div class="card-block"> 77 @if (specs.HasKey("Kampagnestart") && specs.HasKey("Kampagneslut")) 78 { 79 var start = specs.GetByKey("Kampagnestart").AsDate(); 80 var slut = specs.GetByKey("Kampagneslut").AsDate(); 81 var nu = DateTime.Now; 82 83 if (start < nu && nu < slut) 84 { 85 <text> 86 @specs.GetByKey("Kampagnetekst").Value 87 </text> 88 } 89 90 } 91 else 92 { 93 <text> 94 @specs.GetByKey("Kampagnetekst").Value 95 </text> 96 } 97 </div> 98 </div> 99 </div> 100 </div> 101 </div> 102 </div> 103 } 104 else if (Pageview.IsVisualEditorMode) 105 { 106 <div class="alert alert-dark m-0">@Translate("Campaign info will be displayed here")</div> 107 } 108 } 109
Error executing template "Designs/Swift/Paragraph/CustomTradeIn.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at NORRIQ.CustomCode.Razor.ProductViewModelExtensions.GetAutoId(ProductViewModel product) in D:\a\1\s\NORRIQ.CustomCode\Razor\ProductViewModelExtensions.cs:line 47 at NORRIQ.CustomCode.Razor.ProductViewModelExtensions.GetSpecifications(ProductViewModel product) in D:\a\1\s\NORRIQ.CustomCode\Razor\ProductViewModelExtensions.cs:line 26 at CompiledRazorTemplates.Dynamic.RazorEngine_60bd87aa72ba40f293cada8f4c2e09f7.Execute() in C:\inetpub\solutions\Goecker-2022-Prod\Files\Templates\Designs\Swift\Paragraph\CustomTradeIn.cshtml:line 46 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 NLWI.Core.Factory 4 @using NORRIQ.CustomCode.Razor 5 6 @{ 7 ProductViewModel product = new ProductViewModel(); 8 9 ProductViewModelSettings productSetting = new ProductViewModelSettings 10 { 11 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 12 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 13 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 14 ShopId = Pageview.Area.EcomShopId 15 }; 16 17 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 18 { 19 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 20 } 21 else if (Pageview.Item["DummyProduct"] != null) 22 { 23 24 string dummyProductId = ""; 25 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 26 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 27 if (productList.Products != null) 28 { 29 foreach (var p in productList.Products) { dummyProductId = p.Id; } 30 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 31 product = dummyProduct; 32 } 33 else 34 { 35 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 36 } 37 } 38 else if (Pageview.Item["DummyProduct"] == null) 39 { 40 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 41 } 42 } 43 44 @if (product is object) 45 { 46 var specs = product.GetSpecifications(); 47 48 if (specs.GetByKey("LoopiaDisplayTradeInLink")?.Value == "true" || Pageview.IsVisualEditorMode) 49 { 50 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : string.Empty; 51 var header = Model.Item.GetRawValueString("Header"); 52 var text = Model.Item.GetRawValueString("Text"); 53 var link = Model.Item.GetLink("Link"); 54 var linkText = Model.Item.GetRawValueString("LinkText"); 55 56 <div class="accordion mt-3 @theme" id="accordion"> 57 <div class="accordion-item"> 58 59 <h2 class="accordion-header" id="headingOne"> 60 <button class="accordion-button fw-bold collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTrade" aria-expanded="true" aria-controls="collapseOne"> 61 @header 62 </button> 63 </h2> 64 65 <div id="collapseTrade" class="accordion-collapse collapse" aria-labelledby="headingOne" data-bs-parent="#accordion"> 66 <div class="accordion-body d-flex justify-content-between flex-wrap"> 67 <div class="p-2 fs-7"> 68 @text 69 <p> 70 <strong><a href="@(link?.Url + product.Number)">@linkText</a></strong> 71 </p> 72 </div> 73 </div> 74 </div> 75 </div> 76 </div> 77 } 78 } 79 else if (Pageview.IsVisualEditorMode) 80 { 81 <div class="alert alert-dark m-0">@Translate("Trade-in box will be displayed here")</div> 82 } 83
Error executing template "/Designs/Swift/Paragraph/Swift_ProductDetailsAccordion_Custom.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at NORRIQ.CustomCode.Razor.ProductViewModelExtensions.GetAutoId(ProductViewModel product) in D:\a\1\s\NORRIQ.CustomCode\Razor\ProductViewModelExtensions.cs:line 47 at NORRIQ.CustomCode.Razor.ProductViewModelExtensions.GetSpecifications(ProductViewModel product) in D:\a\1\s\NORRIQ.CustomCode\Razor\ProductViewModelExtensions.cs:line 26 at CompiledRazorTemplates.Dynamic.RazorEngine_2c343076fe8a4d3ba05fbc5f7330d2c1.Execute() in C:\inetpub\solutions\Goecker-2022-Prod\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDetailsAccordion_Custom.cshtml:line 47 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 NLWI.Core.Factory 4 @using NLWI.Platforms.Dynamicweb9.Specs.Services 5 @using NORRIQ.CustomCode.Razor 6 @using NORRIQ.CustomCode.Pricing 7 8 @* CUSTOM TEMPLATE SUPPORTED BY SWIFT (v1.15.0) *@ 9 10 @{ 11 ProductViewModel product = new ProductViewModel(); 12 13 ProductViewModelSettings productSetting = new ProductViewModelSettings 14 { 15 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 16 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 17 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 18 ShopId = Pageview.Area.EcomShopId 19 }; 20 21 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 22 { 23 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 24 } 25 else if (Pageview.Item["DummyProduct"] != null) 26 { 27 28 string dummyProductId = ""; 29 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 30 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 31 if (productList.Products != null) 32 { 33 foreach (var p in productList.Products) { dummyProductId = p.Id; } 34 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 35 product = dummyProduct; 36 } 37 else 38 { 39 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 40 } 41 } 42 else if (Pageview.Item["DummyProduct"] == null) 43 { 44 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetAllProducts(Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 45 } 46 47 var specs = product.GetSpecifications(); 48 var shopId = Pageview.Area.EcomShopId; 49 var language = Dynamicweb.Ecommerce.Services.Languages.GetLanguage(Pageview.Area.EcomLanguageId); 50 var featurePostFix = language.CountryCode == "DK" ? "" : language.CountryCode; 51 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/"; 52 53 <div class="accordion mt-3" id="accordion"> 54 @if (specs.GetAllByKey("Produktekspert" + featurePostFix).Any() && !Model.Item.GetBoolean("HideProductExperts")) 55 { 56 <div class="accordion-item"> 57 58 <h2 class="accordion-header" id="headingOne"> 59 <button class="accordion-button fw-bold collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne"> 60 <img src="@(iconPath)users.svg" class="me-2" /> 61 @Translate("Smartpage:Product.Details.Product experts", "Produkteksperter") 62 </button> 63 </h2> 64 65 <div id="collapseOne" class="accordion-collapse collapse" aria-labelledby="headingOne" data-bs-parent="#accordion"> 66 <div class="accordion-body d-flex justify-content-between flex-wrap flex-column"> 67 68 69 @foreach (var expert in specs.GetAllByKey("Produktekspert" + featurePostFix)) 70 { 71 var referenceSpecfication = expert.GetReferenceSpecification(); 72 73 var image = "~/Files/Images/missing_image.jpg"; 74 foreach (var test in referenceSpecfication.GetAllAvailableKeys()) 75 { 76 if (referenceSpecfication.GetByKey(test).Value.Contains("Images/Perfion")) 77 { 78 image = referenceSpecfication.GetByKey(test).Value; 79 } 80 } 81 <div class="expert-container d-flex"> 82 <img src="/Admin/Public/GetImage.ashx?Image=@image&Width=60&Height=60&Crop=5&Compression=85" width="60" height="60" /> 83 <div class="info ms-2 fs-7"> 84 <strong>@referenceSpecfication.GetByKey("Value").Value</strong><br /> 85 <a href="mailto:@referenceSpecfication.GetByKey("Email").Value" class="link-primary">@referenceSpecfication.GetByKey("Email").Value</a><br /> 86 <span class="icon-phone"></span> 87 @referenceSpecfication.GetByKey("Telefonnr").Value<br /> 88 @if (referenceSpecfication.HasKey("Lokation")) 89 { 90 <span class="icon-map"></span> 91 @referenceSpecfication.GetByKey("Lokation").Value 92 }<br /><br /> 93 </div> 94 </div> 95 } 96 </div> 97 </div> 98 </div> 99 } 100 101 @if (specs.GetAllByKey("PDFbrochure").Any()) 102 { 103 <div class="accordion-item"> 104 105 <h2 class="accordion-header" id="headingTwo"> 106 <button class="accordion-button collapsed fw-bold" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> 107 <img src="@(iconPath)file.svg" class="me-2" /> 108 @Translate("Brochurer og tech. Info") 109 </button> 110 </h2> 111 112 <div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordion"> 113 <div class="accordion-body d-flex flex-column justify-content-between flex-wrap gap-2"> 114 @foreach (var pdfbrochure in specs.GetAllByKey("PDFbrochure")) 115 { 116 <div class="d-flex align-items-center"> 117 <img src="@(iconPath)file.svg" class="me-2" /> 118 <a href="@(pdfbrochure.Value)" class="text-decoration-none" target="_blank"> 119 @Translate("Produkt brochure") 120 </a> 121 </div> 122 } 123 @foreach (var pdfmanual in specs.GetAllByKey("PDFmanual")) 124 { 125 <div class="d-flex align-items-center"> 126 <img src="@(iconPath)file.svg" class="me-2" /> 127 <a href="@(pdfmanual.Value)" class="text-decoration-none" target="_blank"> 128 @Translate("Produkt manual") 129 </a> 130 </div> 131 } 132 @foreach (var pdfbrochure in specs.GetAllByKey("PDFreview")) 133 { 134 <div class="d-flex align-items-center"> 135 <img src="@(iconPath)file.svg" class="me-2" /> 136 <a href="@(pdfbrochure.Value)" class="text-decoration-none" target="_blank"> 137 @Translate("Produkt review") 138 </a> 139 </div> 140 } 141 </div> 142 </div> 143 </div> 144 } 145 146 147 @if (!Model.Item.GetBoolean("HideFactSheetLink")) 148 { 149 string sheetId = Model.Item.GetString("PerfionDatasheetId"); 150 151 <div class="accordion-item"> 152 <h2 class="accordion-header" id="headingTwo"> 153 <button class="accordion-button collapsed fw-bold noafter" type="button" onclick="window.open('/Handlers/DownloadPerfionDocument.ashx?number=@(product.Number)&reportId=@(sheetId)&language=@Translate("perfion_language","DAN")')" rel="nofollow" target="_blank"> 154 <img src="@(iconPath)download.svg" class="me-2" /> 155 @Translate("Smartpage:Product.Details.Printable fact sheet", "Printbar fakta side") 156 </button> 157 </h2> 158 </div> 159 } 160 </div> 161 }