Vinkarafler og -tilbehør

Fra dekantering til opbevaring. Alt du behøver for at fuldende vinoplevelsen. Tilbehør, der gør både servering og opbevaring enkel og elegant.


Filter:

Dekanteringsprop
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_160448cdee3c46a18a7a094dcad8bbe9.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage_Custom.cshtml:line 32
   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 System @*//CUSTOM*@ 3 @using System.Collections.Generic @*//CUSTOM*@ 4 @using System.Linq @*//CUSTOM*@ 5 @using Dynamicweb.Core @*//CUSTOM*@ 6 @using Dynamicweb.Ecommerce.ProductCatalog 7 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 10 11 @{ 12 ProductViewModel product = null; 13 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 14 { 15 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 16 } 17 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 18 { 19 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 20 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 21 22 if (productList?.Products is object) 23 { 24 product = productList.Products[0]; 25 } 26 } 27 } 28 29 @if (product is object) 30 { 31 //CUSTOM 32 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 33 DateTime currentDate = DateTime.Today; 34 bool showComingSoonBadge = currentDate < launchDate; 35 string brandLogo = Model.Item.GetString("Custom_BrandLogo"); 36 string brandLogoKey = Model.Item.GetString("Custom_BrandLogoKey"); 37 string brandLogoAltText = Model.Item.GetString("Custom_BrandAltText"); 38 int brandLogoWidth = Model.Item.GetInt32("Custom_BrandLogoWidth") > 0 ? Model.Item.GetInt32("Custom_BrandLogoWidth") : 70; 39 string productBrand = product.ProductFields.ContainsKey("Custom_Brand") ? Converter.ToString(product.ProductFields["Custom_Brand"].Value) : ""; 40 bool enableBrandLogo = !string.IsNullOrEmpty(brandLogo) && !string.IsNullOrEmpty(brandLogoKey) && brandLogoKey == productBrand; 41 //--CUSTOM 42 43 string imagePath = product?.DefaultImage?.Value ?? ""; 44 string imagePathUrlEncoded = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 45 46 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 47 ratio = ratio != "0" ? ratio : ""; 48 string ratioCssClass = ratio != "" ? " ratio" : ""; 49 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 50 51 string width = Model.Item.GetRawValueString("Width", "auto"); 52 int smallImageSize = 640; 53 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 54 55 string ImageObjectFit = Model.Item.GetRawValueString("ImageObjectFit", "contain"); 56 57 string imagePathXs = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 58 string imagePathS = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 59 string imagePathFallBack = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 60 61 var badgeParms = new Dictionary<string, object>(); 62 badgeParms.Add("size", "h7"); 63 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 64 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 65 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 66 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 67 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 68 69 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 70 71 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 72 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 73 bool anonymousUser = Pageview.User == null; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 if (!anonymousUser && showFavoritesSelector) 77 { 78 int defaultFavoriteListId = 0; 79 80 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 81 if (favoreiteLists.Count() == 1) 82 { 83 foreach (FavoriteList list in favoreiteLists) 84 { 85 defaultFavoriteListId = list.ListId; 86 } 87 } 88 89 favoriteParameters.Add("ListId", defaultFavoriteListId); 90 } 91 92 MediaViewModel alternativeImage = new MediaViewModel(); 93 if (Model.Item.GetBoolean("ShowAlternativeImageOnHover")) 94 { 95 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 96 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 97 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 98 alternativeImage = allAssetsImages.FirstOrDefault(); 99 } 100 101 string altImagePathXs = string.Empty; 102 string altImagePathS = string.Empty; 103 104 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 105 { 106 altImagePathXs = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 107 altImagePathS = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 108 } 109 110 @* Theme settings *@ 111 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 112 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 113 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 114 115 string imageId = "ProductImage_" + product.Id + product.VariantId.Replace(".", "_"); 116 117 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 118 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 119 DateTime createdDate = product.Created.Value; 120 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 121 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 122 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) || showComingSoonBadge || showBadges; //CUSTOM 123 124 string fullWidth = width == "auto" ? "w-100" : ""; 125 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 126 127 @* -- CUSTOM -- Added image item prop *@ 128 if (!string.IsNullOrEmpty(imagePath)) 129 { 130 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 131 <div class="ratio" style="@(ratioVariable)"> 132 <div class="d-flex justify-content-center align-items-center"> 133 @* CUSTOM *@ 134 @if (enableBrandLogo) 135 { 136 <img src="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogo)" 137 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoAltText)" 138 class="productdefault-brand-logo" 139 width="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoWidth.ToString())" /> 140 } 141 @* CUSTOM END *@ 142 @if (imagePath.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 143 { 144 <img id="@imageId" 145 itemprop="image" 146 srcset=" 147 @imagePathXs @(smallImageSize)w, 148 @imagePathS @(largeImageSize)w" 149 sizes="(max-width: 992px) 50vw, 25vw" 150 src="@imagePathFallBack" 151 @if (Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 152 data-alternative-image=" 153 @altImagePathXs @(smallImageSize)w, 154 @altImagePathS @(largeImageSize)w" 155 onmouseover="swift.Image.swapImage(event)" 156 onmouseout="swift.Image.swapImage(event)" 157 </text> } 158 loading="lazy" 159 decoding="async" 160 class="h-100 w-100 @themePadding" 161 style="object-fit: @ImageObjectFit; @themeBorder" 162 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 163 } 164 //CUSTOM 165 else if (imagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) 166 { 167 <img id="@imageId" 168 itemprop="image" 169 srcset=" 170 @imagePathXs @(smallImageSize)w, 171 @imagePathS @(largeImageSize)w" 172 sizes="(max-width: 992px) 50vw, 25vw" 173 src="@imagePathFallBack" 174 data-alternative-image=" 175 @altImagePathXs @(smallImageSize)w, 176 @altImagePathS @(largeImageSize)w" 177 onmouseover="swift.Image.swapImage(event)" 178 onmouseout="swift.Image.swapImage(event)" 179 loading="lazy" 180 decoding="async" 181 class="h-100 w-100 @themePadding" 182 style="object-fit: @ImageObjectFit; @themeBorder" 183 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 184 } 185 //--CUSTOM 186 else 187 { 188 <img itemprop="image" 189 src="@product.DefaultImage.Value" 190 loading="lazy" 191 class="h-100 w-100 @themePadding" 192 style="object-fit: contain; @themeBorder" 193 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 194 } 195 </div> 196 </div> 197 198 @if (showBadges) 199 { 200 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 201 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 202 </div> 203 } 204 205 @if (!anonymousUser) 206 { 207 if (showFavoritesSelector) 208 { 209 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 210 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 211 </div> 212 } 213 } 214 </div> 215 } 216 } 217 else if (Pageview.IsVisualEditorMode) 218 { 219 <div class="alert alert-dark m-0">@Translate("No products available")</div> 220 } 221

Dekanteringsprop

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fb0d18a1de944f3a468232b7643f0eb.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 65
   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.Configuration @*//CUSTOM*@ 3 @using Dynamicweb.Core.Encoders @*//CUSTOM*@ 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 @using System.Globalization 6 @using System.IO @*//CUSTOM*@ 7 8 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 bool productIsDiscontinued = product is object && product.Discontinued; 33 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 34 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 35 } 36 37 @if (product is object && !hidePrice && !isDiscontinued) 38 { 39 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 40 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 41 42 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "h6 justify-content-lg-start"); //CUSTOM 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 45 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 46 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 47 48 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 50 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 51 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 52 53 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 54 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 55 string order = layout == "horizontal" ? string.Empty : "order-2"; 56 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 57 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 61 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 62 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 63 64 //CUSTOM 65 Dictionary<string, FieldValueViewModel> productFields = product.ProductFields; 66 var discountText = ""; 67 bool discountDiscontinued = false; 68 bool discountOnSale = false; 69 70 if (productFields.TryGetValue("Custom_Discontinued", out FieldValueViewModel discontinued)) 71 { 72 var firstValue = (discontinued.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 73 74 if (!string.IsNullOrWhiteSpace(firstValue)) 75 { 76 bool.TryParse(firstValue, out discountDiscontinued); 77 } 78 } 79 80 if (productFields.TryGetValue("Custom_OnSale", out FieldValueViewModel onsale)) 81 { 82 var firstValue = (onsale.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 83 84 if (!string.IsNullOrWhiteSpace(firstValue)) 85 { 86 bool.TryParse(firstValue, out discountOnSale); 87 } 88 } 89 90 if (discountDiscontinued && discountOnSale) 91 { 92 discountText = Translate("Outlet - tilbuddet gælder så længe lager haves"); 93 } 94 else 95 { 96 var discountInfo = Smartpage.EvaSolo.CampaignPrices.Helpers.DiscountHelper.GetDiscountInfo(product); 97 if (discountInfo != null) 98 { 99 discountText = string.Format(Translate(Model.Item.GetRawValueString("Custom_DiscountText", "Tilbuddet gælder {0} - {1}")), $"&zwnj;{discountInfo.ValidFromFormatted}&zwnj;", $"&zwnj;{discountInfo.ValidToFormatted}&zwnj;"); 100 } 101 } 102 string discountType = Model.Item.GetRawValueString("Custom_DiscountType", "none"); 103 string discountTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Custom_DiscountTheme")) ? "theme " + Model.Item.GetRawValueString("Custom_DiscountTheme").Replace(" ", "").Trim().ToLower() : string.Empty; 104 string discountIconColor = Model.Item.GetString("Custom_DiscountIconColor", "text-inherit"); 105 string discountIconSize = Model.Item.GetRawValueString("Custom_DiscountIconSize", "2"); 106 string discountImageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) ? Model.Item.GetFile("Custom_DiscountImage").Path : string.Empty; 107 string discountImagePath = discountImageSrc != string.Empty ? discountImageSrc : Model.Item.GetRawValueString("Custom_DiscountIcon", string.Empty); 108 discountImagePath = Path.GetExtension(discountImagePath).ToLower() != ".svg" ? "/Admin/Public/GetImage.ashx?image=" + discountImagePath + "&height=" + discountIconSize + "&width=" + discountIconSize + "&Crop=0&format=webp" : discountImagePath; 109 string discountImgAltText = Model.Item.GetRawValueString("FeatureAltText", string.Empty); 110 //--CUSTOM 111 112 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 113 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 114 115 string priceMin = ""; 116 string priceMax = ""; 117 118 string liveInfoClass = ""; 119 string productInfoFeed = ""; 120 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 121 if (isLazyLoadingForProductInfoEnabled) 122 { 123 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 124 { 125 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 126 if (!string.IsNullOrEmpty(productInfoFeed)) 127 { 128 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 129 } 130 } 131 liveInfoClass = "js-live-info"; 132 } 133 134 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 135 @if (showInformativePrice && product.PriceInformative.Price != 0) 136 { 137 <div class="opacity-50"> 138 <span>@Translate("RRP") </span> 139 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 140 </div> 141 } 142 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 143 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 144 145 @*//CUSTOM*@ 146 @if (showPricesWithVat == "false" && !neverShowVat) 147 { 148 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 149 { 150 <span class="text-price js-text-price"> 151 <span class="spinner-border" role="status"></span> 152 </span> 153 } 154 else 155 { 156 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 157 158 if (product?.VariantInfo?.VariantInfo != null) 159 { 160 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 161 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 162 } 163 if (priceMin != priceMax) 164 { 165 price = priceMin + " - " + priceMax; 166 } 167 168 <span class="@theme"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 195 <span class="@theme"> 196 <span class="text-price">@price</span> 197 </span> 198 } 199 } 200 201 @if (showPricesWithVat == "false" && !neverShowVat) 202 { 203 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 204 { 205 <span itemprop="price" content="" class="d-none"></span> 206 <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> 207 } 208 else 209 { 210 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 211 212 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 213 214 if (product.Price.Price != product.PriceBeforeDiscount.Price) 215 { 216 <span class="opacity-75 @(order)"> 217 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 218 </span> 219 220 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 221 { 222 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 223 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 224 { 225 PriceWithoutVAT = (product.PriceBeforeDiscount.PriceWithoutVat - product.Price.PriceWithoutVat) 226 }; 227 228 <span class="d-none d-sm-inline opacity-75 @(order)"> 229 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceWithoutVATFormatted)</span> 230 </span> 231 } 232 } 233 } 234 } 235 else 236 { 237 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 238 { 239 <span itemprop="price" content="" class="d-none"></span> 240 <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> 241 } 242 else 243 { 244 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 245 246 <span itemprop="price" content="@product.Price.Price.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 247 248 if (product.Price.Price < product.PriceBeforeDiscount.Price) 249 { 250 <span class="opacity-75 @(order)"> 251 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 252 </span> 253 254 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 255 { 256 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 257 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 258 { 259 PriceWithVAT = (product.PriceBeforeDiscount.Price - product.Price.Price) 260 }; 261 262 <span class="d-none d-sm-inline opacity-75 @(order)"> 263 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceFormatted)</span> 264 </span> 265 } 266 } 267 } 268 } 269 @*//--CUSTOM*@ 270 271 @*//CUSTOM*@ 272 @if (discountType == "icon-tooltip" && product.Price.Price != product.PriceBeforeDiscount.Price && discountText != null) 273 { 274 if ((!string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) || !discountImagePath.ToLower().Contains("none")) && discountImagePath != string.Empty) 275 { 276 <span data-bs-toggle="tooltip" data-bs-custom-class="@(discountTheme)" data-bs-html="true" data-bs-title="@HtmlEncoder.HtmlAttributeEncode(discountText)" data-bs-custom-prevent-event="click" data-bs-custom-click-close-delay="2000"> 277 @if (Path.GetExtension(discountImagePath).ToLower() == ".svg") 278 { 279 <span class="icon-auto @(discountIconColor)" style="vertical-align:text-top;height:@(discountIconSize)px;width:@(discountIconSize)px;">@ReadFile(discountImagePath)</span> 280 } 281 else 282 { 283 <img loading="lazy" src="@(discountImagePath)" alt="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" title="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" style="height:@(discountIconSize)px;width:@(discountIconSize)px;"> 284 } 285 </span> 286 } 287 } 288 @*//--CUSTOM*@ 289 290 @* Stock state for Schema.org, start *@ 291 @{ 292 Uri url = Dynamicweb.Context.Current.Request.Url; 293 } 294 295 <link itemprop="url" href="@url"> 296 297 @{ 298 bool IsNeverOutOfStock = product.NeverOutOfstock; 299 } 300 301 @if (IsNeverOutOfStock) 302 { 303 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 304 } 305 else 306 { 307 if (product.StockLevel > 0) 308 { 309 <span itemprop="availability" class="d-none">InStock</span> 310 } 311 else 312 { 313 <span itemprop="availability" class="d-none">OutOfStock</span> 314 } 315 } 316 @* Stock state for Schema.org, stop *@ 317 318 </div> 319 320 @if (showPricesWithVat == "false" && !neverShowVat) 321 { 322 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 323 { 324 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 325 } 326 else 327 { 328 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 329 330 if (product?.VariantInfo?.VariantInfo != null) 331 { 332 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 333 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 334 } 335 if (priceMin != priceMax) 336 { 337 price = priceMin + " - " + priceMax; 338 } 339 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 340 } 341 } 342 343 @*//CUSTOM*@ 344 @if (discountType == "inline" && product.Price.Price != product.PriceBeforeDiscount.Price && !string.IsNullOrEmpty(discountText)) 345 { 346 var discountFontSize = priceFontSize.Contains("h6") ? priceFontSize.Replace("h6", "small") : "small"; 347 348 <div class="@(discountFontSize) mt-1 d-flex flex-wrap @(flexDirection) @(horizontalAlign)"> 349 @discountText 350 </div> 351 } 352 @*//--CUSTOM*@ 353 354 </div> 355 } 356 else if (Pageview.IsVisualEditorMode) 357 { 358 <div class="alert alert-dark m-0" role="alert"> 359 <span>@Translate("No products available")</span> 360 </div> 361 } 362
Error executing template "Designs/Swift/Paragraph/Swift_ProductBadges_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_fe4e63c166214874a0bcb86da4f14f88.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBadges_Custom.cshtml:line 27
   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 System 3 @using System.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Content 7 @using Dynamicweb.Core 8 @using Dynamicweb.Ecommerce.ProductCatalog 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 28 DateTime currentDate = DateTime.Today; 29 bool showComingSoonBadge = currentDate < launchDate && string.Equals( Model.Item.GetRawValueString("NewBadgeDesign"), "comingsoon", StringComparison.InvariantCultureIgnoreCase ); 30 } 31 32 @if (product is object) 33 { 34 var badgeParms = new Dictionary<string, object>(); 35 badgeParms.Add("size", "h7"); 36 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 37 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 38 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 39 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 40 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 41 42 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 46 47 Dictionary<string, ParagraphInfoViewModel> badgeConfigurations; 48 List<string> campaignBadgesValues = Model.Item.GetRawValueString("CampaignBadges") != null ? Model.Item.GetRawValueString("CampaignBadges").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>(); 49 50 if (Dynamicweb.Context.Current.Items.Contains("badgeConfigurations")) 51 { 52 badgeConfigurations = (Dictionary<string, ParagraphInfoViewModel>)Dynamicweb.Context.Current.Items["badgeConfigurations"]; 53 } 54 else 55 { 56 var badgesPage = Pageview.AreaSettings.GetLink("EcommerceBadgesPage") != null ? Pageview.AreaSettings.GetLink("EcommerceBadgesPage").PageId : 0; 57 var allBadges = badgesPage != 0 ? Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(badgesPage) : null; 58 59 badgeConfigurations = new Dictionary<string, ParagraphInfoViewModel>(); 60 61 if ( allBadges != null ) 62 { 63 foreach ( Paragraph badge in allBadges ) 64 { 65 var paragraphviewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel( badge ); 66 string cssClassName = paragraphviewModel.Item.GetString( "CssClassName" )?.Trim().ToLower() ?? string.Empty;; 67 if ( !badgeConfigurations.ContainsKey( cssClassName ) ) 68 { 69 badgeConfigurations.Add( cssClassName, paragraphviewModel ); 70 } 71 } 72 } 73 74 Dynamicweb.Context.Current.Items.Add("badgeConfigurations", badgeConfigurations); 75 } 76 77 int badgesCount = 0; 78 if (badgeConfigurations.Any()) 79 { 80 foreach (string campaign in campaignBadgesValues) 81 { 82 if (!string.IsNullOrEmpty(campaign)) 83 { 84 FieldValueViewModel availableCampaignsObject; 85 product.ProductFields.TryGetValue("Campaign", out availableCampaignsObject); 86 87 if (availableCampaignsObject != null) 88 { 89 string campaignType = string.Empty; 90 91 if (badgeConfigurations.ContainsKey(campaign)) 92 { 93 ParagraphInfoViewModel paragraphviewModel; 94 if (badgeConfigurations.TryGetValue(campaign, out paragraphviewModel)) 95 { 96 campaignType = paragraphviewModel.Item.GetRawValueString("CampaignType"); 97 } 98 } 99 100 List<FieldOptionValueViewModel> availableCampaigns = (List<FieldOptionValueViewModel>)availableCampaignsObject.Value; 101 102 foreach (FieldOptionValueViewModel availableOption in availableCampaigns) 103 { 104 if (campaignType == availableOption.Value) 105 { 106 badgesCount++; 107 break; 108 } 109 } 110 } 111 } 112 } 113 } 114 115 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 116 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 117 DateTime createdDate = product.Created.Value; 118 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 119 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 120 showBadges = (!string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) && badgesCount != 0) || showComingSoonBadge || showBadges; 121 122 if (showBadges) 123 { 124 <div class="@badgeSize @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 125 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 126 </div> 127 } 128 else if (Pageview.IsVisualEditorMode) 129 { 130 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 131 } 132 } 133 else if (Pageview.IsVisualEditorMode) 134 { 135 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 136 } 137 138
Vinkube - Nordic kitchen - Rummer op til 6 flasker
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_160448cdee3c46a18a7a094dcad8bbe9.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage_Custom.cshtml:line 32
   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 System @*//CUSTOM*@ 3 @using System.Collections.Generic @*//CUSTOM*@ 4 @using System.Linq @*//CUSTOM*@ 5 @using Dynamicweb.Core @*//CUSTOM*@ 6 @using Dynamicweb.Ecommerce.ProductCatalog 7 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 10 11 @{ 12 ProductViewModel product = null; 13 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 14 { 15 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 16 } 17 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 18 { 19 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 20 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 21 22 if (productList?.Products is object) 23 { 24 product = productList.Products[0]; 25 } 26 } 27 } 28 29 @if (product is object) 30 { 31 //CUSTOM 32 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 33 DateTime currentDate = DateTime.Today; 34 bool showComingSoonBadge = currentDate < launchDate; 35 string brandLogo = Model.Item.GetString("Custom_BrandLogo"); 36 string brandLogoKey = Model.Item.GetString("Custom_BrandLogoKey"); 37 string brandLogoAltText = Model.Item.GetString("Custom_BrandAltText"); 38 int brandLogoWidth = Model.Item.GetInt32("Custom_BrandLogoWidth") > 0 ? Model.Item.GetInt32("Custom_BrandLogoWidth") : 70; 39 string productBrand = product.ProductFields.ContainsKey("Custom_Brand") ? Converter.ToString(product.ProductFields["Custom_Brand"].Value) : ""; 40 bool enableBrandLogo = !string.IsNullOrEmpty(brandLogo) && !string.IsNullOrEmpty(brandLogoKey) && brandLogoKey == productBrand; 41 //--CUSTOM 42 43 string imagePath = product?.DefaultImage?.Value ?? ""; 44 string imagePathUrlEncoded = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 45 46 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 47 ratio = ratio != "0" ? ratio : ""; 48 string ratioCssClass = ratio != "" ? " ratio" : ""; 49 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 50 51 string width = Model.Item.GetRawValueString("Width", "auto"); 52 int smallImageSize = 640; 53 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 54 55 string ImageObjectFit = Model.Item.GetRawValueString("ImageObjectFit", "contain"); 56 57 string imagePathXs = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 58 string imagePathS = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 59 string imagePathFallBack = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 60 61 var badgeParms = new Dictionary<string, object>(); 62 badgeParms.Add("size", "h7"); 63 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 64 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 65 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 66 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 67 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 68 69 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 70 71 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 72 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 73 bool anonymousUser = Pageview.User == null; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 if (!anonymousUser && showFavoritesSelector) 77 { 78 int defaultFavoriteListId = 0; 79 80 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 81 if (favoreiteLists.Count() == 1) 82 { 83 foreach (FavoriteList list in favoreiteLists) 84 { 85 defaultFavoriteListId = list.ListId; 86 } 87 } 88 89 favoriteParameters.Add("ListId", defaultFavoriteListId); 90 } 91 92 MediaViewModel alternativeImage = new MediaViewModel(); 93 if (Model.Item.GetBoolean("ShowAlternativeImageOnHover")) 94 { 95 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 96 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 97 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 98 alternativeImage = allAssetsImages.FirstOrDefault(); 99 } 100 101 string altImagePathXs = string.Empty; 102 string altImagePathS = string.Empty; 103 104 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 105 { 106 altImagePathXs = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 107 altImagePathS = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 108 } 109 110 @* Theme settings *@ 111 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 112 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 113 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 114 115 string imageId = "ProductImage_" + product.Id + product.VariantId.Replace(".", "_"); 116 117 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 118 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 119 DateTime createdDate = product.Created.Value; 120 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 121 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 122 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) || showComingSoonBadge || showBadges; //CUSTOM 123 124 string fullWidth = width == "auto" ? "w-100" : ""; 125 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 126 127 @* -- CUSTOM -- Added image item prop *@ 128 if (!string.IsNullOrEmpty(imagePath)) 129 { 130 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 131 <div class="ratio" style="@(ratioVariable)"> 132 <div class="d-flex justify-content-center align-items-center"> 133 @* CUSTOM *@ 134 @if (enableBrandLogo) 135 { 136 <img src="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogo)" 137 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoAltText)" 138 class="productdefault-brand-logo" 139 width="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoWidth.ToString())" /> 140 } 141 @* CUSTOM END *@ 142 @if (imagePath.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 143 { 144 <img id="@imageId" 145 itemprop="image" 146 srcset=" 147 @imagePathXs @(smallImageSize)w, 148 @imagePathS @(largeImageSize)w" 149 sizes="(max-width: 992px) 50vw, 25vw" 150 src="@imagePathFallBack" 151 @if (Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 152 data-alternative-image=" 153 @altImagePathXs @(smallImageSize)w, 154 @altImagePathS @(largeImageSize)w" 155 onmouseover="swift.Image.swapImage(event)" 156 onmouseout="swift.Image.swapImage(event)" 157 </text> } 158 loading="lazy" 159 decoding="async" 160 class="h-100 w-100 @themePadding" 161 style="object-fit: @ImageObjectFit; @themeBorder" 162 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 163 } 164 //CUSTOM 165 else if (imagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) 166 { 167 <img id="@imageId" 168 itemprop="image" 169 srcset=" 170 @imagePathXs @(smallImageSize)w, 171 @imagePathS @(largeImageSize)w" 172 sizes="(max-width: 992px) 50vw, 25vw" 173 src="@imagePathFallBack" 174 data-alternative-image=" 175 @altImagePathXs @(smallImageSize)w, 176 @altImagePathS @(largeImageSize)w" 177 onmouseover="swift.Image.swapImage(event)" 178 onmouseout="swift.Image.swapImage(event)" 179 loading="lazy" 180 decoding="async" 181 class="h-100 w-100 @themePadding" 182 style="object-fit: @ImageObjectFit; @themeBorder" 183 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 184 } 185 //--CUSTOM 186 else 187 { 188 <img itemprop="image" 189 src="@product.DefaultImage.Value" 190 loading="lazy" 191 class="h-100 w-100 @themePadding" 192 style="object-fit: contain; @themeBorder" 193 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 194 } 195 </div> 196 </div> 197 198 @if (showBadges) 199 { 200 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 201 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 202 </div> 203 } 204 205 @if (!anonymousUser) 206 { 207 if (showFavoritesSelector) 208 { 209 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 210 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 211 </div> 212 } 213 } 214 </div> 215 } 216 } 217 else if (Pageview.IsVisualEditorMode) 218 { 219 <div class="alert alert-dark m-0">@Translate("No products available")</div> 220 } 221

Vinkube - Nordic kitchen - Rummer op til 6 flasker

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fb0d18a1de944f3a468232b7643f0eb.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 65
   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.Configuration @*//CUSTOM*@ 3 @using Dynamicweb.Core.Encoders @*//CUSTOM*@ 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 @using System.Globalization 6 @using System.IO @*//CUSTOM*@ 7 8 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 bool productIsDiscontinued = product is object && product.Discontinued; 33 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 34 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 35 } 36 37 @if (product is object && !hidePrice && !isDiscontinued) 38 { 39 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 40 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 41 42 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "h6 justify-content-lg-start"); //CUSTOM 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 45 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 46 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 47 48 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 50 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 51 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 52 53 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 54 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 55 string order = layout == "horizontal" ? string.Empty : "order-2"; 56 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 57 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 61 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 62 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 63 64 //CUSTOM 65 Dictionary<string, FieldValueViewModel> productFields = product.ProductFields; 66 var discountText = ""; 67 bool discountDiscontinued = false; 68 bool discountOnSale = false; 69 70 if (productFields.TryGetValue("Custom_Discontinued", out FieldValueViewModel discontinued)) 71 { 72 var firstValue = (discontinued.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 73 74 if (!string.IsNullOrWhiteSpace(firstValue)) 75 { 76 bool.TryParse(firstValue, out discountDiscontinued); 77 } 78 } 79 80 if (productFields.TryGetValue("Custom_OnSale", out FieldValueViewModel onsale)) 81 { 82 var firstValue = (onsale.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 83 84 if (!string.IsNullOrWhiteSpace(firstValue)) 85 { 86 bool.TryParse(firstValue, out discountOnSale); 87 } 88 } 89 90 if (discountDiscontinued && discountOnSale) 91 { 92 discountText = Translate("Outlet - tilbuddet gælder så længe lager haves"); 93 } 94 else 95 { 96 var discountInfo = Smartpage.EvaSolo.CampaignPrices.Helpers.DiscountHelper.GetDiscountInfo(product); 97 if (discountInfo != null) 98 { 99 discountText = string.Format(Translate(Model.Item.GetRawValueString("Custom_DiscountText", "Tilbuddet gælder {0} - {1}")), $"&zwnj;{discountInfo.ValidFromFormatted}&zwnj;", $"&zwnj;{discountInfo.ValidToFormatted}&zwnj;"); 100 } 101 } 102 string discountType = Model.Item.GetRawValueString("Custom_DiscountType", "none"); 103 string discountTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Custom_DiscountTheme")) ? "theme " + Model.Item.GetRawValueString("Custom_DiscountTheme").Replace(" ", "").Trim().ToLower() : string.Empty; 104 string discountIconColor = Model.Item.GetString("Custom_DiscountIconColor", "text-inherit"); 105 string discountIconSize = Model.Item.GetRawValueString("Custom_DiscountIconSize", "2"); 106 string discountImageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) ? Model.Item.GetFile("Custom_DiscountImage").Path : string.Empty; 107 string discountImagePath = discountImageSrc != string.Empty ? discountImageSrc : Model.Item.GetRawValueString("Custom_DiscountIcon", string.Empty); 108 discountImagePath = Path.GetExtension(discountImagePath).ToLower() != ".svg" ? "/Admin/Public/GetImage.ashx?image=" + discountImagePath + "&height=" + discountIconSize + "&width=" + discountIconSize + "&Crop=0&format=webp" : discountImagePath; 109 string discountImgAltText = Model.Item.GetRawValueString("FeatureAltText", string.Empty); 110 //--CUSTOM 111 112 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 113 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 114 115 string priceMin = ""; 116 string priceMax = ""; 117 118 string liveInfoClass = ""; 119 string productInfoFeed = ""; 120 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 121 if (isLazyLoadingForProductInfoEnabled) 122 { 123 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 124 { 125 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 126 if (!string.IsNullOrEmpty(productInfoFeed)) 127 { 128 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 129 } 130 } 131 liveInfoClass = "js-live-info"; 132 } 133 134 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 135 @if (showInformativePrice && product.PriceInformative.Price != 0) 136 { 137 <div class="opacity-50"> 138 <span>@Translate("RRP") </span> 139 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 140 </div> 141 } 142 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 143 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 144 145 @*//CUSTOM*@ 146 @if (showPricesWithVat == "false" && !neverShowVat) 147 { 148 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 149 { 150 <span class="text-price js-text-price"> 151 <span class="spinner-border" role="status"></span> 152 </span> 153 } 154 else 155 { 156 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 157 158 if (product?.VariantInfo?.VariantInfo != null) 159 { 160 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 161 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 162 } 163 if (priceMin != priceMax) 164 { 165 price = priceMin + " - " + priceMax; 166 } 167 168 <span class="@theme"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 195 <span class="@theme"> 196 <span class="text-price">@price</span> 197 </span> 198 } 199 } 200 201 @if (showPricesWithVat == "false" && !neverShowVat) 202 { 203 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 204 { 205 <span itemprop="price" content="" class="d-none"></span> 206 <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> 207 } 208 else 209 { 210 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 211 212 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 213 214 if (product.Price.Price != product.PriceBeforeDiscount.Price) 215 { 216 <span class="opacity-75 @(order)"> 217 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 218 </span> 219 220 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 221 { 222 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 223 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 224 { 225 PriceWithoutVAT = (product.PriceBeforeDiscount.PriceWithoutVat - product.Price.PriceWithoutVat) 226 }; 227 228 <span class="d-none d-sm-inline opacity-75 @(order)"> 229 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceWithoutVATFormatted)</span> 230 </span> 231 } 232 } 233 } 234 } 235 else 236 { 237 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 238 { 239 <span itemprop="price" content="" class="d-none"></span> 240 <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> 241 } 242 else 243 { 244 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 245 246 <span itemprop="price" content="@product.Price.Price.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 247 248 if (product.Price.Price < product.PriceBeforeDiscount.Price) 249 { 250 <span class="opacity-75 @(order)"> 251 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 252 </span> 253 254 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 255 { 256 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 257 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 258 { 259 PriceWithVAT = (product.PriceBeforeDiscount.Price - product.Price.Price) 260 }; 261 262 <span class="d-none d-sm-inline opacity-75 @(order)"> 263 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceFormatted)</span> 264 </span> 265 } 266 } 267 } 268 } 269 @*//--CUSTOM*@ 270 271 @*//CUSTOM*@ 272 @if (discountType == "icon-tooltip" && product.Price.Price != product.PriceBeforeDiscount.Price && discountText != null) 273 { 274 if ((!string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) || !discountImagePath.ToLower().Contains("none")) && discountImagePath != string.Empty) 275 { 276 <span data-bs-toggle="tooltip" data-bs-custom-class="@(discountTheme)" data-bs-html="true" data-bs-title="@HtmlEncoder.HtmlAttributeEncode(discountText)" data-bs-custom-prevent-event="click" data-bs-custom-click-close-delay="2000"> 277 @if (Path.GetExtension(discountImagePath).ToLower() == ".svg") 278 { 279 <span class="icon-auto @(discountIconColor)" style="vertical-align:text-top;height:@(discountIconSize)px;width:@(discountIconSize)px;">@ReadFile(discountImagePath)</span> 280 } 281 else 282 { 283 <img loading="lazy" src="@(discountImagePath)" alt="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" title="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" style="height:@(discountIconSize)px;width:@(discountIconSize)px;"> 284 } 285 </span> 286 } 287 } 288 @*//--CUSTOM*@ 289 290 @* Stock state for Schema.org, start *@ 291 @{ 292 Uri url = Dynamicweb.Context.Current.Request.Url; 293 } 294 295 <link itemprop="url" href="@url"> 296 297 @{ 298 bool IsNeverOutOfStock = product.NeverOutOfstock; 299 } 300 301 @if (IsNeverOutOfStock) 302 { 303 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 304 } 305 else 306 { 307 if (product.StockLevel > 0) 308 { 309 <span itemprop="availability" class="d-none">InStock</span> 310 } 311 else 312 { 313 <span itemprop="availability" class="d-none">OutOfStock</span> 314 } 315 } 316 @* Stock state for Schema.org, stop *@ 317 318 </div> 319 320 @if (showPricesWithVat == "false" && !neverShowVat) 321 { 322 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 323 { 324 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 325 } 326 else 327 { 328 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 329 330 if (product?.VariantInfo?.VariantInfo != null) 331 { 332 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 333 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 334 } 335 if (priceMin != priceMax) 336 { 337 price = priceMin + " - " + priceMax; 338 } 339 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 340 } 341 } 342 343 @*//CUSTOM*@ 344 @if (discountType == "inline" && product.Price.Price != product.PriceBeforeDiscount.Price && !string.IsNullOrEmpty(discountText)) 345 { 346 var discountFontSize = priceFontSize.Contains("h6") ? priceFontSize.Replace("h6", "small") : "small"; 347 348 <div class="@(discountFontSize) mt-1 d-flex flex-wrap @(flexDirection) @(horizontalAlign)"> 349 @discountText 350 </div> 351 } 352 @*//--CUSTOM*@ 353 354 </div> 355 } 356 else if (Pageview.IsVisualEditorMode) 357 { 358 <div class="alert alert-dark m-0" role="alert"> 359 <span>@Translate("No products available")</span> 360 </div> 361 } 362
Error executing template "Designs/Swift/Paragraph/Swift_ProductBadges_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_fe4e63c166214874a0bcb86da4f14f88.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBadges_Custom.cshtml:line 27
   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 System 3 @using System.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Content 7 @using Dynamicweb.Core 8 @using Dynamicweb.Ecommerce.ProductCatalog 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 28 DateTime currentDate = DateTime.Today; 29 bool showComingSoonBadge = currentDate < launchDate && string.Equals( Model.Item.GetRawValueString("NewBadgeDesign"), "comingsoon", StringComparison.InvariantCultureIgnoreCase ); 30 } 31 32 @if (product is object) 33 { 34 var badgeParms = new Dictionary<string, object>(); 35 badgeParms.Add("size", "h7"); 36 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 37 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 38 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 39 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 40 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 41 42 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 46 47 Dictionary<string, ParagraphInfoViewModel> badgeConfigurations; 48 List<string> campaignBadgesValues = Model.Item.GetRawValueString("CampaignBadges") != null ? Model.Item.GetRawValueString("CampaignBadges").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>(); 49 50 if (Dynamicweb.Context.Current.Items.Contains("badgeConfigurations")) 51 { 52 badgeConfigurations = (Dictionary<string, ParagraphInfoViewModel>)Dynamicweb.Context.Current.Items["badgeConfigurations"]; 53 } 54 else 55 { 56 var badgesPage = Pageview.AreaSettings.GetLink("EcommerceBadgesPage") != null ? Pageview.AreaSettings.GetLink("EcommerceBadgesPage").PageId : 0; 57 var allBadges = badgesPage != 0 ? Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(badgesPage) : null; 58 59 badgeConfigurations = new Dictionary<string, ParagraphInfoViewModel>(); 60 61 if ( allBadges != null ) 62 { 63 foreach ( Paragraph badge in allBadges ) 64 { 65 var paragraphviewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel( badge ); 66 string cssClassName = paragraphviewModel.Item.GetString( "CssClassName" )?.Trim().ToLower() ?? string.Empty;; 67 if ( !badgeConfigurations.ContainsKey( cssClassName ) ) 68 { 69 badgeConfigurations.Add( cssClassName, paragraphviewModel ); 70 } 71 } 72 } 73 74 Dynamicweb.Context.Current.Items.Add("badgeConfigurations", badgeConfigurations); 75 } 76 77 int badgesCount = 0; 78 if (badgeConfigurations.Any()) 79 { 80 foreach (string campaign in campaignBadgesValues) 81 { 82 if (!string.IsNullOrEmpty(campaign)) 83 { 84 FieldValueViewModel availableCampaignsObject; 85 product.ProductFields.TryGetValue("Campaign", out availableCampaignsObject); 86 87 if (availableCampaignsObject != null) 88 { 89 string campaignType = string.Empty; 90 91 if (badgeConfigurations.ContainsKey(campaign)) 92 { 93 ParagraphInfoViewModel paragraphviewModel; 94 if (badgeConfigurations.TryGetValue(campaign, out paragraphviewModel)) 95 { 96 campaignType = paragraphviewModel.Item.GetRawValueString("CampaignType"); 97 } 98 } 99 100 List<FieldOptionValueViewModel> availableCampaigns = (List<FieldOptionValueViewModel>)availableCampaignsObject.Value; 101 102 foreach (FieldOptionValueViewModel availableOption in availableCampaigns) 103 { 104 if (campaignType == availableOption.Value) 105 { 106 badgesCount++; 107 break; 108 } 109 } 110 } 111 } 112 } 113 } 114 115 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 116 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 117 DateTime createdDate = product.Created.Value; 118 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 119 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 120 showBadges = (!string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) && badgesCount != 0) || showComingSoonBadge || showBadges; 121 122 if (showBadges) 123 { 124 <div class="@badgeSize @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 125 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 126 </div> 127 } 128 else if (Pageview.IsVisualEditorMode) 129 { 130 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 131 } 132 } 133 else if (Pageview.IsVisualEditorMode) 134 { 135 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 136 } 137 138
Liquid Lounge Champagneprop
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_160448cdee3c46a18a7a094dcad8bbe9.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage_Custom.cshtml:line 32
   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 System @*//CUSTOM*@ 3 @using System.Collections.Generic @*//CUSTOM*@ 4 @using System.Linq @*//CUSTOM*@ 5 @using Dynamicweb.Core @*//CUSTOM*@ 6 @using Dynamicweb.Ecommerce.ProductCatalog 7 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 10 11 @{ 12 ProductViewModel product = null; 13 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 14 { 15 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 16 } 17 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 18 { 19 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 20 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 21 22 if (productList?.Products is object) 23 { 24 product = productList.Products[0]; 25 } 26 } 27 } 28 29 @if (product is object) 30 { 31 //CUSTOM 32 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 33 DateTime currentDate = DateTime.Today; 34 bool showComingSoonBadge = currentDate < launchDate; 35 string brandLogo = Model.Item.GetString("Custom_BrandLogo"); 36 string brandLogoKey = Model.Item.GetString("Custom_BrandLogoKey"); 37 string brandLogoAltText = Model.Item.GetString("Custom_BrandAltText"); 38 int brandLogoWidth = Model.Item.GetInt32("Custom_BrandLogoWidth") > 0 ? Model.Item.GetInt32("Custom_BrandLogoWidth") : 70; 39 string productBrand = product.ProductFields.ContainsKey("Custom_Brand") ? Converter.ToString(product.ProductFields["Custom_Brand"].Value) : ""; 40 bool enableBrandLogo = !string.IsNullOrEmpty(brandLogo) && !string.IsNullOrEmpty(brandLogoKey) && brandLogoKey == productBrand; 41 //--CUSTOM 42 43 string imagePath = product?.DefaultImage?.Value ?? ""; 44 string imagePathUrlEncoded = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 45 46 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 47 ratio = ratio != "0" ? ratio : ""; 48 string ratioCssClass = ratio != "" ? " ratio" : ""; 49 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 50 51 string width = Model.Item.GetRawValueString("Width", "auto"); 52 int smallImageSize = 640; 53 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 54 55 string ImageObjectFit = Model.Item.GetRawValueString("ImageObjectFit", "contain"); 56 57 string imagePathXs = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 58 string imagePathS = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 59 string imagePathFallBack = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 60 61 var badgeParms = new Dictionary<string, object>(); 62 badgeParms.Add("size", "h7"); 63 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 64 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 65 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 66 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 67 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 68 69 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 70 71 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 72 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 73 bool anonymousUser = Pageview.User == null; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 if (!anonymousUser && showFavoritesSelector) 77 { 78 int defaultFavoriteListId = 0; 79 80 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 81 if (favoreiteLists.Count() == 1) 82 { 83 foreach (FavoriteList list in favoreiteLists) 84 { 85 defaultFavoriteListId = list.ListId; 86 } 87 } 88 89 favoriteParameters.Add("ListId", defaultFavoriteListId); 90 } 91 92 MediaViewModel alternativeImage = new MediaViewModel(); 93 if (Model.Item.GetBoolean("ShowAlternativeImageOnHover")) 94 { 95 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 96 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 97 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 98 alternativeImage = allAssetsImages.FirstOrDefault(); 99 } 100 101 string altImagePathXs = string.Empty; 102 string altImagePathS = string.Empty; 103 104 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 105 { 106 altImagePathXs = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 107 altImagePathS = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 108 } 109 110 @* Theme settings *@ 111 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 112 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 113 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 114 115 string imageId = "ProductImage_" + product.Id + product.VariantId.Replace(".", "_"); 116 117 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 118 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 119 DateTime createdDate = product.Created.Value; 120 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 121 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 122 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) || showComingSoonBadge || showBadges; //CUSTOM 123 124 string fullWidth = width == "auto" ? "w-100" : ""; 125 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 126 127 @* -- CUSTOM -- Added image item prop *@ 128 if (!string.IsNullOrEmpty(imagePath)) 129 { 130 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 131 <div class="ratio" style="@(ratioVariable)"> 132 <div class="d-flex justify-content-center align-items-center"> 133 @* CUSTOM *@ 134 @if (enableBrandLogo) 135 { 136 <img src="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogo)" 137 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoAltText)" 138 class="productdefault-brand-logo" 139 width="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoWidth.ToString())" /> 140 } 141 @* CUSTOM END *@ 142 @if (imagePath.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 143 { 144 <img id="@imageId" 145 itemprop="image" 146 srcset=" 147 @imagePathXs @(smallImageSize)w, 148 @imagePathS @(largeImageSize)w" 149 sizes="(max-width: 992px) 50vw, 25vw" 150 src="@imagePathFallBack" 151 @if (Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 152 data-alternative-image=" 153 @altImagePathXs @(smallImageSize)w, 154 @altImagePathS @(largeImageSize)w" 155 onmouseover="swift.Image.swapImage(event)" 156 onmouseout="swift.Image.swapImage(event)" 157 </text> } 158 loading="lazy" 159 decoding="async" 160 class="h-100 w-100 @themePadding" 161 style="object-fit: @ImageObjectFit; @themeBorder" 162 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 163 } 164 //CUSTOM 165 else if (imagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) 166 { 167 <img id="@imageId" 168 itemprop="image" 169 srcset=" 170 @imagePathXs @(smallImageSize)w, 171 @imagePathS @(largeImageSize)w" 172 sizes="(max-width: 992px) 50vw, 25vw" 173 src="@imagePathFallBack" 174 data-alternative-image=" 175 @altImagePathXs @(smallImageSize)w, 176 @altImagePathS @(largeImageSize)w" 177 onmouseover="swift.Image.swapImage(event)" 178 onmouseout="swift.Image.swapImage(event)" 179 loading="lazy" 180 decoding="async" 181 class="h-100 w-100 @themePadding" 182 style="object-fit: @ImageObjectFit; @themeBorder" 183 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 184 } 185 //--CUSTOM 186 else 187 { 188 <img itemprop="image" 189 src="@product.DefaultImage.Value" 190 loading="lazy" 191 class="h-100 w-100 @themePadding" 192 style="object-fit: contain; @themeBorder" 193 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 194 } 195 </div> 196 </div> 197 198 @if (showBadges) 199 { 200 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 201 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 202 </div> 203 } 204 205 @if (!anonymousUser) 206 { 207 if (showFavoritesSelector) 208 { 209 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 210 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 211 </div> 212 } 213 } 214 </div> 215 } 216 } 217 else if (Pageview.IsVisualEditorMode) 218 { 219 <div class="alert alert-dark m-0">@Translate("No products available")</div> 220 } 221

Liquid Lounge Champagneprop

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fb0d18a1de944f3a468232b7643f0eb.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 65
   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.Configuration @*//CUSTOM*@ 3 @using Dynamicweb.Core.Encoders @*//CUSTOM*@ 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 @using System.Globalization 6 @using System.IO @*//CUSTOM*@ 7 8 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 bool productIsDiscontinued = product is object && product.Discontinued; 33 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 34 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 35 } 36 37 @if (product is object && !hidePrice && !isDiscontinued) 38 { 39 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 40 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 41 42 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "h6 justify-content-lg-start"); //CUSTOM 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 45 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 46 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 47 48 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 50 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 51 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 52 53 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 54 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 55 string order = layout == "horizontal" ? string.Empty : "order-2"; 56 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 57 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 61 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 62 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 63 64 //CUSTOM 65 Dictionary<string, FieldValueViewModel> productFields = product.ProductFields; 66 var discountText = ""; 67 bool discountDiscontinued = false; 68 bool discountOnSale = false; 69 70 if (productFields.TryGetValue("Custom_Discontinued", out FieldValueViewModel discontinued)) 71 { 72 var firstValue = (discontinued.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 73 74 if (!string.IsNullOrWhiteSpace(firstValue)) 75 { 76 bool.TryParse(firstValue, out discountDiscontinued); 77 } 78 } 79 80 if (productFields.TryGetValue("Custom_OnSale", out FieldValueViewModel onsale)) 81 { 82 var firstValue = (onsale.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 83 84 if (!string.IsNullOrWhiteSpace(firstValue)) 85 { 86 bool.TryParse(firstValue, out discountOnSale); 87 } 88 } 89 90 if (discountDiscontinued && discountOnSale) 91 { 92 discountText = Translate("Outlet - tilbuddet gælder så længe lager haves"); 93 } 94 else 95 { 96 var discountInfo = Smartpage.EvaSolo.CampaignPrices.Helpers.DiscountHelper.GetDiscountInfo(product); 97 if (discountInfo != null) 98 { 99 discountText = string.Format(Translate(Model.Item.GetRawValueString("Custom_DiscountText", "Tilbuddet gælder {0} - {1}")), $"&zwnj;{discountInfo.ValidFromFormatted}&zwnj;", $"&zwnj;{discountInfo.ValidToFormatted}&zwnj;"); 100 } 101 } 102 string discountType = Model.Item.GetRawValueString("Custom_DiscountType", "none"); 103 string discountTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Custom_DiscountTheme")) ? "theme " + Model.Item.GetRawValueString("Custom_DiscountTheme").Replace(" ", "").Trim().ToLower() : string.Empty; 104 string discountIconColor = Model.Item.GetString("Custom_DiscountIconColor", "text-inherit"); 105 string discountIconSize = Model.Item.GetRawValueString("Custom_DiscountIconSize", "2"); 106 string discountImageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) ? Model.Item.GetFile("Custom_DiscountImage").Path : string.Empty; 107 string discountImagePath = discountImageSrc != string.Empty ? discountImageSrc : Model.Item.GetRawValueString("Custom_DiscountIcon", string.Empty); 108 discountImagePath = Path.GetExtension(discountImagePath).ToLower() != ".svg" ? "/Admin/Public/GetImage.ashx?image=" + discountImagePath + "&height=" + discountIconSize + "&width=" + discountIconSize + "&Crop=0&format=webp" : discountImagePath; 109 string discountImgAltText = Model.Item.GetRawValueString("FeatureAltText", string.Empty); 110 //--CUSTOM 111 112 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 113 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 114 115 string priceMin = ""; 116 string priceMax = ""; 117 118 string liveInfoClass = ""; 119 string productInfoFeed = ""; 120 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 121 if (isLazyLoadingForProductInfoEnabled) 122 { 123 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 124 { 125 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 126 if (!string.IsNullOrEmpty(productInfoFeed)) 127 { 128 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 129 } 130 } 131 liveInfoClass = "js-live-info"; 132 } 133 134 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 135 @if (showInformativePrice && product.PriceInformative.Price != 0) 136 { 137 <div class="opacity-50"> 138 <span>@Translate("RRP") </span> 139 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 140 </div> 141 } 142 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 143 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 144 145 @*//CUSTOM*@ 146 @if (showPricesWithVat == "false" && !neverShowVat) 147 { 148 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 149 { 150 <span class="text-price js-text-price"> 151 <span class="spinner-border" role="status"></span> 152 </span> 153 } 154 else 155 { 156 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 157 158 if (product?.VariantInfo?.VariantInfo != null) 159 { 160 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 161 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 162 } 163 if (priceMin != priceMax) 164 { 165 price = priceMin + " - " + priceMax; 166 } 167 168 <span class="@theme"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 195 <span class="@theme"> 196 <span class="text-price">@price</span> 197 </span> 198 } 199 } 200 201 @if (showPricesWithVat == "false" && !neverShowVat) 202 { 203 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 204 { 205 <span itemprop="price" content="" class="d-none"></span> 206 <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> 207 } 208 else 209 { 210 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 211 212 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 213 214 if (product.Price.Price != product.PriceBeforeDiscount.Price) 215 { 216 <span class="opacity-75 @(order)"> 217 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 218 </span> 219 220 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 221 { 222 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 223 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 224 { 225 PriceWithoutVAT = (product.PriceBeforeDiscount.PriceWithoutVat - product.Price.PriceWithoutVat) 226 }; 227 228 <span class="d-none d-sm-inline opacity-75 @(order)"> 229 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceWithoutVATFormatted)</span> 230 </span> 231 } 232 } 233 } 234 } 235 else 236 { 237 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 238 { 239 <span itemprop="price" content="" class="d-none"></span> 240 <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> 241 } 242 else 243 { 244 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 245 246 <span itemprop="price" content="@product.Price.Price.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 247 248 if (product.Price.Price < product.PriceBeforeDiscount.Price) 249 { 250 <span class="opacity-75 @(order)"> 251 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 252 </span> 253 254 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 255 { 256 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 257 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 258 { 259 PriceWithVAT = (product.PriceBeforeDiscount.Price - product.Price.Price) 260 }; 261 262 <span class="d-none d-sm-inline opacity-75 @(order)"> 263 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceFormatted)</span> 264 </span> 265 } 266 } 267 } 268 } 269 @*//--CUSTOM*@ 270 271 @*//CUSTOM*@ 272 @if (discountType == "icon-tooltip" && product.Price.Price != product.PriceBeforeDiscount.Price && discountText != null) 273 { 274 if ((!string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) || !discountImagePath.ToLower().Contains("none")) && discountImagePath != string.Empty) 275 { 276 <span data-bs-toggle="tooltip" data-bs-custom-class="@(discountTheme)" data-bs-html="true" data-bs-title="@HtmlEncoder.HtmlAttributeEncode(discountText)" data-bs-custom-prevent-event="click" data-bs-custom-click-close-delay="2000"> 277 @if (Path.GetExtension(discountImagePath).ToLower() == ".svg") 278 { 279 <span class="icon-auto @(discountIconColor)" style="vertical-align:text-top;height:@(discountIconSize)px;width:@(discountIconSize)px;">@ReadFile(discountImagePath)</span> 280 } 281 else 282 { 283 <img loading="lazy" src="@(discountImagePath)" alt="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" title="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" style="height:@(discountIconSize)px;width:@(discountIconSize)px;"> 284 } 285 </span> 286 } 287 } 288 @*//--CUSTOM*@ 289 290 @* Stock state for Schema.org, start *@ 291 @{ 292 Uri url = Dynamicweb.Context.Current.Request.Url; 293 } 294 295 <link itemprop="url" href="@url"> 296 297 @{ 298 bool IsNeverOutOfStock = product.NeverOutOfstock; 299 } 300 301 @if (IsNeverOutOfStock) 302 { 303 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 304 } 305 else 306 { 307 if (product.StockLevel > 0) 308 { 309 <span itemprop="availability" class="d-none">InStock</span> 310 } 311 else 312 { 313 <span itemprop="availability" class="d-none">OutOfStock</span> 314 } 315 } 316 @* Stock state for Schema.org, stop *@ 317 318 </div> 319 320 @if (showPricesWithVat == "false" && !neverShowVat) 321 { 322 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 323 { 324 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 325 } 326 else 327 { 328 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 329 330 if (product?.VariantInfo?.VariantInfo != null) 331 { 332 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 333 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 334 } 335 if (priceMin != priceMax) 336 { 337 price = priceMin + " - " + priceMax; 338 } 339 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 340 } 341 } 342 343 @*//CUSTOM*@ 344 @if (discountType == "inline" && product.Price.Price != product.PriceBeforeDiscount.Price && !string.IsNullOrEmpty(discountText)) 345 { 346 var discountFontSize = priceFontSize.Contains("h6") ? priceFontSize.Replace("h6", "small") : "small"; 347 348 <div class="@(discountFontSize) mt-1 d-flex flex-wrap @(flexDirection) @(horizontalAlign)"> 349 @discountText 350 </div> 351 } 352 @*//--CUSTOM*@ 353 354 </div> 355 } 356 else if (Pageview.IsVisualEditorMode) 357 { 358 <div class="alert alert-dark m-0" role="alert"> 359 <span>@Translate("No products available")</span> 360 </div> 361 } 362
Error executing template "Designs/Swift/Paragraph/Swift_ProductBadges_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_fe4e63c166214874a0bcb86da4f14f88.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBadges_Custom.cshtml:line 27
   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 System 3 @using System.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Content 7 @using Dynamicweb.Core 8 @using Dynamicweb.Ecommerce.ProductCatalog 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 28 DateTime currentDate = DateTime.Today; 29 bool showComingSoonBadge = currentDate < launchDate && string.Equals( Model.Item.GetRawValueString("NewBadgeDesign"), "comingsoon", StringComparison.InvariantCultureIgnoreCase ); 30 } 31 32 @if (product is object) 33 { 34 var badgeParms = new Dictionary<string, object>(); 35 badgeParms.Add("size", "h7"); 36 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 37 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 38 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 39 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 40 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 41 42 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 46 47 Dictionary<string, ParagraphInfoViewModel> badgeConfigurations; 48 List<string> campaignBadgesValues = Model.Item.GetRawValueString("CampaignBadges") != null ? Model.Item.GetRawValueString("CampaignBadges").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>(); 49 50 if (Dynamicweb.Context.Current.Items.Contains("badgeConfigurations")) 51 { 52 badgeConfigurations = (Dictionary<string, ParagraphInfoViewModel>)Dynamicweb.Context.Current.Items["badgeConfigurations"]; 53 } 54 else 55 { 56 var badgesPage = Pageview.AreaSettings.GetLink("EcommerceBadgesPage") != null ? Pageview.AreaSettings.GetLink("EcommerceBadgesPage").PageId : 0; 57 var allBadges = badgesPage != 0 ? Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(badgesPage) : null; 58 59 badgeConfigurations = new Dictionary<string, ParagraphInfoViewModel>(); 60 61 if ( allBadges != null ) 62 { 63 foreach ( Paragraph badge in allBadges ) 64 { 65 var paragraphviewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel( badge ); 66 string cssClassName = paragraphviewModel.Item.GetString( "CssClassName" )?.Trim().ToLower() ?? string.Empty;; 67 if ( !badgeConfigurations.ContainsKey( cssClassName ) ) 68 { 69 badgeConfigurations.Add( cssClassName, paragraphviewModel ); 70 } 71 } 72 } 73 74 Dynamicweb.Context.Current.Items.Add("badgeConfigurations", badgeConfigurations); 75 } 76 77 int badgesCount = 0; 78 if (badgeConfigurations.Any()) 79 { 80 foreach (string campaign in campaignBadgesValues) 81 { 82 if (!string.IsNullOrEmpty(campaign)) 83 { 84 FieldValueViewModel availableCampaignsObject; 85 product.ProductFields.TryGetValue("Campaign", out availableCampaignsObject); 86 87 if (availableCampaignsObject != null) 88 { 89 string campaignType = string.Empty; 90 91 if (badgeConfigurations.ContainsKey(campaign)) 92 { 93 ParagraphInfoViewModel paragraphviewModel; 94 if (badgeConfigurations.TryGetValue(campaign, out paragraphviewModel)) 95 { 96 campaignType = paragraphviewModel.Item.GetRawValueString("CampaignType"); 97 } 98 } 99 100 List<FieldOptionValueViewModel> availableCampaigns = (List<FieldOptionValueViewModel>)availableCampaignsObject.Value; 101 102 foreach (FieldOptionValueViewModel availableOption in availableCampaigns) 103 { 104 if (campaignType == availableOption.Value) 105 { 106 badgesCount++; 107 break; 108 } 109 } 110 } 111 } 112 } 113 } 114 115 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 116 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 117 DateTime createdDate = product.Created.Value; 118 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 119 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 120 showBadges = (!string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) && badgesCount != 0) || showComingSoonBadge || showBadges; 121 122 if (showBadges) 123 { 124 <div class="@badgeSize @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 125 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 126 </div> 127 } 128 else if (Pageview.IsVisualEditorMode) 129 { 130 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 131 } 132 } 133 else if (Pageview.IsVisualEditorMode) 134 { 135 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 136 } 137 138
Liquid Lounge Vinprop
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_160448cdee3c46a18a7a094dcad8bbe9.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage_Custom.cshtml:line 32
   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 System @*//CUSTOM*@ 3 @using System.Collections.Generic @*//CUSTOM*@ 4 @using System.Linq @*//CUSTOM*@ 5 @using Dynamicweb.Core @*//CUSTOM*@ 6 @using Dynamicweb.Ecommerce.ProductCatalog 7 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 10 11 @{ 12 ProductViewModel product = null; 13 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 14 { 15 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 16 } 17 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 18 { 19 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 20 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 21 22 if (productList?.Products is object) 23 { 24 product = productList.Products[0]; 25 } 26 } 27 } 28 29 @if (product is object) 30 { 31 //CUSTOM 32 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 33 DateTime currentDate = DateTime.Today; 34 bool showComingSoonBadge = currentDate < launchDate; 35 string brandLogo = Model.Item.GetString("Custom_BrandLogo"); 36 string brandLogoKey = Model.Item.GetString("Custom_BrandLogoKey"); 37 string brandLogoAltText = Model.Item.GetString("Custom_BrandAltText"); 38 int brandLogoWidth = Model.Item.GetInt32("Custom_BrandLogoWidth") > 0 ? Model.Item.GetInt32("Custom_BrandLogoWidth") : 70; 39 string productBrand = product.ProductFields.ContainsKey("Custom_Brand") ? Converter.ToString(product.ProductFields["Custom_Brand"].Value) : ""; 40 bool enableBrandLogo = !string.IsNullOrEmpty(brandLogo) && !string.IsNullOrEmpty(brandLogoKey) && brandLogoKey == productBrand; 41 //--CUSTOM 42 43 string imagePath = product?.DefaultImage?.Value ?? ""; 44 string imagePathUrlEncoded = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 45 46 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 47 ratio = ratio != "0" ? ratio : ""; 48 string ratioCssClass = ratio != "" ? " ratio" : ""; 49 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 50 51 string width = Model.Item.GetRawValueString("Width", "auto"); 52 int smallImageSize = 640; 53 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 54 55 string ImageObjectFit = Model.Item.GetRawValueString("ImageObjectFit", "contain"); 56 57 string imagePathXs = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 58 string imagePathS = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 59 string imagePathFallBack = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 60 61 var badgeParms = new Dictionary<string, object>(); 62 badgeParms.Add("size", "h7"); 63 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 64 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 65 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 66 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 67 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 68 69 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 70 71 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 72 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 73 bool anonymousUser = Pageview.User == null; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 if (!anonymousUser && showFavoritesSelector) 77 { 78 int defaultFavoriteListId = 0; 79 80 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 81 if (favoreiteLists.Count() == 1) 82 { 83 foreach (FavoriteList list in favoreiteLists) 84 { 85 defaultFavoriteListId = list.ListId; 86 } 87 } 88 89 favoriteParameters.Add("ListId", defaultFavoriteListId); 90 } 91 92 MediaViewModel alternativeImage = new MediaViewModel(); 93 if (Model.Item.GetBoolean("ShowAlternativeImageOnHover")) 94 { 95 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 96 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 97 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 98 alternativeImage = allAssetsImages.FirstOrDefault(); 99 } 100 101 string altImagePathXs = string.Empty; 102 string altImagePathS = string.Empty; 103 104 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 105 { 106 altImagePathXs = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 107 altImagePathS = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 108 } 109 110 @* Theme settings *@ 111 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 112 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 113 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 114 115 string imageId = "ProductImage_" + product.Id + product.VariantId.Replace(".", "_"); 116 117 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 118 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 119 DateTime createdDate = product.Created.Value; 120 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 121 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 122 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) || showComingSoonBadge || showBadges; //CUSTOM 123 124 string fullWidth = width == "auto" ? "w-100" : ""; 125 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 126 127 @* -- CUSTOM -- Added image item prop *@ 128 if (!string.IsNullOrEmpty(imagePath)) 129 { 130 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 131 <div class="ratio" style="@(ratioVariable)"> 132 <div class="d-flex justify-content-center align-items-center"> 133 @* CUSTOM *@ 134 @if (enableBrandLogo) 135 { 136 <img src="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogo)" 137 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoAltText)" 138 class="productdefault-brand-logo" 139 width="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoWidth.ToString())" /> 140 } 141 @* CUSTOM END *@ 142 @if (imagePath.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 143 { 144 <img id="@imageId" 145 itemprop="image" 146 srcset=" 147 @imagePathXs @(smallImageSize)w, 148 @imagePathS @(largeImageSize)w" 149 sizes="(max-width: 992px) 50vw, 25vw" 150 src="@imagePathFallBack" 151 @if (Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 152 data-alternative-image=" 153 @altImagePathXs @(smallImageSize)w, 154 @altImagePathS @(largeImageSize)w" 155 onmouseover="swift.Image.swapImage(event)" 156 onmouseout="swift.Image.swapImage(event)" 157 </text> } 158 loading="lazy" 159 decoding="async" 160 class="h-100 w-100 @themePadding" 161 style="object-fit: @ImageObjectFit; @themeBorder" 162 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 163 } 164 //CUSTOM 165 else if (imagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) 166 { 167 <img id="@imageId" 168 itemprop="image" 169 srcset=" 170 @imagePathXs @(smallImageSize)w, 171 @imagePathS @(largeImageSize)w" 172 sizes="(max-width: 992px) 50vw, 25vw" 173 src="@imagePathFallBack" 174 data-alternative-image=" 175 @altImagePathXs @(smallImageSize)w, 176 @altImagePathS @(largeImageSize)w" 177 onmouseover="swift.Image.swapImage(event)" 178 onmouseout="swift.Image.swapImage(event)" 179 loading="lazy" 180 decoding="async" 181 class="h-100 w-100 @themePadding" 182 style="object-fit: @ImageObjectFit; @themeBorder" 183 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 184 } 185 //--CUSTOM 186 else 187 { 188 <img itemprop="image" 189 src="@product.DefaultImage.Value" 190 loading="lazy" 191 class="h-100 w-100 @themePadding" 192 style="object-fit: contain; @themeBorder" 193 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 194 } 195 </div> 196 </div> 197 198 @if (showBadges) 199 { 200 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 201 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 202 </div> 203 } 204 205 @if (!anonymousUser) 206 { 207 if (showFavoritesSelector) 208 { 209 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 210 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 211 </div> 212 } 213 } 214 </div> 215 } 216 } 217 else if (Pageview.IsVisualEditorMode) 218 { 219 <div class="alert alert-dark m-0">@Translate("No products available")</div> 220 } 221

Liquid Lounge Vinprop

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fb0d18a1de944f3a468232b7643f0eb.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 65
   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.Configuration @*//CUSTOM*@ 3 @using Dynamicweb.Core.Encoders @*//CUSTOM*@ 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 @using System.Globalization 6 @using System.IO @*//CUSTOM*@ 7 8 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 bool productIsDiscontinued = product is object && product.Discontinued; 33 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 34 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 35 } 36 37 @if (product is object && !hidePrice && !isDiscontinued) 38 { 39 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 40 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 41 42 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "h6 justify-content-lg-start"); //CUSTOM 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 45 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 46 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 47 48 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 50 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 51 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 52 53 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 54 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 55 string order = layout == "horizontal" ? string.Empty : "order-2"; 56 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 57 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 61 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 62 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 63 64 //CUSTOM 65 Dictionary<string, FieldValueViewModel> productFields = product.ProductFields; 66 var discountText = ""; 67 bool discountDiscontinued = false; 68 bool discountOnSale = false; 69 70 if (productFields.TryGetValue("Custom_Discontinued", out FieldValueViewModel discontinued)) 71 { 72 var firstValue = (discontinued.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 73 74 if (!string.IsNullOrWhiteSpace(firstValue)) 75 { 76 bool.TryParse(firstValue, out discountDiscontinued); 77 } 78 } 79 80 if (productFields.TryGetValue("Custom_OnSale", out FieldValueViewModel onsale)) 81 { 82 var firstValue = (onsale.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 83 84 if (!string.IsNullOrWhiteSpace(firstValue)) 85 { 86 bool.TryParse(firstValue, out discountOnSale); 87 } 88 } 89 90 if (discountDiscontinued && discountOnSale) 91 { 92 discountText = Translate("Outlet - tilbuddet gælder så længe lager haves"); 93 } 94 else 95 { 96 var discountInfo = Smartpage.EvaSolo.CampaignPrices.Helpers.DiscountHelper.GetDiscountInfo(product); 97 if (discountInfo != null) 98 { 99 discountText = string.Format(Translate(Model.Item.GetRawValueString("Custom_DiscountText", "Tilbuddet gælder {0} - {1}")), $"&zwnj;{discountInfo.ValidFromFormatted}&zwnj;", $"&zwnj;{discountInfo.ValidToFormatted}&zwnj;"); 100 } 101 } 102 string discountType = Model.Item.GetRawValueString("Custom_DiscountType", "none"); 103 string discountTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Custom_DiscountTheme")) ? "theme " + Model.Item.GetRawValueString("Custom_DiscountTheme").Replace(" ", "").Trim().ToLower() : string.Empty; 104 string discountIconColor = Model.Item.GetString("Custom_DiscountIconColor", "text-inherit"); 105 string discountIconSize = Model.Item.GetRawValueString("Custom_DiscountIconSize", "2"); 106 string discountImageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) ? Model.Item.GetFile("Custom_DiscountImage").Path : string.Empty; 107 string discountImagePath = discountImageSrc != string.Empty ? discountImageSrc : Model.Item.GetRawValueString("Custom_DiscountIcon", string.Empty); 108 discountImagePath = Path.GetExtension(discountImagePath).ToLower() != ".svg" ? "/Admin/Public/GetImage.ashx?image=" + discountImagePath + "&height=" + discountIconSize + "&width=" + discountIconSize + "&Crop=0&format=webp" : discountImagePath; 109 string discountImgAltText = Model.Item.GetRawValueString("FeatureAltText", string.Empty); 110 //--CUSTOM 111 112 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 113 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 114 115 string priceMin = ""; 116 string priceMax = ""; 117 118 string liveInfoClass = ""; 119 string productInfoFeed = ""; 120 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 121 if (isLazyLoadingForProductInfoEnabled) 122 { 123 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 124 { 125 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 126 if (!string.IsNullOrEmpty(productInfoFeed)) 127 { 128 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 129 } 130 } 131 liveInfoClass = "js-live-info"; 132 } 133 134 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 135 @if (showInformativePrice && product.PriceInformative.Price != 0) 136 { 137 <div class="opacity-50"> 138 <span>@Translate("RRP") </span> 139 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 140 </div> 141 } 142 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 143 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 144 145 @*//CUSTOM*@ 146 @if (showPricesWithVat == "false" && !neverShowVat) 147 { 148 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 149 { 150 <span class="text-price js-text-price"> 151 <span class="spinner-border" role="status"></span> 152 </span> 153 } 154 else 155 { 156 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 157 158 if (product?.VariantInfo?.VariantInfo != null) 159 { 160 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 161 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 162 } 163 if (priceMin != priceMax) 164 { 165 price = priceMin + " - " + priceMax; 166 } 167 168 <span class="@theme"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 195 <span class="@theme"> 196 <span class="text-price">@price</span> 197 </span> 198 } 199 } 200 201 @if (showPricesWithVat == "false" && !neverShowVat) 202 { 203 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 204 { 205 <span itemprop="price" content="" class="d-none"></span> 206 <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> 207 } 208 else 209 { 210 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 211 212 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 213 214 if (product.Price.Price != product.PriceBeforeDiscount.Price) 215 { 216 <span class="opacity-75 @(order)"> 217 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 218 </span> 219 220 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 221 { 222 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 223 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 224 { 225 PriceWithoutVAT = (product.PriceBeforeDiscount.PriceWithoutVat - product.Price.PriceWithoutVat) 226 }; 227 228 <span class="d-none d-sm-inline opacity-75 @(order)"> 229 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceWithoutVATFormatted)</span> 230 </span> 231 } 232 } 233 } 234 } 235 else 236 { 237 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 238 { 239 <span itemprop="price" content="" class="d-none"></span> 240 <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> 241 } 242 else 243 { 244 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 245 246 <span itemprop="price" content="@product.Price.Price.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 247 248 if (product.Price.Price < product.PriceBeforeDiscount.Price) 249 { 250 <span class="opacity-75 @(order)"> 251 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 252 </span> 253 254 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 255 { 256 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 257 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 258 { 259 PriceWithVAT = (product.PriceBeforeDiscount.Price - product.Price.Price) 260 }; 261 262 <span class="d-none d-sm-inline opacity-75 @(order)"> 263 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceFormatted)</span> 264 </span> 265 } 266 } 267 } 268 } 269 @*//--CUSTOM*@ 270 271 @*//CUSTOM*@ 272 @if (discountType == "icon-tooltip" && product.Price.Price != product.PriceBeforeDiscount.Price && discountText != null) 273 { 274 if ((!string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) || !discountImagePath.ToLower().Contains("none")) && discountImagePath != string.Empty) 275 { 276 <span data-bs-toggle="tooltip" data-bs-custom-class="@(discountTheme)" data-bs-html="true" data-bs-title="@HtmlEncoder.HtmlAttributeEncode(discountText)" data-bs-custom-prevent-event="click" data-bs-custom-click-close-delay="2000"> 277 @if (Path.GetExtension(discountImagePath).ToLower() == ".svg") 278 { 279 <span class="icon-auto @(discountIconColor)" style="vertical-align:text-top;height:@(discountIconSize)px;width:@(discountIconSize)px;">@ReadFile(discountImagePath)</span> 280 } 281 else 282 { 283 <img loading="lazy" src="@(discountImagePath)" alt="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" title="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" style="height:@(discountIconSize)px;width:@(discountIconSize)px;"> 284 } 285 </span> 286 } 287 } 288 @*//--CUSTOM*@ 289 290 @* Stock state for Schema.org, start *@ 291 @{ 292 Uri url = Dynamicweb.Context.Current.Request.Url; 293 } 294 295 <link itemprop="url" href="@url"> 296 297 @{ 298 bool IsNeverOutOfStock = product.NeverOutOfstock; 299 } 300 301 @if (IsNeverOutOfStock) 302 { 303 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 304 } 305 else 306 { 307 if (product.StockLevel > 0) 308 { 309 <span itemprop="availability" class="d-none">InStock</span> 310 } 311 else 312 { 313 <span itemprop="availability" class="d-none">OutOfStock</span> 314 } 315 } 316 @* Stock state for Schema.org, stop *@ 317 318 </div> 319 320 @if (showPricesWithVat == "false" && !neverShowVat) 321 { 322 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 323 { 324 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 325 } 326 else 327 { 328 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 329 330 if (product?.VariantInfo?.VariantInfo != null) 331 { 332 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 333 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 334 } 335 if (priceMin != priceMax) 336 { 337 price = priceMin + " - " + priceMax; 338 } 339 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 340 } 341 } 342 343 @*//CUSTOM*@ 344 @if (discountType == "inline" && product.Price.Price != product.PriceBeforeDiscount.Price && !string.IsNullOrEmpty(discountText)) 345 { 346 var discountFontSize = priceFontSize.Contains("h6") ? priceFontSize.Replace("h6", "small") : "small"; 347 348 <div class="@(discountFontSize) mt-1 d-flex flex-wrap @(flexDirection) @(horizontalAlign)"> 349 @discountText 350 </div> 351 } 352 @*//--CUSTOM*@ 353 354 </div> 355 } 356 else if (Pageview.IsVisualEditorMode) 357 { 358 <div class="alert alert-dark m-0" role="alert"> 359 <span>@Translate("No products available")</span> 360 </div> 361 } 362
Error executing template "Designs/Swift/Paragraph/Swift_ProductBadges_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_fe4e63c166214874a0bcb86da4f14f88.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBadges_Custom.cshtml:line 27
   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 System 3 @using System.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Content 7 @using Dynamicweb.Core 8 @using Dynamicweb.Ecommerce.ProductCatalog 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 28 DateTime currentDate = DateTime.Today; 29 bool showComingSoonBadge = currentDate < launchDate && string.Equals( Model.Item.GetRawValueString("NewBadgeDesign"), "comingsoon", StringComparison.InvariantCultureIgnoreCase ); 30 } 31 32 @if (product is object) 33 { 34 var badgeParms = new Dictionary<string, object>(); 35 badgeParms.Add("size", "h7"); 36 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 37 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 38 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 39 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 40 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 41 42 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 46 47 Dictionary<string, ParagraphInfoViewModel> badgeConfigurations; 48 List<string> campaignBadgesValues = Model.Item.GetRawValueString("CampaignBadges") != null ? Model.Item.GetRawValueString("CampaignBadges").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>(); 49 50 if (Dynamicweb.Context.Current.Items.Contains("badgeConfigurations")) 51 { 52 badgeConfigurations = (Dictionary<string, ParagraphInfoViewModel>)Dynamicweb.Context.Current.Items["badgeConfigurations"]; 53 } 54 else 55 { 56 var badgesPage = Pageview.AreaSettings.GetLink("EcommerceBadgesPage") != null ? Pageview.AreaSettings.GetLink("EcommerceBadgesPage").PageId : 0; 57 var allBadges = badgesPage != 0 ? Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(badgesPage) : null; 58 59 badgeConfigurations = new Dictionary<string, ParagraphInfoViewModel>(); 60 61 if ( allBadges != null ) 62 { 63 foreach ( Paragraph badge in allBadges ) 64 { 65 var paragraphviewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel( badge ); 66 string cssClassName = paragraphviewModel.Item.GetString( "CssClassName" )?.Trim().ToLower() ?? string.Empty;; 67 if ( !badgeConfigurations.ContainsKey( cssClassName ) ) 68 { 69 badgeConfigurations.Add( cssClassName, paragraphviewModel ); 70 } 71 } 72 } 73 74 Dynamicweb.Context.Current.Items.Add("badgeConfigurations", badgeConfigurations); 75 } 76 77 int badgesCount = 0; 78 if (badgeConfigurations.Any()) 79 { 80 foreach (string campaign in campaignBadgesValues) 81 { 82 if (!string.IsNullOrEmpty(campaign)) 83 { 84 FieldValueViewModel availableCampaignsObject; 85 product.ProductFields.TryGetValue("Campaign", out availableCampaignsObject); 86 87 if (availableCampaignsObject != null) 88 { 89 string campaignType = string.Empty; 90 91 if (badgeConfigurations.ContainsKey(campaign)) 92 { 93 ParagraphInfoViewModel paragraphviewModel; 94 if (badgeConfigurations.TryGetValue(campaign, out paragraphviewModel)) 95 { 96 campaignType = paragraphviewModel.Item.GetRawValueString("CampaignType"); 97 } 98 } 99 100 List<FieldOptionValueViewModel> availableCampaigns = (List<FieldOptionValueViewModel>)availableCampaignsObject.Value; 101 102 foreach (FieldOptionValueViewModel availableOption in availableCampaigns) 103 { 104 if (campaignType == availableOption.Value) 105 { 106 badgesCount++; 107 break; 108 } 109 } 110 } 111 } 112 } 113 } 114 115 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 116 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 117 DateTime createdDate = product.Created.Value; 118 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 119 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 120 showBadges = (!string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) && badgesCount != 0) || showComingSoonBadge || showBadges; 121 122 if (showBadges) 123 { 124 <div class="@badgeSize @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 125 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 126 </div> 127 } 128 else if (Pageview.IsVisualEditorMode) 129 { 130 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 131 } 132 } 133 else if (Pageview.IsVisualEditorMode) 134 { 135 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 136 } 137 138
Liquid Lounge Isoleret isspand med ske
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_160448cdee3c46a18a7a094dcad8bbe9.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage_Custom.cshtml:line 32
   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 System @*//CUSTOM*@ 3 @using System.Collections.Generic @*//CUSTOM*@ 4 @using System.Linq @*//CUSTOM*@ 5 @using Dynamicweb.Core @*//CUSTOM*@ 6 @using Dynamicweb.Ecommerce.ProductCatalog 7 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 10 11 @{ 12 ProductViewModel product = null; 13 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 14 { 15 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 16 } 17 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 18 { 19 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 20 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 21 22 if (productList?.Products is object) 23 { 24 product = productList.Products[0]; 25 } 26 } 27 } 28 29 @if (product is object) 30 { 31 //CUSTOM 32 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 33 DateTime currentDate = DateTime.Today; 34 bool showComingSoonBadge = currentDate < launchDate; 35 string brandLogo = Model.Item.GetString("Custom_BrandLogo"); 36 string brandLogoKey = Model.Item.GetString("Custom_BrandLogoKey"); 37 string brandLogoAltText = Model.Item.GetString("Custom_BrandAltText"); 38 int brandLogoWidth = Model.Item.GetInt32("Custom_BrandLogoWidth") > 0 ? Model.Item.GetInt32("Custom_BrandLogoWidth") : 70; 39 string productBrand = product.ProductFields.ContainsKey("Custom_Brand") ? Converter.ToString(product.ProductFields["Custom_Brand"].Value) : ""; 40 bool enableBrandLogo = !string.IsNullOrEmpty(brandLogo) && !string.IsNullOrEmpty(brandLogoKey) && brandLogoKey == productBrand; 41 //--CUSTOM 42 43 string imagePath = product?.DefaultImage?.Value ?? ""; 44 string imagePathUrlEncoded = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 45 46 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 47 ratio = ratio != "0" ? ratio : ""; 48 string ratioCssClass = ratio != "" ? " ratio" : ""; 49 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 50 51 string width = Model.Item.GetRawValueString("Width", "auto"); 52 int smallImageSize = 640; 53 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 54 55 string ImageObjectFit = Model.Item.GetRawValueString("ImageObjectFit", "contain"); 56 57 string imagePathXs = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 58 string imagePathS = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 59 string imagePathFallBack = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 60 61 var badgeParms = new Dictionary<string, object>(); 62 badgeParms.Add("size", "h7"); 63 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 64 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 65 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 66 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 67 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 68 69 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 70 71 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 72 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 73 bool anonymousUser = Pageview.User == null; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 if (!anonymousUser && showFavoritesSelector) 77 { 78 int defaultFavoriteListId = 0; 79 80 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 81 if (favoreiteLists.Count() == 1) 82 { 83 foreach (FavoriteList list in favoreiteLists) 84 { 85 defaultFavoriteListId = list.ListId; 86 } 87 } 88 89 favoriteParameters.Add("ListId", defaultFavoriteListId); 90 } 91 92 MediaViewModel alternativeImage = new MediaViewModel(); 93 if (Model.Item.GetBoolean("ShowAlternativeImageOnHover")) 94 { 95 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 96 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 97 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 98 alternativeImage = allAssetsImages.FirstOrDefault(); 99 } 100 101 string altImagePathXs = string.Empty; 102 string altImagePathS = string.Empty; 103 104 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 105 { 106 altImagePathXs = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 107 altImagePathS = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 108 } 109 110 @* Theme settings *@ 111 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 112 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 113 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 114 115 string imageId = "ProductImage_" + product.Id + product.VariantId.Replace(".", "_"); 116 117 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 118 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 119 DateTime createdDate = product.Created.Value; 120 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 121 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 122 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) || showComingSoonBadge || showBadges; //CUSTOM 123 124 string fullWidth = width == "auto" ? "w-100" : ""; 125 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 126 127 @* -- CUSTOM -- Added image item prop *@ 128 if (!string.IsNullOrEmpty(imagePath)) 129 { 130 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 131 <div class="ratio" style="@(ratioVariable)"> 132 <div class="d-flex justify-content-center align-items-center"> 133 @* CUSTOM *@ 134 @if (enableBrandLogo) 135 { 136 <img src="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogo)" 137 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoAltText)" 138 class="productdefault-brand-logo" 139 width="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoWidth.ToString())" /> 140 } 141 @* CUSTOM END *@ 142 @if (imagePath.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 143 { 144 <img id="@imageId" 145 itemprop="image" 146 srcset=" 147 @imagePathXs @(smallImageSize)w, 148 @imagePathS @(largeImageSize)w" 149 sizes="(max-width: 992px) 50vw, 25vw" 150 src="@imagePathFallBack" 151 @if (Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 152 data-alternative-image=" 153 @altImagePathXs @(smallImageSize)w, 154 @altImagePathS @(largeImageSize)w" 155 onmouseover="swift.Image.swapImage(event)" 156 onmouseout="swift.Image.swapImage(event)" 157 </text> } 158 loading="lazy" 159 decoding="async" 160 class="h-100 w-100 @themePadding" 161 style="object-fit: @ImageObjectFit; @themeBorder" 162 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 163 } 164 //CUSTOM 165 else if (imagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) 166 { 167 <img id="@imageId" 168 itemprop="image" 169 srcset=" 170 @imagePathXs @(smallImageSize)w, 171 @imagePathS @(largeImageSize)w" 172 sizes="(max-width: 992px) 50vw, 25vw" 173 src="@imagePathFallBack" 174 data-alternative-image=" 175 @altImagePathXs @(smallImageSize)w, 176 @altImagePathS @(largeImageSize)w" 177 onmouseover="swift.Image.swapImage(event)" 178 onmouseout="swift.Image.swapImage(event)" 179 loading="lazy" 180 decoding="async" 181 class="h-100 w-100 @themePadding" 182 style="object-fit: @ImageObjectFit; @themeBorder" 183 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 184 } 185 //--CUSTOM 186 else 187 { 188 <img itemprop="image" 189 src="@product.DefaultImage.Value" 190 loading="lazy" 191 class="h-100 w-100 @themePadding" 192 style="object-fit: contain; @themeBorder" 193 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 194 } 195 </div> 196 </div> 197 198 @if (showBadges) 199 { 200 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 201 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 202 </div> 203 } 204 205 @if (!anonymousUser) 206 { 207 if (showFavoritesSelector) 208 { 209 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 210 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 211 </div> 212 } 213 } 214 </div> 215 } 216 } 217 else if (Pageview.IsVisualEditorMode) 218 { 219 <div class="alert alert-dark m-0">@Translate("No products available")</div> 220 } 221

Liquid Lounge Isoleret isspand med ske

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fb0d18a1de944f3a468232b7643f0eb.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 65
   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.Configuration @*//CUSTOM*@ 3 @using Dynamicweb.Core.Encoders @*//CUSTOM*@ 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 @using System.Globalization 6 @using System.IO @*//CUSTOM*@ 7 8 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 bool productIsDiscontinued = product is object && product.Discontinued; 33 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 34 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 35 } 36 37 @if (product is object && !hidePrice && !isDiscontinued) 38 { 39 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 40 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 41 42 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "h6 justify-content-lg-start"); //CUSTOM 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 45 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 46 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 47 48 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 50 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 51 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 52 53 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 54 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 55 string order = layout == "horizontal" ? string.Empty : "order-2"; 56 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 57 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 61 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 62 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 63 64 //CUSTOM 65 Dictionary<string, FieldValueViewModel> productFields = product.ProductFields; 66 var discountText = ""; 67 bool discountDiscontinued = false; 68 bool discountOnSale = false; 69 70 if (productFields.TryGetValue("Custom_Discontinued", out FieldValueViewModel discontinued)) 71 { 72 var firstValue = (discontinued.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 73 74 if (!string.IsNullOrWhiteSpace(firstValue)) 75 { 76 bool.TryParse(firstValue, out discountDiscontinued); 77 } 78 } 79 80 if (productFields.TryGetValue("Custom_OnSale", out FieldValueViewModel onsale)) 81 { 82 var firstValue = (onsale.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 83 84 if (!string.IsNullOrWhiteSpace(firstValue)) 85 { 86 bool.TryParse(firstValue, out discountOnSale); 87 } 88 } 89 90 if (discountDiscontinued && discountOnSale) 91 { 92 discountText = Translate("Outlet - tilbuddet gælder så længe lager haves"); 93 } 94 else 95 { 96 var discountInfo = Smartpage.EvaSolo.CampaignPrices.Helpers.DiscountHelper.GetDiscountInfo(product); 97 if (discountInfo != null) 98 { 99 discountText = string.Format(Translate(Model.Item.GetRawValueString("Custom_DiscountText", "Tilbuddet gælder {0} - {1}")), $"&zwnj;{discountInfo.ValidFromFormatted}&zwnj;", $"&zwnj;{discountInfo.ValidToFormatted}&zwnj;"); 100 } 101 } 102 string discountType = Model.Item.GetRawValueString("Custom_DiscountType", "none"); 103 string discountTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Custom_DiscountTheme")) ? "theme " + Model.Item.GetRawValueString("Custom_DiscountTheme").Replace(" ", "").Trim().ToLower() : string.Empty; 104 string discountIconColor = Model.Item.GetString("Custom_DiscountIconColor", "text-inherit"); 105 string discountIconSize = Model.Item.GetRawValueString("Custom_DiscountIconSize", "2"); 106 string discountImageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) ? Model.Item.GetFile("Custom_DiscountImage").Path : string.Empty; 107 string discountImagePath = discountImageSrc != string.Empty ? discountImageSrc : Model.Item.GetRawValueString("Custom_DiscountIcon", string.Empty); 108 discountImagePath = Path.GetExtension(discountImagePath).ToLower() != ".svg" ? "/Admin/Public/GetImage.ashx?image=" + discountImagePath + "&height=" + discountIconSize + "&width=" + discountIconSize + "&Crop=0&format=webp" : discountImagePath; 109 string discountImgAltText = Model.Item.GetRawValueString("FeatureAltText", string.Empty); 110 //--CUSTOM 111 112 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 113 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 114 115 string priceMin = ""; 116 string priceMax = ""; 117 118 string liveInfoClass = ""; 119 string productInfoFeed = ""; 120 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 121 if (isLazyLoadingForProductInfoEnabled) 122 { 123 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 124 { 125 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 126 if (!string.IsNullOrEmpty(productInfoFeed)) 127 { 128 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 129 } 130 } 131 liveInfoClass = "js-live-info"; 132 } 133 134 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 135 @if (showInformativePrice && product.PriceInformative.Price != 0) 136 { 137 <div class="opacity-50"> 138 <span>@Translate("RRP") </span> 139 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 140 </div> 141 } 142 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 143 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 144 145 @*//CUSTOM*@ 146 @if (showPricesWithVat == "false" && !neverShowVat) 147 { 148 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 149 { 150 <span class="text-price js-text-price"> 151 <span class="spinner-border" role="status"></span> 152 </span> 153 } 154 else 155 { 156 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 157 158 if (product?.VariantInfo?.VariantInfo != null) 159 { 160 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 161 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 162 } 163 if (priceMin != priceMax) 164 { 165 price = priceMin + " - " + priceMax; 166 } 167 168 <span class="@theme"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 195 <span class="@theme"> 196 <span class="text-price">@price</span> 197 </span> 198 } 199 } 200 201 @if (showPricesWithVat == "false" && !neverShowVat) 202 { 203 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 204 { 205 <span itemprop="price" content="" class="d-none"></span> 206 <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> 207 } 208 else 209 { 210 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 211 212 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 213 214 if (product.Price.Price != product.PriceBeforeDiscount.Price) 215 { 216 <span class="opacity-75 @(order)"> 217 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 218 </span> 219 220 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 221 { 222 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 223 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 224 { 225 PriceWithoutVAT = (product.PriceBeforeDiscount.PriceWithoutVat - product.Price.PriceWithoutVat) 226 }; 227 228 <span class="d-none d-sm-inline opacity-75 @(order)"> 229 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceWithoutVATFormatted)</span> 230 </span> 231 } 232 } 233 } 234 } 235 else 236 { 237 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 238 { 239 <span itemprop="price" content="" class="d-none"></span> 240 <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> 241 } 242 else 243 { 244 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 245 246 <span itemprop="price" content="@product.Price.Price.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 247 248 if (product.Price.Price < product.PriceBeforeDiscount.Price) 249 { 250 <span class="opacity-75 @(order)"> 251 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 252 </span> 253 254 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 255 { 256 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 257 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 258 { 259 PriceWithVAT = (product.PriceBeforeDiscount.Price - product.Price.Price) 260 }; 261 262 <span class="d-none d-sm-inline opacity-75 @(order)"> 263 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceFormatted)</span> 264 </span> 265 } 266 } 267 } 268 } 269 @*//--CUSTOM*@ 270 271 @*//CUSTOM*@ 272 @if (discountType == "icon-tooltip" && product.Price.Price != product.PriceBeforeDiscount.Price && discountText != null) 273 { 274 if ((!string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) || !discountImagePath.ToLower().Contains("none")) && discountImagePath != string.Empty) 275 { 276 <span data-bs-toggle="tooltip" data-bs-custom-class="@(discountTheme)" data-bs-html="true" data-bs-title="@HtmlEncoder.HtmlAttributeEncode(discountText)" data-bs-custom-prevent-event="click" data-bs-custom-click-close-delay="2000"> 277 @if (Path.GetExtension(discountImagePath).ToLower() == ".svg") 278 { 279 <span class="icon-auto @(discountIconColor)" style="vertical-align:text-top;height:@(discountIconSize)px;width:@(discountIconSize)px;">@ReadFile(discountImagePath)</span> 280 } 281 else 282 { 283 <img loading="lazy" src="@(discountImagePath)" alt="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" title="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" style="height:@(discountIconSize)px;width:@(discountIconSize)px;"> 284 } 285 </span> 286 } 287 } 288 @*//--CUSTOM*@ 289 290 @* Stock state for Schema.org, start *@ 291 @{ 292 Uri url = Dynamicweb.Context.Current.Request.Url; 293 } 294 295 <link itemprop="url" href="@url"> 296 297 @{ 298 bool IsNeverOutOfStock = product.NeverOutOfstock; 299 } 300 301 @if (IsNeverOutOfStock) 302 { 303 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 304 } 305 else 306 { 307 if (product.StockLevel > 0) 308 { 309 <span itemprop="availability" class="d-none">InStock</span> 310 } 311 else 312 { 313 <span itemprop="availability" class="d-none">OutOfStock</span> 314 } 315 } 316 @* Stock state for Schema.org, stop *@ 317 318 </div> 319 320 @if (showPricesWithVat == "false" && !neverShowVat) 321 { 322 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 323 { 324 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 325 } 326 else 327 { 328 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 329 330 if (product?.VariantInfo?.VariantInfo != null) 331 { 332 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 333 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 334 } 335 if (priceMin != priceMax) 336 { 337 price = priceMin + " - " + priceMax; 338 } 339 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 340 } 341 } 342 343 @*//CUSTOM*@ 344 @if (discountType == "inline" && product.Price.Price != product.PriceBeforeDiscount.Price && !string.IsNullOrEmpty(discountText)) 345 { 346 var discountFontSize = priceFontSize.Contains("h6") ? priceFontSize.Replace("h6", "small") : "small"; 347 348 <div class="@(discountFontSize) mt-1 d-flex flex-wrap @(flexDirection) @(horizontalAlign)"> 349 @discountText 350 </div> 351 } 352 @*//--CUSTOM*@ 353 354 </div> 355 } 356 else if (Pageview.IsVisualEditorMode) 357 { 358 <div class="alert alert-dark m-0" role="alert"> 359 <span>@Translate("No products available")</span> 360 </div> 361 } 362
Error executing template "Designs/Swift/Paragraph/Swift_ProductBadges_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_fe4e63c166214874a0bcb86da4f14f88.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBadges_Custom.cshtml:line 27
   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 System 3 @using System.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Content 7 @using Dynamicweb.Core 8 @using Dynamicweb.Ecommerce.ProductCatalog 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 28 DateTime currentDate = DateTime.Today; 29 bool showComingSoonBadge = currentDate < launchDate && string.Equals( Model.Item.GetRawValueString("NewBadgeDesign"), "comingsoon", StringComparison.InvariantCultureIgnoreCase ); 30 } 31 32 @if (product is object) 33 { 34 var badgeParms = new Dictionary<string, object>(); 35 badgeParms.Add("size", "h7"); 36 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 37 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 38 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 39 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 40 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 41 42 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 46 47 Dictionary<string, ParagraphInfoViewModel> badgeConfigurations; 48 List<string> campaignBadgesValues = Model.Item.GetRawValueString("CampaignBadges") != null ? Model.Item.GetRawValueString("CampaignBadges").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>(); 49 50 if (Dynamicweb.Context.Current.Items.Contains("badgeConfigurations")) 51 { 52 badgeConfigurations = (Dictionary<string, ParagraphInfoViewModel>)Dynamicweb.Context.Current.Items["badgeConfigurations"]; 53 } 54 else 55 { 56 var badgesPage = Pageview.AreaSettings.GetLink("EcommerceBadgesPage") != null ? Pageview.AreaSettings.GetLink("EcommerceBadgesPage").PageId : 0; 57 var allBadges = badgesPage != 0 ? Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(badgesPage) : null; 58 59 badgeConfigurations = new Dictionary<string, ParagraphInfoViewModel>(); 60 61 if ( allBadges != null ) 62 { 63 foreach ( Paragraph badge in allBadges ) 64 { 65 var paragraphviewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel( badge ); 66 string cssClassName = paragraphviewModel.Item.GetString( "CssClassName" )?.Trim().ToLower() ?? string.Empty;; 67 if ( !badgeConfigurations.ContainsKey( cssClassName ) ) 68 { 69 badgeConfigurations.Add( cssClassName, paragraphviewModel ); 70 } 71 } 72 } 73 74 Dynamicweb.Context.Current.Items.Add("badgeConfigurations", badgeConfigurations); 75 } 76 77 int badgesCount = 0; 78 if (badgeConfigurations.Any()) 79 { 80 foreach (string campaign in campaignBadgesValues) 81 { 82 if (!string.IsNullOrEmpty(campaign)) 83 { 84 FieldValueViewModel availableCampaignsObject; 85 product.ProductFields.TryGetValue("Campaign", out availableCampaignsObject); 86 87 if (availableCampaignsObject != null) 88 { 89 string campaignType = string.Empty; 90 91 if (badgeConfigurations.ContainsKey(campaign)) 92 { 93 ParagraphInfoViewModel paragraphviewModel; 94 if (badgeConfigurations.TryGetValue(campaign, out paragraphviewModel)) 95 { 96 campaignType = paragraphviewModel.Item.GetRawValueString("CampaignType"); 97 } 98 } 99 100 List<FieldOptionValueViewModel> availableCampaigns = (List<FieldOptionValueViewModel>)availableCampaignsObject.Value; 101 102 foreach (FieldOptionValueViewModel availableOption in availableCampaigns) 103 { 104 if (campaignType == availableOption.Value) 105 { 106 badgesCount++; 107 break; 108 } 109 } 110 } 111 } 112 } 113 } 114 115 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 116 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 117 DateTime createdDate = product.Created.Value; 118 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 119 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 120 showBadges = (!string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) && badgesCount != 0) || showComingSoonBadge || showBadges; 121 122 if (showBadges) 123 { 124 <div class="@badgeSize @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 125 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 126 </div> 127 } 128 else if (Pageview.IsVisualEditorMode) 129 { 130 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 131 } 132 } 133 else if (Pageview.IsVisualEditorMode) 134 { 135 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 136 } 137 138
Liquid Lounge Cocktail shaker
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_160448cdee3c46a18a7a094dcad8bbe9.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage_Custom.cshtml:line 32
   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 System @*//CUSTOM*@ 3 @using System.Collections.Generic @*//CUSTOM*@ 4 @using System.Linq @*//CUSTOM*@ 5 @using Dynamicweb.Core @*//CUSTOM*@ 6 @using Dynamicweb.Ecommerce.ProductCatalog 7 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 10 11 @{ 12 ProductViewModel product = null; 13 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 14 { 15 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 16 } 17 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 18 { 19 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 20 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 21 22 if (productList?.Products is object) 23 { 24 product = productList.Products[0]; 25 } 26 } 27 } 28 29 @if (product is object) 30 { 31 //CUSTOM 32 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 33 DateTime currentDate = DateTime.Today; 34 bool showComingSoonBadge = currentDate < launchDate; 35 string brandLogo = Model.Item.GetString("Custom_BrandLogo"); 36 string brandLogoKey = Model.Item.GetString("Custom_BrandLogoKey"); 37 string brandLogoAltText = Model.Item.GetString("Custom_BrandAltText"); 38 int brandLogoWidth = Model.Item.GetInt32("Custom_BrandLogoWidth") > 0 ? Model.Item.GetInt32("Custom_BrandLogoWidth") : 70; 39 string productBrand = product.ProductFields.ContainsKey("Custom_Brand") ? Converter.ToString(product.ProductFields["Custom_Brand"].Value) : ""; 40 bool enableBrandLogo = !string.IsNullOrEmpty(brandLogo) && !string.IsNullOrEmpty(brandLogoKey) && brandLogoKey == productBrand; 41 //--CUSTOM 42 43 string imagePath = product?.DefaultImage?.Value ?? ""; 44 string imagePathUrlEncoded = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 45 46 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 47 ratio = ratio != "0" ? ratio : ""; 48 string ratioCssClass = ratio != "" ? " ratio" : ""; 49 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 50 51 string width = Model.Item.GetRawValueString("Width", "auto"); 52 int smallImageSize = 640; 53 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 54 55 string ImageObjectFit = Model.Item.GetRawValueString("ImageObjectFit", "contain"); 56 57 string imagePathXs = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 58 string imagePathS = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 59 string imagePathFallBack = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 60 61 var badgeParms = new Dictionary<string, object>(); 62 badgeParms.Add("size", "h7"); 63 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 64 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 65 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 66 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 67 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 68 69 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 70 71 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 72 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 73 bool anonymousUser = Pageview.User == null; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 if (!anonymousUser && showFavoritesSelector) 77 { 78 int defaultFavoriteListId = 0; 79 80 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 81 if (favoreiteLists.Count() == 1) 82 { 83 foreach (FavoriteList list in favoreiteLists) 84 { 85 defaultFavoriteListId = list.ListId; 86 } 87 } 88 89 favoriteParameters.Add("ListId", defaultFavoriteListId); 90 } 91 92 MediaViewModel alternativeImage = new MediaViewModel(); 93 if (Model.Item.GetBoolean("ShowAlternativeImageOnHover")) 94 { 95 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 96 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 97 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 98 alternativeImage = allAssetsImages.FirstOrDefault(); 99 } 100 101 string altImagePathXs = string.Empty; 102 string altImagePathS = string.Empty; 103 104 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 105 { 106 altImagePathXs = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 107 altImagePathS = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 108 } 109 110 @* Theme settings *@ 111 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 112 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 113 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 114 115 string imageId = "ProductImage_" + product.Id + product.VariantId.Replace(".", "_"); 116 117 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 118 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 119 DateTime createdDate = product.Created.Value; 120 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 121 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 122 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) || showComingSoonBadge || showBadges; //CUSTOM 123 124 string fullWidth = width == "auto" ? "w-100" : ""; 125 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 126 127 @* -- CUSTOM -- Added image item prop *@ 128 if (!string.IsNullOrEmpty(imagePath)) 129 { 130 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 131 <div class="ratio" style="@(ratioVariable)"> 132 <div class="d-flex justify-content-center align-items-center"> 133 @* CUSTOM *@ 134 @if (enableBrandLogo) 135 { 136 <img src="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogo)" 137 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoAltText)" 138 class="productdefault-brand-logo" 139 width="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoWidth.ToString())" /> 140 } 141 @* CUSTOM END *@ 142 @if (imagePath.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 143 { 144 <img id="@imageId" 145 itemprop="image" 146 srcset=" 147 @imagePathXs @(smallImageSize)w, 148 @imagePathS @(largeImageSize)w" 149 sizes="(max-width: 992px) 50vw, 25vw" 150 src="@imagePathFallBack" 151 @if (Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 152 data-alternative-image=" 153 @altImagePathXs @(smallImageSize)w, 154 @altImagePathS @(largeImageSize)w" 155 onmouseover="swift.Image.swapImage(event)" 156 onmouseout="swift.Image.swapImage(event)" 157 </text> } 158 loading="lazy" 159 decoding="async" 160 class="h-100 w-100 @themePadding" 161 style="object-fit: @ImageObjectFit; @themeBorder" 162 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 163 } 164 //CUSTOM 165 else if (imagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) 166 { 167 <img id="@imageId" 168 itemprop="image" 169 srcset=" 170 @imagePathXs @(smallImageSize)w, 171 @imagePathS @(largeImageSize)w" 172 sizes="(max-width: 992px) 50vw, 25vw" 173 src="@imagePathFallBack" 174 data-alternative-image=" 175 @altImagePathXs @(smallImageSize)w, 176 @altImagePathS @(largeImageSize)w" 177 onmouseover="swift.Image.swapImage(event)" 178 onmouseout="swift.Image.swapImage(event)" 179 loading="lazy" 180 decoding="async" 181 class="h-100 w-100 @themePadding" 182 style="object-fit: @ImageObjectFit; @themeBorder" 183 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 184 } 185 //--CUSTOM 186 else 187 { 188 <img itemprop="image" 189 src="@product.DefaultImage.Value" 190 loading="lazy" 191 class="h-100 w-100 @themePadding" 192 style="object-fit: contain; @themeBorder" 193 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 194 } 195 </div> 196 </div> 197 198 @if (showBadges) 199 { 200 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 201 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 202 </div> 203 } 204 205 @if (!anonymousUser) 206 { 207 if (showFavoritesSelector) 208 { 209 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 210 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 211 </div> 212 } 213 } 214 </div> 215 } 216 } 217 else if (Pageview.IsVisualEditorMode) 218 { 219 <div class="alert alert-dark m-0">@Translate("No products available")</div> 220 } 221

Liquid Lounge Cocktail shaker

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fb0d18a1de944f3a468232b7643f0eb.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 65
   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.Configuration @*//CUSTOM*@ 3 @using Dynamicweb.Core.Encoders @*//CUSTOM*@ 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 @using System.Globalization 6 @using System.IO @*//CUSTOM*@ 7 8 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 bool productIsDiscontinued = product is object && product.Discontinued; 33 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 34 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 35 } 36 37 @if (product is object && !hidePrice && !isDiscontinued) 38 { 39 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 40 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 41 42 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "h6 justify-content-lg-start"); //CUSTOM 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 45 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 46 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 47 48 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 50 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 51 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 52 53 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 54 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 55 string order = layout == "horizontal" ? string.Empty : "order-2"; 56 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 57 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 61 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 62 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 63 64 //CUSTOM 65 Dictionary<string, FieldValueViewModel> productFields = product.ProductFields; 66 var discountText = ""; 67 bool discountDiscontinued = false; 68 bool discountOnSale = false; 69 70 if (productFields.TryGetValue("Custom_Discontinued", out FieldValueViewModel discontinued)) 71 { 72 var firstValue = (discontinued.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 73 74 if (!string.IsNullOrWhiteSpace(firstValue)) 75 { 76 bool.TryParse(firstValue, out discountDiscontinued); 77 } 78 } 79 80 if (productFields.TryGetValue("Custom_OnSale", out FieldValueViewModel onsale)) 81 { 82 var firstValue = (onsale.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 83 84 if (!string.IsNullOrWhiteSpace(firstValue)) 85 { 86 bool.TryParse(firstValue, out discountOnSale); 87 } 88 } 89 90 if (discountDiscontinued && discountOnSale) 91 { 92 discountText = Translate("Outlet - tilbuddet gælder så længe lager haves"); 93 } 94 else 95 { 96 var discountInfo = Smartpage.EvaSolo.CampaignPrices.Helpers.DiscountHelper.GetDiscountInfo(product); 97 if (discountInfo != null) 98 { 99 discountText = string.Format(Translate(Model.Item.GetRawValueString("Custom_DiscountText", "Tilbuddet gælder {0} - {1}")), $"&zwnj;{discountInfo.ValidFromFormatted}&zwnj;", $"&zwnj;{discountInfo.ValidToFormatted}&zwnj;"); 100 } 101 } 102 string discountType = Model.Item.GetRawValueString("Custom_DiscountType", "none"); 103 string discountTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Custom_DiscountTheme")) ? "theme " + Model.Item.GetRawValueString("Custom_DiscountTheme").Replace(" ", "").Trim().ToLower() : string.Empty; 104 string discountIconColor = Model.Item.GetString("Custom_DiscountIconColor", "text-inherit"); 105 string discountIconSize = Model.Item.GetRawValueString("Custom_DiscountIconSize", "2"); 106 string discountImageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) ? Model.Item.GetFile("Custom_DiscountImage").Path : string.Empty; 107 string discountImagePath = discountImageSrc != string.Empty ? discountImageSrc : Model.Item.GetRawValueString("Custom_DiscountIcon", string.Empty); 108 discountImagePath = Path.GetExtension(discountImagePath).ToLower() != ".svg" ? "/Admin/Public/GetImage.ashx?image=" + discountImagePath + "&height=" + discountIconSize + "&width=" + discountIconSize + "&Crop=0&format=webp" : discountImagePath; 109 string discountImgAltText = Model.Item.GetRawValueString("FeatureAltText", string.Empty); 110 //--CUSTOM 111 112 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 113 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 114 115 string priceMin = ""; 116 string priceMax = ""; 117 118 string liveInfoClass = ""; 119 string productInfoFeed = ""; 120 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 121 if (isLazyLoadingForProductInfoEnabled) 122 { 123 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 124 { 125 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 126 if (!string.IsNullOrEmpty(productInfoFeed)) 127 { 128 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 129 } 130 } 131 liveInfoClass = "js-live-info"; 132 } 133 134 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 135 @if (showInformativePrice && product.PriceInformative.Price != 0) 136 { 137 <div class="opacity-50"> 138 <span>@Translate("RRP") </span> 139 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 140 </div> 141 } 142 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 143 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 144 145 @*//CUSTOM*@ 146 @if (showPricesWithVat == "false" && !neverShowVat) 147 { 148 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 149 { 150 <span class="text-price js-text-price"> 151 <span class="spinner-border" role="status"></span> 152 </span> 153 } 154 else 155 { 156 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 157 158 if (product?.VariantInfo?.VariantInfo != null) 159 { 160 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 161 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 162 } 163 if (priceMin != priceMax) 164 { 165 price = priceMin + " - " + priceMax; 166 } 167 168 <span class="@theme"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 195 <span class="@theme"> 196 <span class="text-price">@price</span> 197 </span> 198 } 199 } 200 201 @if (showPricesWithVat == "false" && !neverShowVat) 202 { 203 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 204 { 205 <span itemprop="price" content="" class="d-none"></span> 206 <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> 207 } 208 else 209 { 210 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 211 212 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 213 214 if (product.Price.Price != product.PriceBeforeDiscount.Price) 215 { 216 <span class="opacity-75 @(order)"> 217 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 218 </span> 219 220 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 221 { 222 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 223 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 224 { 225 PriceWithoutVAT = (product.PriceBeforeDiscount.PriceWithoutVat - product.Price.PriceWithoutVat) 226 }; 227 228 <span class="d-none d-sm-inline opacity-75 @(order)"> 229 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceWithoutVATFormatted)</span> 230 </span> 231 } 232 } 233 } 234 } 235 else 236 { 237 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 238 { 239 <span itemprop="price" content="" class="d-none"></span> 240 <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> 241 } 242 else 243 { 244 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 245 246 <span itemprop="price" content="@product.Price.Price.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 247 248 if (product.Price.Price < product.PriceBeforeDiscount.Price) 249 { 250 <span class="opacity-75 @(order)"> 251 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 252 </span> 253 254 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 255 { 256 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 257 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 258 { 259 PriceWithVAT = (product.PriceBeforeDiscount.Price - product.Price.Price) 260 }; 261 262 <span class="d-none d-sm-inline opacity-75 @(order)"> 263 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceFormatted)</span> 264 </span> 265 } 266 } 267 } 268 } 269 @*//--CUSTOM*@ 270 271 @*//CUSTOM*@ 272 @if (discountType == "icon-tooltip" && product.Price.Price != product.PriceBeforeDiscount.Price && discountText != null) 273 { 274 if ((!string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) || !discountImagePath.ToLower().Contains("none")) && discountImagePath != string.Empty) 275 { 276 <span data-bs-toggle="tooltip" data-bs-custom-class="@(discountTheme)" data-bs-html="true" data-bs-title="@HtmlEncoder.HtmlAttributeEncode(discountText)" data-bs-custom-prevent-event="click" data-bs-custom-click-close-delay="2000"> 277 @if (Path.GetExtension(discountImagePath).ToLower() == ".svg") 278 { 279 <span class="icon-auto @(discountIconColor)" style="vertical-align:text-top;height:@(discountIconSize)px;width:@(discountIconSize)px;">@ReadFile(discountImagePath)</span> 280 } 281 else 282 { 283 <img loading="lazy" src="@(discountImagePath)" alt="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" title="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" style="height:@(discountIconSize)px;width:@(discountIconSize)px;"> 284 } 285 </span> 286 } 287 } 288 @*//--CUSTOM*@ 289 290 @* Stock state for Schema.org, start *@ 291 @{ 292 Uri url = Dynamicweb.Context.Current.Request.Url; 293 } 294 295 <link itemprop="url" href="@url"> 296 297 @{ 298 bool IsNeverOutOfStock = product.NeverOutOfstock; 299 } 300 301 @if (IsNeverOutOfStock) 302 { 303 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 304 } 305 else 306 { 307 if (product.StockLevel > 0) 308 { 309 <span itemprop="availability" class="d-none">InStock</span> 310 } 311 else 312 { 313 <span itemprop="availability" class="d-none">OutOfStock</span> 314 } 315 } 316 @* Stock state for Schema.org, stop *@ 317 318 </div> 319 320 @if (showPricesWithVat == "false" && !neverShowVat) 321 { 322 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 323 { 324 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 325 } 326 else 327 { 328 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 329 330 if (product?.VariantInfo?.VariantInfo != null) 331 { 332 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 333 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 334 } 335 if (priceMin != priceMax) 336 { 337 price = priceMin + " - " + priceMax; 338 } 339 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 340 } 341 } 342 343 @*//CUSTOM*@ 344 @if (discountType == "inline" && product.Price.Price != product.PriceBeforeDiscount.Price && !string.IsNullOrEmpty(discountText)) 345 { 346 var discountFontSize = priceFontSize.Contains("h6") ? priceFontSize.Replace("h6", "small") : "small"; 347 348 <div class="@(discountFontSize) mt-1 d-flex flex-wrap @(flexDirection) @(horizontalAlign)"> 349 @discountText 350 </div> 351 } 352 @*//--CUSTOM*@ 353 354 </div> 355 } 356 else if (Pageview.IsVisualEditorMode) 357 { 358 <div class="alert alert-dark m-0" role="alert"> 359 <span>@Translate("No products available")</span> 360 </div> 361 } 362
Error executing template "Designs/Swift/Paragraph/Swift_ProductBadges_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_fe4e63c166214874a0bcb86da4f14f88.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBadges_Custom.cshtml:line 27
   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 System 3 @using System.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Content 7 @using Dynamicweb.Core 8 @using Dynamicweb.Ecommerce.ProductCatalog 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 28 DateTime currentDate = DateTime.Today; 29 bool showComingSoonBadge = currentDate < launchDate && string.Equals( Model.Item.GetRawValueString("NewBadgeDesign"), "comingsoon", StringComparison.InvariantCultureIgnoreCase ); 30 } 31 32 @if (product is object) 33 { 34 var badgeParms = new Dictionary<string, object>(); 35 badgeParms.Add("size", "h7"); 36 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 37 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 38 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 39 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 40 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 41 42 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 46 47 Dictionary<string, ParagraphInfoViewModel> badgeConfigurations; 48 List<string> campaignBadgesValues = Model.Item.GetRawValueString("CampaignBadges") != null ? Model.Item.GetRawValueString("CampaignBadges").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>(); 49 50 if (Dynamicweb.Context.Current.Items.Contains("badgeConfigurations")) 51 { 52 badgeConfigurations = (Dictionary<string, ParagraphInfoViewModel>)Dynamicweb.Context.Current.Items["badgeConfigurations"]; 53 } 54 else 55 { 56 var badgesPage = Pageview.AreaSettings.GetLink("EcommerceBadgesPage") != null ? Pageview.AreaSettings.GetLink("EcommerceBadgesPage").PageId : 0; 57 var allBadges = badgesPage != 0 ? Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(badgesPage) : null; 58 59 badgeConfigurations = new Dictionary<string, ParagraphInfoViewModel>(); 60 61 if ( allBadges != null ) 62 { 63 foreach ( Paragraph badge in allBadges ) 64 { 65 var paragraphviewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel( badge ); 66 string cssClassName = paragraphviewModel.Item.GetString( "CssClassName" )?.Trim().ToLower() ?? string.Empty;; 67 if ( !badgeConfigurations.ContainsKey( cssClassName ) ) 68 { 69 badgeConfigurations.Add( cssClassName, paragraphviewModel ); 70 } 71 } 72 } 73 74 Dynamicweb.Context.Current.Items.Add("badgeConfigurations", badgeConfigurations); 75 } 76 77 int badgesCount = 0; 78 if (badgeConfigurations.Any()) 79 { 80 foreach (string campaign in campaignBadgesValues) 81 { 82 if (!string.IsNullOrEmpty(campaign)) 83 { 84 FieldValueViewModel availableCampaignsObject; 85 product.ProductFields.TryGetValue("Campaign", out availableCampaignsObject); 86 87 if (availableCampaignsObject != null) 88 { 89 string campaignType = string.Empty; 90 91 if (badgeConfigurations.ContainsKey(campaign)) 92 { 93 ParagraphInfoViewModel paragraphviewModel; 94 if (badgeConfigurations.TryGetValue(campaign, out paragraphviewModel)) 95 { 96 campaignType = paragraphviewModel.Item.GetRawValueString("CampaignType"); 97 } 98 } 99 100 List<FieldOptionValueViewModel> availableCampaigns = (List<FieldOptionValueViewModel>)availableCampaignsObject.Value; 101 102 foreach (FieldOptionValueViewModel availableOption in availableCampaigns) 103 { 104 if (campaignType == availableOption.Value) 105 { 106 badgesCount++; 107 break; 108 } 109 } 110 } 111 } 112 } 113 } 114 115 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 116 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 117 DateTime createdDate = product.Created.Value; 118 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 119 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 120 showBadges = (!string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) && badgesCount != 0) || showComingSoonBadge || showBadges; 121 122 if (showBadges) 123 { 124 <div class="@badgeSize @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 125 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 126 </div> 127 } 128 else if (Pageview.IsVisualEditorMode) 129 { 130 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 131 } 132 } 133 else if (Pageview.IsVisualEditorMode) 134 { 135 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 136 } 137 138
Liquid Lounge Cocktail målebæger
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_160448cdee3c46a18a7a094dcad8bbe9.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage_Custom.cshtml:line 32
   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 System @*//CUSTOM*@ 3 @using System.Collections.Generic @*//CUSTOM*@ 4 @using System.Linq @*//CUSTOM*@ 5 @using Dynamicweb.Core @*//CUSTOM*@ 6 @using Dynamicweb.Ecommerce.ProductCatalog 7 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 10 11 @{ 12 ProductViewModel product = null; 13 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 14 { 15 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 16 } 17 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 18 { 19 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 20 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 21 22 if (productList?.Products is object) 23 { 24 product = productList.Products[0]; 25 } 26 } 27 } 28 29 @if (product is object) 30 { 31 //CUSTOM 32 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 33 DateTime currentDate = DateTime.Today; 34 bool showComingSoonBadge = currentDate < launchDate; 35 string brandLogo = Model.Item.GetString("Custom_BrandLogo"); 36 string brandLogoKey = Model.Item.GetString("Custom_BrandLogoKey"); 37 string brandLogoAltText = Model.Item.GetString("Custom_BrandAltText"); 38 int brandLogoWidth = Model.Item.GetInt32("Custom_BrandLogoWidth") > 0 ? Model.Item.GetInt32("Custom_BrandLogoWidth") : 70; 39 string productBrand = product.ProductFields.ContainsKey("Custom_Brand") ? Converter.ToString(product.ProductFields["Custom_Brand"].Value) : ""; 40 bool enableBrandLogo = !string.IsNullOrEmpty(brandLogo) && !string.IsNullOrEmpty(brandLogoKey) && brandLogoKey == productBrand; 41 //--CUSTOM 42 43 string imagePath = product?.DefaultImage?.Value ?? ""; 44 string imagePathUrlEncoded = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 45 46 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 47 ratio = ratio != "0" ? ratio : ""; 48 string ratioCssClass = ratio != "" ? " ratio" : ""; 49 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 50 51 string width = Model.Item.GetRawValueString("Width", "auto"); 52 int smallImageSize = 640; 53 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 54 55 string ImageObjectFit = Model.Item.GetRawValueString("ImageObjectFit", "contain"); 56 57 string imagePathXs = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 58 string imagePathS = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 59 string imagePathFallBack = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 60 61 var badgeParms = new Dictionary<string, object>(); 62 badgeParms.Add("size", "h7"); 63 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 64 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 65 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 66 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 67 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 68 69 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 70 71 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 72 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 73 bool anonymousUser = Pageview.User == null; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 if (!anonymousUser && showFavoritesSelector) 77 { 78 int defaultFavoriteListId = 0; 79 80 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 81 if (favoreiteLists.Count() == 1) 82 { 83 foreach (FavoriteList list in favoreiteLists) 84 { 85 defaultFavoriteListId = list.ListId; 86 } 87 } 88 89 favoriteParameters.Add("ListId", defaultFavoriteListId); 90 } 91 92 MediaViewModel alternativeImage = new MediaViewModel(); 93 if (Model.Item.GetBoolean("ShowAlternativeImageOnHover")) 94 { 95 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 96 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 97 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 98 alternativeImage = allAssetsImages.FirstOrDefault(); 99 } 100 101 string altImagePathXs = string.Empty; 102 string altImagePathS = string.Empty; 103 104 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 105 { 106 altImagePathXs = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 107 altImagePathS = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 108 } 109 110 @* Theme settings *@ 111 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 112 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 113 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 114 115 string imageId = "ProductImage_" + product.Id + product.VariantId.Replace(".", "_"); 116 117 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 118 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 119 DateTime createdDate = product.Created.Value; 120 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 121 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 122 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) || showComingSoonBadge || showBadges; //CUSTOM 123 124 string fullWidth = width == "auto" ? "w-100" : ""; 125 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 126 127 @* -- CUSTOM -- Added image item prop *@ 128 if (!string.IsNullOrEmpty(imagePath)) 129 { 130 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 131 <div class="ratio" style="@(ratioVariable)"> 132 <div class="d-flex justify-content-center align-items-center"> 133 @* CUSTOM *@ 134 @if (enableBrandLogo) 135 { 136 <img src="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogo)" 137 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoAltText)" 138 class="productdefault-brand-logo" 139 width="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoWidth.ToString())" /> 140 } 141 @* CUSTOM END *@ 142 @if (imagePath.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 143 { 144 <img id="@imageId" 145 itemprop="image" 146 srcset=" 147 @imagePathXs @(smallImageSize)w, 148 @imagePathS @(largeImageSize)w" 149 sizes="(max-width: 992px) 50vw, 25vw" 150 src="@imagePathFallBack" 151 @if (Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 152 data-alternative-image=" 153 @altImagePathXs @(smallImageSize)w, 154 @altImagePathS @(largeImageSize)w" 155 onmouseover="swift.Image.swapImage(event)" 156 onmouseout="swift.Image.swapImage(event)" 157 </text> } 158 loading="lazy" 159 decoding="async" 160 class="h-100 w-100 @themePadding" 161 style="object-fit: @ImageObjectFit; @themeBorder" 162 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 163 } 164 //CUSTOM 165 else if (imagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) 166 { 167 <img id="@imageId" 168 itemprop="image" 169 srcset=" 170 @imagePathXs @(smallImageSize)w, 171 @imagePathS @(largeImageSize)w" 172 sizes="(max-width: 992px) 50vw, 25vw" 173 src="@imagePathFallBack" 174 data-alternative-image=" 175 @altImagePathXs @(smallImageSize)w, 176 @altImagePathS @(largeImageSize)w" 177 onmouseover="swift.Image.swapImage(event)" 178 onmouseout="swift.Image.swapImage(event)" 179 loading="lazy" 180 decoding="async" 181 class="h-100 w-100 @themePadding" 182 style="object-fit: @ImageObjectFit; @themeBorder" 183 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 184 } 185 //--CUSTOM 186 else 187 { 188 <img itemprop="image" 189 src="@product.DefaultImage.Value" 190 loading="lazy" 191 class="h-100 w-100 @themePadding" 192 style="object-fit: contain; @themeBorder" 193 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 194 } 195 </div> 196 </div> 197 198 @if (showBadges) 199 { 200 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 201 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 202 </div> 203 } 204 205 @if (!anonymousUser) 206 { 207 if (showFavoritesSelector) 208 { 209 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 210 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 211 </div> 212 } 213 } 214 </div> 215 } 216 } 217 else if (Pageview.IsVisualEditorMode) 218 { 219 <div class="alert alert-dark m-0">@Translate("No products available")</div> 220 } 221

Liquid Lounge Cocktail målebæger

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fb0d18a1de944f3a468232b7643f0eb.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 65
   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.Configuration @*//CUSTOM*@ 3 @using Dynamicweb.Core.Encoders @*//CUSTOM*@ 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 @using System.Globalization 6 @using System.IO @*//CUSTOM*@ 7 8 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 bool productIsDiscontinued = product is object && product.Discontinued; 33 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 34 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 35 } 36 37 @if (product is object && !hidePrice && !isDiscontinued) 38 { 39 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 40 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 41 42 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "h6 justify-content-lg-start"); //CUSTOM 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 45 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 46 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 47 48 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 50 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 51 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 52 53 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 54 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 55 string order = layout == "horizontal" ? string.Empty : "order-2"; 56 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 57 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 61 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 62 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 63 64 //CUSTOM 65 Dictionary<string, FieldValueViewModel> productFields = product.ProductFields; 66 var discountText = ""; 67 bool discountDiscontinued = false; 68 bool discountOnSale = false; 69 70 if (productFields.TryGetValue("Custom_Discontinued", out FieldValueViewModel discontinued)) 71 { 72 var firstValue = (discontinued.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 73 74 if (!string.IsNullOrWhiteSpace(firstValue)) 75 { 76 bool.TryParse(firstValue, out discountDiscontinued); 77 } 78 } 79 80 if (productFields.TryGetValue("Custom_OnSale", out FieldValueViewModel onsale)) 81 { 82 var firstValue = (onsale.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 83 84 if (!string.IsNullOrWhiteSpace(firstValue)) 85 { 86 bool.TryParse(firstValue, out discountOnSale); 87 } 88 } 89 90 if (discountDiscontinued && discountOnSale) 91 { 92 discountText = Translate("Outlet - tilbuddet gælder så længe lager haves"); 93 } 94 else 95 { 96 var discountInfo = Smartpage.EvaSolo.CampaignPrices.Helpers.DiscountHelper.GetDiscountInfo(product); 97 if (discountInfo != null) 98 { 99 discountText = string.Format(Translate(Model.Item.GetRawValueString("Custom_DiscountText", "Tilbuddet gælder {0} - {1}")), $"&zwnj;{discountInfo.ValidFromFormatted}&zwnj;", $"&zwnj;{discountInfo.ValidToFormatted}&zwnj;"); 100 } 101 } 102 string discountType = Model.Item.GetRawValueString("Custom_DiscountType", "none"); 103 string discountTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Custom_DiscountTheme")) ? "theme " + Model.Item.GetRawValueString("Custom_DiscountTheme").Replace(" ", "").Trim().ToLower() : string.Empty; 104 string discountIconColor = Model.Item.GetString("Custom_DiscountIconColor", "text-inherit"); 105 string discountIconSize = Model.Item.GetRawValueString("Custom_DiscountIconSize", "2"); 106 string discountImageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) ? Model.Item.GetFile("Custom_DiscountImage").Path : string.Empty; 107 string discountImagePath = discountImageSrc != string.Empty ? discountImageSrc : Model.Item.GetRawValueString("Custom_DiscountIcon", string.Empty); 108 discountImagePath = Path.GetExtension(discountImagePath).ToLower() != ".svg" ? "/Admin/Public/GetImage.ashx?image=" + discountImagePath + "&height=" + discountIconSize + "&width=" + discountIconSize + "&Crop=0&format=webp" : discountImagePath; 109 string discountImgAltText = Model.Item.GetRawValueString("FeatureAltText", string.Empty); 110 //--CUSTOM 111 112 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 113 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 114 115 string priceMin = ""; 116 string priceMax = ""; 117 118 string liveInfoClass = ""; 119 string productInfoFeed = ""; 120 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 121 if (isLazyLoadingForProductInfoEnabled) 122 { 123 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 124 { 125 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 126 if (!string.IsNullOrEmpty(productInfoFeed)) 127 { 128 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 129 } 130 } 131 liveInfoClass = "js-live-info"; 132 } 133 134 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 135 @if (showInformativePrice && product.PriceInformative.Price != 0) 136 { 137 <div class="opacity-50"> 138 <span>@Translate("RRP") </span> 139 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 140 </div> 141 } 142 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 143 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 144 145 @*//CUSTOM*@ 146 @if (showPricesWithVat == "false" && !neverShowVat) 147 { 148 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 149 { 150 <span class="text-price js-text-price"> 151 <span class="spinner-border" role="status"></span> 152 </span> 153 } 154 else 155 { 156 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 157 158 if (product?.VariantInfo?.VariantInfo != null) 159 { 160 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 161 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 162 } 163 if (priceMin != priceMax) 164 { 165 price = priceMin + " - " + priceMax; 166 } 167 168 <span class="@theme"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 195 <span class="@theme"> 196 <span class="text-price">@price</span> 197 </span> 198 } 199 } 200 201 @if (showPricesWithVat == "false" && !neverShowVat) 202 { 203 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 204 { 205 <span itemprop="price" content="" class="d-none"></span> 206 <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> 207 } 208 else 209 { 210 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 211 212 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 213 214 if (product.Price.Price != product.PriceBeforeDiscount.Price) 215 { 216 <span class="opacity-75 @(order)"> 217 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 218 </span> 219 220 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 221 { 222 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 223 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 224 { 225 PriceWithoutVAT = (product.PriceBeforeDiscount.PriceWithoutVat - product.Price.PriceWithoutVat) 226 }; 227 228 <span class="d-none d-sm-inline opacity-75 @(order)"> 229 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceWithoutVATFormatted)</span> 230 </span> 231 } 232 } 233 } 234 } 235 else 236 { 237 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 238 { 239 <span itemprop="price" content="" class="d-none"></span> 240 <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> 241 } 242 else 243 { 244 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 245 246 <span itemprop="price" content="@product.Price.Price.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 247 248 if (product.Price.Price < product.PriceBeforeDiscount.Price) 249 { 250 <span class="opacity-75 @(order)"> 251 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 252 </span> 253 254 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 255 { 256 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 257 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 258 { 259 PriceWithVAT = (product.PriceBeforeDiscount.Price - product.Price.Price) 260 }; 261 262 <span class="d-none d-sm-inline opacity-75 @(order)"> 263 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceFormatted)</span> 264 </span> 265 } 266 } 267 } 268 } 269 @*//--CUSTOM*@ 270 271 @*//CUSTOM*@ 272 @if (discountType == "icon-tooltip" && product.Price.Price != product.PriceBeforeDiscount.Price && discountText != null) 273 { 274 if ((!string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) || !discountImagePath.ToLower().Contains("none")) && discountImagePath != string.Empty) 275 { 276 <span data-bs-toggle="tooltip" data-bs-custom-class="@(discountTheme)" data-bs-html="true" data-bs-title="@HtmlEncoder.HtmlAttributeEncode(discountText)" data-bs-custom-prevent-event="click" data-bs-custom-click-close-delay="2000"> 277 @if (Path.GetExtension(discountImagePath).ToLower() == ".svg") 278 { 279 <span class="icon-auto @(discountIconColor)" style="vertical-align:text-top;height:@(discountIconSize)px;width:@(discountIconSize)px;">@ReadFile(discountImagePath)</span> 280 } 281 else 282 { 283 <img loading="lazy" src="@(discountImagePath)" alt="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" title="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" style="height:@(discountIconSize)px;width:@(discountIconSize)px;"> 284 } 285 </span> 286 } 287 } 288 @*//--CUSTOM*@ 289 290 @* Stock state for Schema.org, start *@ 291 @{ 292 Uri url = Dynamicweb.Context.Current.Request.Url; 293 } 294 295 <link itemprop="url" href="@url"> 296 297 @{ 298 bool IsNeverOutOfStock = product.NeverOutOfstock; 299 } 300 301 @if (IsNeverOutOfStock) 302 { 303 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 304 } 305 else 306 { 307 if (product.StockLevel > 0) 308 { 309 <span itemprop="availability" class="d-none">InStock</span> 310 } 311 else 312 { 313 <span itemprop="availability" class="d-none">OutOfStock</span> 314 } 315 } 316 @* Stock state for Schema.org, stop *@ 317 318 </div> 319 320 @if (showPricesWithVat == "false" && !neverShowVat) 321 { 322 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 323 { 324 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 325 } 326 else 327 { 328 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 329 330 if (product?.VariantInfo?.VariantInfo != null) 331 { 332 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 333 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 334 } 335 if (priceMin != priceMax) 336 { 337 price = priceMin + " - " + priceMax; 338 } 339 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 340 } 341 } 342 343 @*//CUSTOM*@ 344 @if (discountType == "inline" && product.Price.Price != product.PriceBeforeDiscount.Price && !string.IsNullOrEmpty(discountText)) 345 { 346 var discountFontSize = priceFontSize.Contains("h6") ? priceFontSize.Replace("h6", "small") : "small"; 347 348 <div class="@(discountFontSize) mt-1 d-flex flex-wrap @(flexDirection) @(horizontalAlign)"> 349 @discountText 350 </div> 351 } 352 @*//--CUSTOM*@ 353 354 </div> 355 } 356 else if (Pageview.IsVisualEditorMode) 357 { 358 <div class="alert alert-dark m-0" role="alert"> 359 <span>@Translate("No products available")</span> 360 </div> 361 } 362
Error executing template "Designs/Swift/Paragraph/Swift_ProductBadges_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_fe4e63c166214874a0bcb86da4f14f88.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBadges_Custom.cshtml:line 27
   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 System 3 @using System.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Content 7 @using Dynamicweb.Core 8 @using Dynamicweb.Ecommerce.ProductCatalog 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 28 DateTime currentDate = DateTime.Today; 29 bool showComingSoonBadge = currentDate < launchDate && string.Equals( Model.Item.GetRawValueString("NewBadgeDesign"), "comingsoon", StringComparison.InvariantCultureIgnoreCase ); 30 } 31 32 @if (product is object) 33 { 34 var badgeParms = new Dictionary<string, object>(); 35 badgeParms.Add("size", "h7"); 36 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 37 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 38 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 39 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 40 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 41 42 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 46 47 Dictionary<string, ParagraphInfoViewModel> badgeConfigurations; 48 List<string> campaignBadgesValues = Model.Item.GetRawValueString("CampaignBadges") != null ? Model.Item.GetRawValueString("CampaignBadges").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>(); 49 50 if (Dynamicweb.Context.Current.Items.Contains("badgeConfigurations")) 51 { 52 badgeConfigurations = (Dictionary<string, ParagraphInfoViewModel>)Dynamicweb.Context.Current.Items["badgeConfigurations"]; 53 } 54 else 55 { 56 var badgesPage = Pageview.AreaSettings.GetLink("EcommerceBadgesPage") != null ? Pageview.AreaSettings.GetLink("EcommerceBadgesPage").PageId : 0; 57 var allBadges = badgesPage != 0 ? Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(badgesPage) : null; 58 59 badgeConfigurations = new Dictionary<string, ParagraphInfoViewModel>(); 60 61 if ( allBadges != null ) 62 { 63 foreach ( Paragraph badge in allBadges ) 64 { 65 var paragraphviewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel( badge ); 66 string cssClassName = paragraphviewModel.Item.GetString( "CssClassName" )?.Trim().ToLower() ?? string.Empty;; 67 if ( !badgeConfigurations.ContainsKey( cssClassName ) ) 68 { 69 badgeConfigurations.Add( cssClassName, paragraphviewModel ); 70 } 71 } 72 } 73 74 Dynamicweb.Context.Current.Items.Add("badgeConfigurations", badgeConfigurations); 75 } 76 77 int badgesCount = 0; 78 if (badgeConfigurations.Any()) 79 { 80 foreach (string campaign in campaignBadgesValues) 81 { 82 if (!string.IsNullOrEmpty(campaign)) 83 { 84 FieldValueViewModel availableCampaignsObject; 85 product.ProductFields.TryGetValue("Campaign", out availableCampaignsObject); 86 87 if (availableCampaignsObject != null) 88 { 89 string campaignType = string.Empty; 90 91 if (badgeConfigurations.ContainsKey(campaign)) 92 { 93 ParagraphInfoViewModel paragraphviewModel; 94 if (badgeConfigurations.TryGetValue(campaign, out paragraphviewModel)) 95 { 96 campaignType = paragraphviewModel.Item.GetRawValueString("CampaignType"); 97 } 98 } 99 100 List<FieldOptionValueViewModel> availableCampaigns = (List<FieldOptionValueViewModel>)availableCampaignsObject.Value; 101 102 foreach (FieldOptionValueViewModel availableOption in availableCampaigns) 103 { 104 if (campaignType == availableOption.Value) 105 { 106 badgesCount++; 107 break; 108 } 109 } 110 } 111 } 112 } 113 } 114 115 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 116 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 117 DateTime createdDate = product.Created.Value; 118 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 119 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 120 showBadges = (!string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) && badgesCount != 0) || showComingSoonBadge || showBadges; 121 122 if (showBadges) 123 { 124 <div class="@badgeSize @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 125 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 126 </div> 127 } 128 else if (Pageview.IsVisualEditorMode) 129 { 130 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 131 } 132 } 133 else if (Pageview.IsVisualEditorMode) 134 { 135 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 136 } 137 138
Liquid Lounge Proptrækker
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_160448cdee3c46a18a7a094dcad8bbe9.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage_Custom.cshtml:line 32
   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 System @*//CUSTOM*@ 3 @using System.Collections.Generic @*//CUSTOM*@ 4 @using System.Linq @*//CUSTOM*@ 5 @using Dynamicweb.Core @*//CUSTOM*@ 6 @using Dynamicweb.Ecommerce.ProductCatalog 7 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 10 11 @{ 12 ProductViewModel product = null; 13 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 14 { 15 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 16 } 17 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 18 { 19 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 20 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 21 22 if (productList?.Products is object) 23 { 24 product = productList.Products[0]; 25 } 26 } 27 } 28 29 @if (product is object) 30 { 31 //CUSTOM 32 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 33 DateTime currentDate = DateTime.Today; 34 bool showComingSoonBadge = currentDate < launchDate; 35 string brandLogo = Model.Item.GetString("Custom_BrandLogo"); 36 string brandLogoKey = Model.Item.GetString("Custom_BrandLogoKey"); 37 string brandLogoAltText = Model.Item.GetString("Custom_BrandAltText"); 38 int brandLogoWidth = Model.Item.GetInt32("Custom_BrandLogoWidth") > 0 ? Model.Item.GetInt32("Custom_BrandLogoWidth") : 70; 39 string productBrand = product.ProductFields.ContainsKey("Custom_Brand") ? Converter.ToString(product.ProductFields["Custom_Brand"].Value) : ""; 40 bool enableBrandLogo = !string.IsNullOrEmpty(brandLogo) && !string.IsNullOrEmpty(brandLogoKey) && brandLogoKey == productBrand; 41 //--CUSTOM 42 43 string imagePath = product?.DefaultImage?.Value ?? ""; 44 string imagePathUrlEncoded = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 45 46 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 47 ratio = ratio != "0" ? ratio : ""; 48 string ratioCssClass = ratio != "" ? " ratio" : ""; 49 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 50 51 string width = Model.Item.GetRawValueString("Width", "auto"); 52 int smallImageSize = 640; 53 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 54 55 string ImageObjectFit = Model.Item.GetRawValueString("ImageObjectFit", "contain"); 56 57 string imagePathXs = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 58 string imagePathS = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 59 string imagePathFallBack = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 60 61 var badgeParms = new Dictionary<string, object>(); 62 badgeParms.Add("size", "h7"); 63 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 64 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 65 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 66 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 67 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 68 69 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 70 71 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 72 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 73 bool anonymousUser = Pageview.User == null; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 if (!anonymousUser && showFavoritesSelector) 77 { 78 int defaultFavoriteListId = 0; 79 80 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 81 if (favoreiteLists.Count() == 1) 82 { 83 foreach (FavoriteList list in favoreiteLists) 84 { 85 defaultFavoriteListId = list.ListId; 86 } 87 } 88 89 favoriteParameters.Add("ListId", defaultFavoriteListId); 90 } 91 92 MediaViewModel alternativeImage = new MediaViewModel(); 93 if (Model.Item.GetBoolean("ShowAlternativeImageOnHover")) 94 { 95 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 96 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 97 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 98 alternativeImage = allAssetsImages.FirstOrDefault(); 99 } 100 101 string altImagePathXs = string.Empty; 102 string altImagePathS = string.Empty; 103 104 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 105 { 106 altImagePathXs = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 107 altImagePathS = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 108 } 109 110 @* Theme settings *@ 111 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 112 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 113 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 114 115 string imageId = "ProductImage_" + product.Id + product.VariantId.Replace(".", "_"); 116 117 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 118 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 119 DateTime createdDate = product.Created.Value; 120 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 121 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 122 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) || showComingSoonBadge || showBadges; //CUSTOM 123 124 string fullWidth = width == "auto" ? "w-100" : ""; 125 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 126 127 @* -- CUSTOM -- Added image item prop *@ 128 if (!string.IsNullOrEmpty(imagePath)) 129 { 130 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 131 <div class="ratio" style="@(ratioVariable)"> 132 <div class="d-flex justify-content-center align-items-center"> 133 @* CUSTOM *@ 134 @if (enableBrandLogo) 135 { 136 <img src="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogo)" 137 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoAltText)" 138 class="productdefault-brand-logo" 139 width="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoWidth.ToString())" /> 140 } 141 @* CUSTOM END *@ 142 @if (imagePath.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 143 { 144 <img id="@imageId" 145 itemprop="image" 146 srcset=" 147 @imagePathXs @(smallImageSize)w, 148 @imagePathS @(largeImageSize)w" 149 sizes="(max-width: 992px) 50vw, 25vw" 150 src="@imagePathFallBack" 151 @if (Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 152 data-alternative-image=" 153 @altImagePathXs @(smallImageSize)w, 154 @altImagePathS @(largeImageSize)w" 155 onmouseover="swift.Image.swapImage(event)" 156 onmouseout="swift.Image.swapImage(event)" 157 </text> } 158 loading="lazy" 159 decoding="async" 160 class="h-100 w-100 @themePadding" 161 style="object-fit: @ImageObjectFit; @themeBorder" 162 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 163 } 164 //CUSTOM 165 else if (imagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) 166 { 167 <img id="@imageId" 168 itemprop="image" 169 srcset=" 170 @imagePathXs @(smallImageSize)w, 171 @imagePathS @(largeImageSize)w" 172 sizes="(max-width: 992px) 50vw, 25vw" 173 src="@imagePathFallBack" 174 data-alternative-image=" 175 @altImagePathXs @(smallImageSize)w, 176 @altImagePathS @(largeImageSize)w" 177 onmouseover="swift.Image.swapImage(event)" 178 onmouseout="swift.Image.swapImage(event)" 179 loading="lazy" 180 decoding="async" 181 class="h-100 w-100 @themePadding" 182 style="object-fit: @ImageObjectFit; @themeBorder" 183 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 184 } 185 //--CUSTOM 186 else 187 { 188 <img itemprop="image" 189 src="@product.DefaultImage.Value" 190 loading="lazy" 191 class="h-100 w-100 @themePadding" 192 style="object-fit: contain; @themeBorder" 193 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 194 } 195 </div> 196 </div> 197 198 @if (showBadges) 199 { 200 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 201 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 202 </div> 203 } 204 205 @if (!anonymousUser) 206 { 207 if (showFavoritesSelector) 208 { 209 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 210 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 211 </div> 212 } 213 } 214 </div> 215 } 216 } 217 else if (Pageview.IsVisualEditorMode) 218 { 219 <div class="alert alert-dark m-0">@Translate("No products available")</div> 220 } 221

Liquid Lounge Proptrækker

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fb0d18a1de944f3a468232b7643f0eb.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 65
   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.Configuration @*//CUSTOM*@ 3 @using Dynamicweb.Core.Encoders @*//CUSTOM*@ 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 @using System.Globalization 6 @using System.IO @*//CUSTOM*@ 7 8 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 bool productIsDiscontinued = product is object && product.Discontinued; 33 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 34 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 35 } 36 37 @if (product is object && !hidePrice && !isDiscontinued) 38 { 39 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 40 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 41 42 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "h6 justify-content-lg-start"); //CUSTOM 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 45 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 46 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 47 48 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 50 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 51 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 52 53 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 54 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 55 string order = layout == "horizontal" ? string.Empty : "order-2"; 56 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 57 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 61 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 62 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 63 64 //CUSTOM 65 Dictionary<string, FieldValueViewModel> productFields = product.ProductFields; 66 var discountText = ""; 67 bool discountDiscontinued = false; 68 bool discountOnSale = false; 69 70 if (productFields.TryGetValue("Custom_Discontinued", out FieldValueViewModel discontinued)) 71 { 72 var firstValue = (discontinued.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 73 74 if (!string.IsNullOrWhiteSpace(firstValue)) 75 { 76 bool.TryParse(firstValue, out discountDiscontinued); 77 } 78 } 79 80 if (productFields.TryGetValue("Custom_OnSale", out FieldValueViewModel onsale)) 81 { 82 var firstValue = (onsale.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 83 84 if (!string.IsNullOrWhiteSpace(firstValue)) 85 { 86 bool.TryParse(firstValue, out discountOnSale); 87 } 88 } 89 90 if (discountDiscontinued && discountOnSale) 91 { 92 discountText = Translate("Outlet - tilbuddet gælder så længe lager haves"); 93 } 94 else 95 { 96 var discountInfo = Smartpage.EvaSolo.CampaignPrices.Helpers.DiscountHelper.GetDiscountInfo(product); 97 if (discountInfo != null) 98 { 99 discountText = string.Format(Translate(Model.Item.GetRawValueString("Custom_DiscountText", "Tilbuddet gælder {0} - {1}")), $"&zwnj;{discountInfo.ValidFromFormatted}&zwnj;", $"&zwnj;{discountInfo.ValidToFormatted}&zwnj;"); 100 } 101 } 102 string discountType = Model.Item.GetRawValueString("Custom_DiscountType", "none"); 103 string discountTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Custom_DiscountTheme")) ? "theme " + Model.Item.GetRawValueString("Custom_DiscountTheme").Replace(" ", "").Trim().ToLower() : string.Empty; 104 string discountIconColor = Model.Item.GetString("Custom_DiscountIconColor", "text-inherit"); 105 string discountIconSize = Model.Item.GetRawValueString("Custom_DiscountIconSize", "2"); 106 string discountImageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) ? Model.Item.GetFile("Custom_DiscountImage").Path : string.Empty; 107 string discountImagePath = discountImageSrc != string.Empty ? discountImageSrc : Model.Item.GetRawValueString("Custom_DiscountIcon", string.Empty); 108 discountImagePath = Path.GetExtension(discountImagePath).ToLower() != ".svg" ? "/Admin/Public/GetImage.ashx?image=" + discountImagePath + "&height=" + discountIconSize + "&width=" + discountIconSize + "&Crop=0&format=webp" : discountImagePath; 109 string discountImgAltText = Model.Item.GetRawValueString("FeatureAltText", string.Empty); 110 //--CUSTOM 111 112 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 113 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 114 115 string priceMin = ""; 116 string priceMax = ""; 117 118 string liveInfoClass = ""; 119 string productInfoFeed = ""; 120 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 121 if (isLazyLoadingForProductInfoEnabled) 122 { 123 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 124 { 125 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 126 if (!string.IsNullOrEmpty(productInfoFeed)) 127 { 128 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 129 } 130 } 131 liveInfoClass = "js-live-info"; 132 } 133 134 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 135 @if (showInformativePrice && product.PriceInformative.Price != 0) 136 { 137 <div class="opacity-50"> 138 <span>@Translate("RRP") </span> 139 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 140 </div> 141 } 142 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 143 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 144 145 @*//CUSTOM*@ 146 @if (showPricesWithVat == "false" && !neverShowVat) 147 { 148 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 149 { 150 <span class="text-price js-text-price"> 151 <span class="spinner-border" role="status"></span> 152 </span> 153 } 154 else 155 { 156 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 157 158 if (product?.VariantInfo?.VariantInfo != null) 159 { 160 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 161 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 162 } 163 if (priceMin != priceMax) 164 { 165 price = priceMin + " - " + priceMax; 166 } 167 168 <span class="@theme"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 195 <span class="@theme"> 196 <span class="text-price">@price</span> 197 </span> 198 } 199 } 200 201 @if (showPricesWithVat == "false" && !neverShowVat) 202 { 203 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 204 { 205 <span itemprop="price" content="" class="d-none"></span> 206 <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> 207 } 208 else 209 { 210 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 211 212 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 213 214 if (product.Price.Price != product.PriceBeforeDiscount.Price) 215 { 216 <span class="opacity-75 @(order)"> 217 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 218 </span> 219 220 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 221 { 222 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 223 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 224 { 225 PriceWithoutVAT = (product.PriceBeforeDiscount.PriceWithoutVat - product.Price.PriceWithoutVat) 226 }; 227 228 <span class="d-none d-sm-inline opacity-75 @(order)"> 229 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceWithoutVATFormatted)</span> 230 </span> 231 } 232 } 233 } 234 } 235 else 236 { 237 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 238 { 239 <span itemprop="price" content="" class="d-none"></span> 240 <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> 241 } 242 else 243 { 244 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 245 246 <span itemprop="price" content="@product.Price.Price.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 247 248 if (product.Price.Price < product.PriceBeforeDiscount.Price) 249 { 250 <span class="opacity-75 @(order)"> 251 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 252 </span> 253 254 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 255 { 256 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 257 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 258 { 259 PriceWithVAT = (product.PriceBeforeDiscount.Price - product.Price.Price) 260 }; 261 262 <span class="d-none d-sm-inline opacity-75 @(order)"> 263 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceFormatted)</span> 264 </span> 265 } 266 } 267 } 268 } 269 @*//--CUSTOM*@ 270 271 @*//CUSTOM*@ 272 @if (discountType == "icon-tooltip" && product.Price.Price != product.PriceBeforeDiscount.Price && discountText != null) 273 { 274 if ((!string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) || !discountImagePath.ToLower().Contains("none")) && discountImagePath != string.Empty) 275 { 276 <span data-bs-toggle="tooltip" data-bs-custom-class="@(discountTheme)" data-bs-html="true" data-bs-title="@HtmlEncoder.HtmlAttributeEncode(discountText)" data-bs-custom-prevent-event="click" data-bs-custom-click-close-delay="2000"> 277 @if (Path.GetExtension(discountImagePath).ToLower() == ".svg") 278 { 279 <span class="icon-auto @(discountIconColor)" style="vertical-align:text-top;height:@(discountIconSize)px;width:@(discountIconSize)px;">@ReadFile(discountImagePath)</span> 280 } 281 else 282 { 283 <img loading="lazy" src="@(discountImagePath)" alt="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" title="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" style="height:@(discountIconSize)px;width:@(discountIconSize)px;"> 284 } 285 </span> 286 } 287 } 288 @*//--CUSTOM*@ 289 290 @* Stock state for Schema.org, start *@ 291 @{ 292 Uri url = Dynamicweb.Context.Current.Request.Url; 293 } 294 295 <link itemprop="url" href="@url"> 296 297 @{ 298 bool IsNeverOutOfStock = product.NeverOutOfstock; 299 } 300 301 @if (IsNeverOutOfStock) 302 { 303 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 304 } 305 else 306 { 307 if (product.StockLevel > 0) 308 { 309 <span itemprop="availability" class="d-none">InStock</span> 310 } 311 else 312 { 313 <span itemprop="availability" class="d-none">OutOfStock</span> 314 } 315 } 316 @* Stock state for Schema.org, stop *@ 317 318 </div> 319 320 @if (showPricesWithVat == "false" && !neverShowVat) 321 { 322 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 323 { 324 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 325 } 326 else 327 { 328 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 329 330 if (product?.VariantInfo?.VariantInfo != null) 331 { 332 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 333 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 334 } 335 if (priceMin != priceMax) 336 { 337 price = priceMin + " - " + priceMax; 338 } 339 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 340 } 341 } 342 343 @*//CUSTOM*@ 344 @if (discountType == "inline" && product.Price.Price != product.PriceBeforeDiscount.Price && !string.IsNullOrEmpty(discountText)) 345 { 346 var discountFontSize = priceFontSize.Contains("h6") ? priceFontSize.Replace("h6", "small") : "small"; 347 348 <div class="@(discountFontSize) mt-1 d-flex flex-wrap @(flexDirection) @(horizontalAlign)"> 349 @discountText 350 </div> 351 } 352 @*//--CUSTOM*@ 353 354 </div> 355 } 356 else if (Pageview.IsVisualEditorMode) 357 { 358 <div class="alert alert-dark m-0" role="alert"> 359 <span>@Translate("No products available")</span> 360 </div> 361 } 362
Error executing template "Designs/Swift/Paragraph/Swift_ProductBadges_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_fe4e63c166214874a0bcb86da4f14f88.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBadges_Custom.cshtml:line 27
   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 System 3 @using System.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Content 7 @using Dynamicweb.Core 8 @using Dynamicweb.Ecommerce.ProductCatalog 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 28 DateTime currentDate = DateTime.Today; 29 bool showComingSoonBadge = currentDate < launchDate && string.Equals( Model.Item.GetRawValueString("NewBadgeDesign"), "comingsoon", StringComparison.InvariantCultureIgnoreCase ); 30 } 31 32 @if (product is object) 33 { 34 var badgeParms = new Dictionary<string, object>(); 35 badgeParms.Add("size", "h7"); 36 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 37 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 38 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 39 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 40 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 41 42 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 46 47 Dictionary<string, ParagraphInfoViewModel> badgeConfigurations; 48 List<string> campaignBadgesValues = Model.Item.GetRawValueString("CampaignBadges") != null ? Model.Item.GetRawValueString("CampaignBadges").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>(); 49 50 if (Dynamicweb.Context.Current.Items.Contains("badgeConfigurations")) 51 { 52 badgeConfigurations = (Dictionary<string, ParagraphInfoViewModel>)Dynamicweb.Context.Current.Items["badgeConfigurations"]; 53 } 54 else 55 { 56 var badgesPage = Pageview.AreaSettings.GetLink("EcommerceBadgesPage") != null ? Pageview.AreaSettings.GetLink("EcommerceBadgesPage").PageId : 0; 57 var allBadges = badgesPage != 0 ? Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(badgesPage) : null; 58 59 badgeConfigurations = new Dictionary<string, ParagraphInfoViewModel>(); 60 61 if ( allBadges != null ) 62 { 63 foreach ( Paragraph badge in allBadges ) 64 { 65 var paragraphviewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel( badge ); 66 string cssClassName = paragraphviewModel.Item.GetString( "CssClassName" )?.Trim().ToLower() ?? string.Empty;; 67 if ( !badgeConfigurations.ContainsKey( cssClassName ) ) 68 { 69 badgeConfigurations.Add( cssClassName, paragraphviewModel ); 70 } 71 } 72 } 73 74 Dynamicweb.Context.Current.Items.Add("badgeConfigurations", badgeConfigurations); 75 } 76 77 int badgesCount = 0; 78 if (badgeConfigurations.Any()) 79 { 80 foreach (string campaign in campaignBadgesValues) 81 { 82 if (!string.IsNullOrEmpty(campaign)) 83 { 84 FieldValueViewModel availableCampaignsObject; 85 product.ProductFields.TryGetValue("Campaign", out availableCampaignsObject); 86 87 if (availableCampaignsObject != null) 88 { 89 string campaignType = string.Empty; 90 91 if (badgeConfigurations.ContainsKey(campaign)) 92 { 93 ParagraphInfoViewModel paragraphviewModel; 94 if (badgeConfigurations.TryGetValue(campaign, out paragraphviewModel)) 95 { 96 campaignType = paragraphviewModel.Item.GetRawValueString("CampaignType"); 97 } 98 } 99 100 List<FieldOptionValueViewModel> availableCampaigns = (List<FieldOptionValueViewModel>)availableCampaignsObject.Value; 101 102 foreach (FieldOptionValueViewModel availableOption in availableCampaigns) 103 { 104 if (campaignType == availableOption.Value) 105 { 106 badgesCount++; 107 break; 108 } 109 } 110 } 111 } 112 } 113 } 114 115 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 116 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 117 DateTime createdDate = product.Created.Value; 118 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 119 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 120 showBadges = (!string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) && badgesCount != 0) || showComingSoonBadge || showBadges; 121 122 if (showBadges) 123 { 124 <div class="@badgeSize @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 125 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 126 </div> 127 } 128 else if (Pageview.IsVisualEditorMode) 129 { 130 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 131 } 132 } 133 else if (Pageview.IsVisualEditorMode) 134 { 135 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 136 } 137 138
Liquid Lounge Tjenerproptrækker
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_160448cdee3c46a18a7a094dcad8bbe9.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage_Custom.cshtml:line 32
   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 System @*//CUSTOM*@ 3 @using System.Collections.Generic @*//CUSTOM*@ 4 @using System.Linq @*//CUSTOM*@ 5 @using Dynamicweb.Core @*//CUSTOM*@ 6 @using Dynamicweb.Ecommerce.ProductCatalog 7 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 10 11 @{ 12 ProductViewModel product = null; 13 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 14 { 15 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 16 } 17 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 18 { 19 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 20 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 21 22 if (productList?.Products is object) 23 { 24 product = productList.Products[0]; 25 } 26 } 27 } 28 29 @if (product is object) 30 { 31 //CUSTOM 32 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 33 DateTime currentDate = DateTime.Today; 34 bool showComingSoonBadge = currentDate < launchDate; 35 string brandLogo = Model.Item.GetString("Custom_BrandLogo"); 36 string brandLogoKey = Model.Item.GetString("Custom_BrandLogoKey"); 37 string brandLogoAltText = Model.Item.GetString("Custom_BrandAltText"); 38 int brandLogoWidth = Model.Item.GetInt32("Custom_BrandLogoWidth") > 0 ? Model.Item.GetInt32("Custom_BrandLogoWidth") : 70; 39 string productBrand = product.ProductFields.ContainsKey("Custom_Brand") ? Converter.ToString(product.ProductFields["Custom_Brand"].Value) : ""; 40 bool enableBrandLogo = !string.IsNullOrEmpty(brandLogo) && !string.IsNullOrEmpty(brandLogoKey) && brandLogoKey == productBrand; 41 //--CUSTOM 42 43 string imagePath = product?.DefaultImage?.Value ?? ""; 44 string imagePathUrlEncoded = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 45 46 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 47 ratio = ratio != "0" ? ratio : ""; 48 string ratioCssClass = ratio != "" ? " ratio" : ""; 49 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 50 51 string width = Model.Item.GetRawValueString("Width", "auto"); 52 int smallImageSize = 640; 53 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 54 55 string ImageObjectFit = Model.Item.GetRawValueString("ImageObjectFit", "contain"); 56 57 string imagePathXs = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 58 string imagePathS = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 59 string imagePathFallBack = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 60 61 var badgeParms = new Dictionary<string, object>(); 62 badgeParms.Add("size", "h7"); 63 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 64 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 65 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 66 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 67 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 68 69 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 70 71 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 72 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 73 bool anonymousUser = Pageview.User == null; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 if (!anonymousUser && showFavoritesSelector) 77 { 78 int defaultFavoriteListId = 0; 79 80 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 81 if (favoreiteLists.Count() == 1) 82 { 83 foreach (FavoriteList list in favoreiteLists) 84 { 85 defaultFavoriteListId = list.ListId; 86 } 87 } 88 89 favoriteParameters.Add("ListId", defaultFavoriteListId); 90 } 91 92 MediaViewModel alternativeImage = new MediaViewModel(); 93 if (Model.Item.GetBoolean("ShowAlternativeImageOnHover")) 94 { 95 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 96 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 97 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 98 alternativeImage = allAssetsImages.FirstOrDefault(); 99 } 100 101 string altImagePathXs = string.Empty; 102 string altImagePathS = string.Empty; 103 104 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 105 { 106 altImagePathXs = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 107 altImagePathS = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 108 } 109 110 @* Theme settings *@ 111 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 112 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 113 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 114 115 string imageId = "ProductImage_" + product.Id + product.VariantId.Replace(".", "_"); 116 117 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 118 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 119 DateTime createdDate = product.Created.Value; 120 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 121 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 122 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) || showComingSoonBadge || showBadges; //CUSTOM 123 124 string fullWidth = width == "auto" ? "w-100" : ""; 125 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 126 127 @* -- CUSTOM -- Added image item prop *@ 128 if (!string.IsNullOrEmpty(imagePath)) 129 { 130 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 131 <div class="ratio" style="@(ratioVariable)"> 132 <div class="d-flex justify-content-center align-items-center"> 133 @* CUSTOM *@ 134 @if (enableBrandLogo) 135 { 136 <img src="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogo)" 137 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoAltText)" 138 class="productdefault-brand-logo" 139 width="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoWidth.ToString())" /> 140 } 141 @* CUSTOM END *@ 142 @if (imagePath.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 143 { 144 <img id="@imageId" 145 itemprop="image" 146 srcset=" 147 @imagePathXs @(smallImageSize)w, 148 @imagePathS @(largeImageSize)w" 149 sizes="(max-width: 992px) 50vw, 25vw" 150 src="@imagePathFallBack" 151 @if (Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 152 data-alternative-image=" 153 @altImagePathXs @(smallImageSize)w, 154 @altImagePathS @(largeImageSize)w" 155 onmouseover="swift.Image.swapImage(event)" 156 onmouseout="swift.Image.swapImage(event)" 157 </text> } 158 loading="lazy" 159 decoding="async" 160 class="h-100 w-100 @themePadding" 161 style="object-fit: @ImageObjectFit; @themeBorder" 162 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 163 } 164 //CUSTOM 165 else if (imagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) 166 { 167 <img id="@imageId" 168 itemprop="image" 169 srcset=" 170 @imagePathXs @(smallImageSize)w, 171 @imagePathS @(largeImageSize)w" 172 sizes="(max-width: 992px) 50vw, 25vw" 173 src="@imagePathFallBack" 174 data-alternative-image=" 175 @altImagePathXs @(smallImageSize)w, 176 @altImagePathS @(largeImageSize)w" 177 onmouseover="swift.Image.swapImage(event)" 178 onmouseout="swift.Image.swapImage(event)" 179 loading="lazy" 180 decoding="async" 181 class="h-100 w-100 @themePadding" 182 style="object-fit: @ImageObjectFit; @themeBorder" 183 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 184 } 185 //--CUSTOM 186 else 187 { 188 <img itemprop="image" 189 src="@product.DefaultImage.Value" 190 loading="lazy" 191 class="h-100 w-100 @themePadding" 192 style="object-fit: contain; @themeBorder" 193 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 194 } 195 </div> 196 </div> 197 198 @if (showBadges) 199 { 200 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 201 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 202 </div> 203 } 204 205 @if (!anonymousUser) 206 { 207 if (showFavoritesSelector) 208 { 209 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 210 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 211 </div> 212 } 213 } 214 </div> 215 } 216 } 217 else if (Pageview.IsVisualEditorMode) 218 { 219 <div class="alert alert-dark m-0">@Translate("No products available")</div> 220 } 221

Liquid Lounge Tjenerproptrækker

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fb0d18a1de944f3a468232b7643f0eb.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 65
   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.Configuration @*//CUSTOM*@ 3 @using Dynamicweb.Core.Encoders @*//CUSTOM*@ 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 @using System.Globalization 6 @using System.IO @*//CUSTOM*@ 7 8 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 bool productIsDiscontinued = product is object && product.Discontinued; 33 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 34 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 35 } 36 37 @if (product is object && !hidePrice && !isDiscontinued) 38 { 39 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 40 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 41 42 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "h6 justify-content-lg-start"); //CUSTOM 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 45 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 46 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 47 48 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 50 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 51 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 52 53 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 54 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 55 string order = layout == "horizontal" ? string.Empty : "order-2"; 56 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 57 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 61 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 62 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 63 64 //CUSTOM 65 Dictionary<string, FieldValueViewModel> productFields = product.ProductFields; 66 var discountText = ""; 67 bool discountDiscontinued = false; 68 bool discountOnSale = false; 69 70 if (productFields.TryGetValue("Custom_Discontinued", out FieldValueViewModel discontinued)) 71 { 72 var firstValue = (discontinued.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 73 74 if (!string.IsNullOrWhiteSpace(firstValue)) 75 { 76 bool.TryParse(firstValue, out discountDiscontinued); 77 } 78 } 79 80 if (productFields.TryGetValue("Custom_OnSale", out FieldValueViewModel onsale)) 81 { 82 var firstValue = (onsale.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 83 84 if (!string.IsNullOrWhiteSpace(firstValue)) 85 { 86 bool.TryParse(firstValue, out discountOnSale); 87 } 88 } 89 90 if (discountDiscontinued && discountOnSale) 91 { 92 discountText = Translate("Outlet - tilbuddet gælder så længe lager haves"); 93 } 94 else 95 { 96 var discountInfo = Smartpage.EvaSolo.CampaignPrices.Helpers.DiscountHelper.GetDiscountInfo(product); 97 if (discountInfo != null) 98 { 99 discountText = string.Format(Translate(Model.Item.GetRawValueString("Custom_DiscountText", "Tilbuddet gælder {0} - {1}")), $"&zwnj;{discountInfo.ValidFromFormatted}&zwnj;", $"&zwnj;{discountInfo.ValidToFormatted}&zwnj;"); 100 } 101 } 102 string discountType = Model.Item.GetRawValueString("Custom_DiscountType", "none"); 103 string discountTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Custom_DiscountTheme")) ? "theme " + Model.Item.GetRawValueString("Custom_DiscountTheme").Replace(" ", "").Trim().ToLower() : string.Empty; 104 string discountIconColor = Model.Item.GetString("Custom_DiscountIconColor", "text-inherit"); 105 string discountIconSize = Model.Item.GetRawValueString("Custom_DiscountIconSize", "2"); 106 string discountImageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) ? Model.Item.GetFile("Custom_DiscountImage").Path : string.Empty; 107 string discountImagePath = discountImageSrc != string.Empty ? discountImageSrc : Model.Item.GetRawValueString("Custom_DiscountIcon", string.Empty); 108 discountImagePath = Path.GetExtension(discountImagePath).ToLower() != ".svg" ? "/Admin/Public/GetImage.ashx?image=" + discountImagePath + "&height=" + discountIconSize + "&width=" + discountIconSize + "&Crop=0&format=webp" : discountImagePath; 109 string discountImgAltText = Model.Item.GetRawValueString("FeatureAltText", string.Empty); 110 //--CUSTOM 111 112 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 113 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 114 115 string priceMin = ""; 116 string priceMax = ""; 117 118 string liveInfoClass = ""; 119 string productInfoFeed = ""; 120 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 121 if (isLazyLoadingForProductInfoEnabled) 122 { 123 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 124 { 125 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 126 if (!string.IsNullOrEmpty(productInfoFeed)) 127 { 128 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 129 } 130 } 131 liveInfoClass = "js-live-info"; 132 } 133 134 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 135 @if (showInformativePrice && product.PriceInformative.Price != 0) 136 { 137 <div class="opacity-50"> 138 <span>@Translate("RRP") </span> 139 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 140 </div> 141 } 142 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 143 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 144 145 @*//CUSTOM*@ 146 @if (showPricesWithVat == "false" && !neverShowVat) 147 { 148 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 149 { 150 <span class="text-price js-text-price"> 151 <span class="spinner-border" role="status"></span> 152 </span> 153 } 154 else 155 { 156 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 157 158 if (product?.VariantInfo?.VariantInfo != null) 159 { 160 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 161 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 162 } 163 if (priceMin != priceMax) 164 { 165 price = priceMin + " - " + priceMax; 166 } 167 168 <span class="@theme"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 195 <span class="@theme"> 196 <span class="text-price">@price</span> 197 </span> 198 } 199 } 200 201 @if (showPricesWithVat == "false" && !neverShowVat) 202 { 203 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 204 { 205 <span itemprop="price" content="" class="d-none"></span> 206 <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> 207 } 208 else 209 { 210 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 211 212 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 213 214 if (product.Price.Price != product.PriceBeforeDiscount.Price) 215 { 216 <span class="opacity-75 @(order)"> 217 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 218 </span> 219 220 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 221 { 222 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 223 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 224 { 225 PriceWithoutVAT = (product.PriceBeforeDiscount.PriceWithoutVat - product.Price.PriceWithoutVat) 226 }; 227 228 <span class="d-none d-sm-inline opacity-75 @(order)"> 229 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceWithoutVATFormatted)</span> 230 </span> 231 } 232 } 233 } 234 } 235 else 236 { 237 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 238 { 239 <span itemprop="price" content="" class="d-none"></span> 240 <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> 241 } 242 else 243 { 244 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 245 246 <span itemprop="price" content="@product.Price.Price.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 247 248 if (product.Price.Price < product.PriceBeforeDiscount.Price) 249 { 250 <span class="opacity-75 @(order)"> 251 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 252 </span> 253 254 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 255 { 256 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 257 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 258 { 259 PriceWithVAT = (product.PriceBeforeDiscount.Price - product.Price.Price) 260 }; 261 262 <span class="d-none d-sm-inline opacity-75 @(order)"> 263 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceFormatted)</span> 264 </span> 265 } 266 } 267 } 268 } 269 @*//--CUSTOM*@ 270 271 @*//CUSTOM*@ 272 @if (discountType == "icon-tooltip" && product.Price.Price != product.PriceBeforeDiscount.Price && discountText != null) 273 { 274 if ((!string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) || !discountImagePath.ToLower().Contains("none")) && discountImagePath != string.Empty) 275 { 276 <span data-bs-toggle="tooltip" data-bs-custom-class="@(discountTheme)" data-bs-html="true" data-bs-title="@HtmlEncoder.HtmlAttributeEncode(discountText)" data-bs-custom-prevent-event="click" data-bs-custom-click-close-delay="2000"> 277 @if (Path.GetExtension(discountImagePath).ToLower() == ".svg") 278 { 279 <span class="icon-auto @(discountIconColor)" style="vertical-align:text-top;height:@(discountIconSize)px;width:@(discountIconSize)px;">@ReadFile(discountImagePath)</span> 280 } 281 else 282 { 283 <img loading="lazy" src="@(discountImagePath)" alt="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" title="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" style="height:@(discountIconSize)px;width:@(discountIconSize)px;"> 284 } 285 </span> 286 } 287 } 288 @*//--CUSTOM*@ 289 290 @* Stock state for Schema.org, start *@ 291 @{ 292 Uri url = Dynamicweb.Context.Current.Request.Url; 293 } 294 295 <link itemprop="url" href="@url"> 296 297 @{ 298 bool IsNeverOutOfStock = product.NeverOutOfstock; 299 } 300 301 @if (IsNeverOutOfStock) 302 { 303 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 304 } 305 else 306 { 307 if (product.StockLevel > 0) 308 { 309 <span itemprop="availability" class="d-none">InStock</span> 310 } 311 else 312 { 313 <span itemprop="availability" class="d-none">OutOfStock</span> 314 } 315 } 316 @* Stock state for Schema.org, stop *@ 317 318 </div> 319 320 @if (showPricesWithVat == "false" && !neverShowVat) 321 { 322 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 323 { 324 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 325 } 326 else 327 { 328 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 329 330 if (product?.VariantInfo?.VariantInfo != null) 331 { 332 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 333 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 334 } 335 if (priceMin != priceMax) 336 { 337 price = priceMin + " - " + priceMax; 338 } 339 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 340 } 341 } 342 343 @*//CUSTOM*@ 344 @if (discountType == "inline" && product.Price.Price != product.PriceBeforeDiscount.Price && !string.IsNullOrEmpty(discountText)) 345 { 346 var discountFontSize = priceFontSize.Contains("h6") ? priceFontSize.Replace("h6", "small") : "small"; 347 348 <div class="@(discountFontSize) mt-1 d-flex flex-wrap @(flexDirection) @(horizontalAlign)"> 349 @discountText 350 </div> 351 } 352 @*//--CUSTOM*@ 353 354 </div> 355 } 356 else if (Pageview.IsVisualEditorMode) 357 { 358 <div class="alert alert-dark m-0" role="alert"> 359 <span>@Translate("No products available")</span> 360 </div> 361 } 362
Error executing template "Designs/Swift/Paragraph/Swift_ProductBadges_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_fe4e63c166214874a0bcb86da4f14f88.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBadges_Custom.cshtml:line 27
   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 System 3 @using System.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Content 7 @using Dynamicweb.Core 8 @using Dynamicweb.Ecommerce.ProductCatalog 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 28 DateTime currentDate = DateTime.Today; 29 bool showComingSoonBadge = currentDate < launchDate && string.Equals( Model.Item.GetRawValueString("NewBadgeDesign"), "comingsoon", StringComparison.InvariantCultureIgnoreCase ); 30 } 31 32 @if (product is object) 33 { 34 var badgeParms = new Dictionary<string, object>(); 35 badgeParms.Add("size", "h7"); 36 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 37 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 38 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 39 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 40 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 41 42 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 46 47 Dictionary<string, ParagraphInfoViewModel> badgeConfigurations; 48 List<string> campaignBadgesValues = Model.Item.GetRawValueString("CampaignBadges") != null ? Model.Item.GetRawValueString("CampaignBadges").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>(); 49 50 if (Dynamicweb.Context.Current.Items.Contains("badgeConfigurations")) 51 { 52 badgeConfigurations = (Dictionary<string, ParagraphInfoViewModel>)Dynamicweb.Context.Current.Items["badgeConfigurations"]; 53 } 54 else 55 { 56 var badgesPage = Pageview.AreaSettings.GetLink("EcommerceBadgesPage") != null ? Pageview.AreaSettings.GetLink("EcommerceBadgesPage").PageId : 0; 57 var allBadges = badgesPage != 0 ? Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(badgesPage) : null; 58 59 badgeConfigurations = new Dictionary<string, ParagraphInfoViewModel>(); 60 61 if ( allBadges != null ) 62 { 63 foreach ( Paragraph badge in allBadges ) 64 { 65 var paragraphviewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel( badge ); 66 string cssClassName = paragraphviewModel.Item.GetString( "CssClassName" )?.Trim().ToLower() ?? string.Empty;; 67 if ( !badgeConfigurations.ContainsKey( cssClassName ) ) 68 { 69 badgeConfigurations.Add( cssClassName, paragraphviewModel ); 70 } 71 } 72 } 73 74 Dynamicweb.Context.Current.Items.Add("badgeConfigurations", badgeConfigurations); 75 } 76 77 int badgesCount = 0; 78 if (badgeConfigurations.Any()) 79 { 80 foreach (string campaign in campaignBadgesValues) 81 { 82 if (!string.IsNullOrEmpty(campaign)) 83 { 84 FieldValueViewModel availableCampaignsObject; 85 product.ProductFields.TryGetValue("Campaign", out availableCampaignsObject); 86 87 if (availableCampaignsObject != null) 88 { 89 string campaignType = string.Empty; 90 91 if (badgeConfigurations.ContainsKey(campaign)) 92 { 93 ParagraphInfoViewModel paragraphviewModel; 94 if (badgeConfigurations.TryGetValue(campaign, out paragraphviewModel)) 95 { 96 campaignType = paragraphviewModel.Item.GetRawValueString("CampaignType"); 97 } 98 } 99 100 List<FieldOptionValueViewModel> availableCampaigns = (List<FieldOptionValueViewModel>)availableCampaignsObject.Value; 101 102 foreach (FieldOptionValueViewModel availableOption in availableCampaigns) 103 { 104 if (campaignType == availableOption.Value) 105 { 106 badgesCount++; 107 break; 108 } 109 } 110 } 111 } 112 } 113 } 114 115 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 116 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 117 DateTime createdDate = product.Created.Value; 118 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 119 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 120 showBadges = (!string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) && badgesCount != 0) || showComingSoonBadge || showBadges; 121 122 if (showBadges) 123 { 124 <div class="@badgeSize @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 125 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 126 </div> 127 } 128 else if (Pageview.IsVisualEditorMode) 129 { 130 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 131 } 132 } 133 else if (Pageview.IsVisualEditorMode) 134 { 135 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 136 } 137 138
Liquid Lounge Cocktail muddler
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_160448cdee3c46a18a7a094dcad8bbe9.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage_Custom.cshtml:line 32
   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 System @*//CUSTOM*@ 3 @using System.Collections.Generic @*//CUSTOM*@ 4 @using System.Linq @*//CUSTOM*@ 5 @using Dynamicweb.Core @*//CUSTOM*@ 6 @using Dynamicweb.Ecommerce.ProductCatalog 7 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 10 11 @{ 12 ProductViewModel product = null; 13 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 14 { 15 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 16 } 17 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 18 { 19 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 20 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 21 22 if (productList?.Products is object) 23 { 24 product = productList.Products[0]; 25 } 26 } 27 } 28 29 @if (product is object) 30 { 31 //CUSTOM 32 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 33 DateTime currentDate = DateTime.Today; 34 bool showComingSoonBadge = currentDate < launchDate; 35 string brandLogo = Model.Item.GetString("Custom_BrandLogo"); 36 string brandLogoKey = Model.Item.GetString("Custom_BrandLogoKey"); 37 string brandLogoAltText = Model.Item.GetString("Custom_BrandAltText"); 38 int brandLogoWidth = Model.Item.GetInt32("Custom_BrandLogoWidth") > 0 ? Model.Item.GetInt32("Custom_BrandLogoWidth") : 70; 39 string productBrand = product.ProductFields.ContainsKey("Custom_Brand") ? Converter.ToString(product.ProductFields["Custom_Brand"].Value) : ""; 40 bool enableBrandLogo = !string.IsNullOrEmpty(brandLogo) && !string.IsNullOrEmpty(brandLogoKey) && brandLogoKey == productBrand; 41 //--CUSTOM 42 43 string imagePath = product?.DefaultImage?.Value ?? ""; 44 string imagePathUrlEncoded = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 45 46 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 47 ratio = ratio != "0" ? ratio : ""; 48 string ratioCssClass = ratio != "" ? " ratio" : ""; 49 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 50 51 string width = Model.Item.GetRawValueString("Width", "auto"); 52 int smallImageSize = 640; 53 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 54 55 string ImageObjectFit = Model.Item.GetRawValueString("ImageObjectFit", "contain"); 56 57 string imagePathXs = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 58 string imagePathS = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 59 string imagePathFallBack = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 60 61 var badgeParms = new Dictionary<string, object>(); 62 badgeParms.Add("size", "h7"); 63 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 64 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 65 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 66 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 67 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 68 69 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 70 71 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 72 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 73 bool anonymousUser = Pageview.User == null; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 if (!anonymousUser && showFavoritesSelector) 77 { 78 int defaultFavoriteListId = 0; 79 80 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 81 if (favoreiteLists.Count() == 1) 82 { 83 foreach (FavoriteList list in favoreiteLists) 84 { 85 defaultFavoriteListId = list.ListId; 86 } 87 } 88 89 favoriteParameters.Add("ListId", defaultFavoriteListId); 90 } 91 92 MediaViewModel alternativeImage = new MediaViewModel(); 93 if (Model.Item.GetBoolean("ShowAlternativeImageOnHover")) 94 { 95 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 96 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 97 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 98 alternativeImage = allAssetsImages.FirstOrDefault(); 99 } 100 101 string altImagePathXs = string.Empty; 102 string altImagePathS = string.Empty; 103 104 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 105 { 106 altImagePathXs = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 107 altImagePathS = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 108 } 109 110 @* Theme settings *@ 111 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 112 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 113 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 114 115 string imageId = "ProductImage_" + product.Id + product.VariantId.Replace(".", "_"); 116 117 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 118 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 119 DateTime createdDate = product.Created.Value; 120 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 121 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 122 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) || showComingSoonBadge || showBadges; //CUSTOM 123 124 string fullWidth = width == "auto" ? "w-100" : ""; 125 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 126 127 @* -- CUSTOM -- Added image item prop *@ 128 if (!string.IsNullOrEmpty(imagePath)) 129 { 130 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 131 <div class="ratio" style="@(ratioVariable)"> 132 <div class="d-flex justify-content-center align-items-center"> 133 @* CUSTOM *@ 134 @if (enableBrandLogo) 135 { 136 <img src="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogo)" 137 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoAltText)" 138 class="productdefault-brand-logo" 139 width="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoWidth.ToString())" /> 140 } 141 @* CUSTOM END *@ 142 @if (imagePath.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 143 { 144 <img id="@imageId" 145 itemprop="image" 146 srcset=" 147 @imagePathXs @(smallImageSize)w, 148 @imagePathS @(largeImageSize)w" 149 sizes="(max-width: 992px) 50vw, 25vw" 150 src="@imagePathFallBack" 151 @if (Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 152 data-alternative-image=" 153 @altImagePathXs @(smallImageSize)w, 154 @altImagePathS @(largeImageSize)w" 155 onmouseover="swift.Image.swapImage(event)" 156 onmouseout="swift.Image.swapImage(event)" 157 </text> } 158 loading="lazy" 159 decoding="async" 160 class="h-100 w-100 @themePadding" 161 style="object-fit: @ImageObjectFit; @themeBorder" 162 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 163 } 164 //CUSTOM 165 else if (imagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) 166 { 167 <img id="@imageId" 168 itemprop="image" 169 srcset=" 170 @imagePathXs @(smallImageSize)w, 171 @imagePathS @(largeImageSize)w" 172 sizes="(max-width: 992px) 50vw, 25vw" 173 src="@imagePathFallBack" 174 data-alternative-image=" 175 @altImagePathXs @(smallImageSize)w, 176 @altImagePathS @(largeImageSize)w" 177 onmouseover="swift.Image.swapImage(event)" 178 onmouseout="swift.Image.swapImage(event)" 179 loading="lazy" 180 decoding="async" 181 class="h-100 w-100 @themePadding" 182 style="object-fit: @ImageObjectFit; @themeBorder" 183 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 184 } 185 //--CUSTOM 186 else 187 { 188 <img itemprop="image" 189 src="@product.DefaultImage.Value" 190 loading="lazy" 191 class="h-100 w-100 @themePadding" 192 style="object-fit: contain; @themeBorder" 193 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 194 } 195 </div> 196 </div> 197 198 @if (showBadges) 199 { 200 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 201 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 202 </div> 203 } 204 205 @if (!anonymousUser) 206 { 207 if (showFavoritesSelector) 208 { 209 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 210 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 211 </div> 212 } 213 } 214 </div> 215 } 216 } 217 else if (Pageview.IsVisualEditorMode) 218 { 219 <div class="alert alert-dark m-0">@Translate("No products available")</div> 220 } 221

Liquid Lounge Cocktail muddler

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fb0d18a1de944f3a468232b7643f0eb.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 65
   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.Configuration @*//CUSTOM*@ 3 @using Dynamicweb.Core.Encoders @*//CUSTOM*@ 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 @using System.Globalization 6 @using System.IO @*//CUSTOM*@ 7 8 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 bool productIsDiscontinued = product is object && product.Discontinued; 33 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 34 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 35 } 36 37 @if (product is object && !hidePrice && !isDiscontinued) 38 { 39 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 40 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 41 42 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "h6 justify-content-lg-start"); //CUSTOM 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 45 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 46 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 47 48 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 50 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 51 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 52 53 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 54 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 55 string order = layout == "horizontal" ? string.Empty : "order-2"; 56 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 57 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 61 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 62 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 63 64 //CUSTOM 65 Dictionary<string, FieldValueViewModel> productFields = product.ProductFields; 66 var discountText = ""; 67 bool discountDiscontinued = false; 68 bool discountOnSale = false; 69 70 if (productFields.TryGetValue("Custom_Discontinued", out FieldValueViewModel discontinued)) 71 { 72 var firstValue = (discontinued.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 73 74 if (!string.IsNullOrWhiteSpace(firstValue)) 75 { 76 bool.TryParse(firstValue, out discountDiscontinued); 77 } 78 } 79 80 if (productFields.TryGetValue("Custom_OnSale", out FieldValueViewModel onsale)) 81 { 82 var firstValue = (onsale.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 83 84 if (!string.IsNullOrWhiteSpace(firstValue)) 85 { 86 bool.TryParse(firstValue, out discountOnSale); 87 } 88 } 89 90 if (discountDiscontinued && discountOnSale) 91 { 92 discountText = Translate("Outlet - tilbuddet gælder så længe lager haves"); 93 } 94 else 95 { 96 var discountInfo = Smartpage.EvaSolo.CampaignPrices.Helpers.DiscountHelper.GetDiscountInfo(product); 97 if (discountInfo != null) 98 { 99 discountText = string.Format(Translate(Model.Item.GetRawValueString("Custom_DiscountText", "Tilbuddet gælder {0} - {1}")), $"&zwnj;{discountInfo.ValidFromFormatted}&zwnj;", $"&zwnj;{discountInfo.ValidToFormatted}&zwnj;"); 100 } 101 } 102 string discountType = Model.Item.GetRawValueString("Custom_DiscountType", "none"); 103 string discountTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Custom_DiscountTheme")) ? "theme " + Model.Item.GetRawValueString("Custom_DiscountTheme").Replace(" ", "").Trim().ToLower() : string.Empty; 104 string discountIconColor = Model.Item.GetString("Custom_DiscountIconColor", "text-inherit"); 105 string discountIconSize = Model.Item.GetRawValueString("Custom_DiscountIconSize", "2"); 106 string discountImageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) ? Model.Item.GetFile("Custom_DiscountImage").Path : string.Empty; 107 string discountImagePath = discountImageSrc != string.Empty ? discountImageSrc : Model.Item.GetRawValueString("Custom_DiscountIcon", string.Empty); 108 discountImagePath = Path.GetExtension(discountImagePath).ToLower() != ".svg" ? "/Admin/Public/GetImage.ashx?image=" + discountImagePath + "&height=" + discountIconSize + "&width=" + discountIconSize + "&Crop=0&format=webp" : discountImagePath; 109 string discountImgAltText = Model.Item.GetRawValueString("FeatureAltText", string.Empty); 110 //--CUSTOM 111 112 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 113 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 114 115 string priceMin = ""; 116 string priceMax = ""; 117 118 string liveInfoClass = ""; 119 string productInfoFeed = ""; 120 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 121 if (isLazyLoadingForProductInfoEnabled) 122 { 123 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 124 { 125 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 126 if (!string.IsNullOrEmpty(productInfoFeed)) 127 { 128 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 129 } 130 } 131 liveInfoClass = "js-live-info"; 132 } 133 134 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 135 @if (showInformativePrice && product.PriceInformative.Price != 0) 136 { 137 <div class="opacity-50"> 138 <span>@Translate("RRP") </span> 139 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 140 </div> 141 } 142 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 143 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 144 145 @*//CUSTOM*@ 146 @if (showPricesWithVat == "false" && !neverShowVat) 147 { 148 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 149 { 150 <span class="text-price js-text-price"> 151 <span class="spinner-border" role="status"></span> 152 </span> 153 } 154 else 155 { 156 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 157 158 if (product?.VariantInfo?.VariantInfo != null) 159 { 160 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 161 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 162 } 163 if (priceMin != priceMax) 164 { 165 price = priceMin + " - " + priceMax; 166 } 167 168 <span class="@theme"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 195 <span class="@theme"> 196 <span class="text-price">@price</span> 197 </span> 198 } 199 } 200 201 @if (showPricesWithVat == "false" && !neverShowVat) 202 { 203 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 204 { 205 <span itemprop="price" content="" class="d-none"></span> 206 <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> 207 } 208 else 209 { 210 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 211 212 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 213 214 if (product.Price.Price != product.PriceBeforeDiscount.Price) 215 { 216 <span class="opacity-75 @(order)"> 217 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 218 </span> 219 220 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 221 { 222 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 223 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 224 { 225 PriceWithoutVAT = (product.PriceBeforeDiscount.PriceWithoutVat - product.Price.PriceWithoutVat) 226 }; 227 228 <span class="d-none d-sm-inline opacity-75 @(order)"> 229 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceWithoutVATFormatted)</span> 230 </span> 231 } 232 } 233 } 234 } 235 else 236 { 237 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 238 { 239 <span itemprop="price" content="" class="d-none"></span> 240 <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> 241 } 242 else 243 { 244 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 245 246 <span itemprop="price" content="@product.Price.Price.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 247 248 if (product.Price.Price < product.PriceBeforeDiscount.Price) 249 { 250 <span class="opacity-75 @(order)"> 251 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 252 </span> 253 254 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 255 { 256 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 257 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 258 { 259 PriceWithVAT = (product.PriceBeforeDiscount.Price - product.Price.Price) 260 }; 261 262 <span class="d-none d-sm-inline opacity-75 @(order)"> 263 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceFormatted)</span> 264 </span> 265 } 266 } 267 } 268 } 269 @*//--CUSTOM*@ 270 271 @*//CUSTOM*@ 272 @if (discountType == "icon-tooltip" && product.Price.Price != product.PriceBeforeDiscount.Price && discountText != null) 273 { 274 if ((!string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) || !discountImagePath.ToLower().Contains("none")) && discountImagePath != string.Empty) 275 { 276 <span data-bs-toggle="tooltip" data-bs-custom-class="@(discountTheme)" data-bs-html="true" data-bs-title="@HtmlEncoder.HtmlAttributeEncode(discountText)" data-bs-custom-prevent-event="click" data-bs-custom-click-close-delay="2000"> 277 @if (Path.GetExtension(discountImagePath).ToLower() == ".svg") 278 { 279 <span class="icon-auto @(discountIconColor)" style="vertical-align:text-top;height:@(discountIconSize)px;width:@(discountIconSize)px;">@ReadFile(discountImagePath)</span> 280 } 281 else 282 { 283 <img loading="lazy" src="@(discountImagePath)" alt="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" title="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" style="height:@(discountIconSize)px;width:@(discountIconSize)px;"> 284 } 285 </span> 286 } 287 } 288 @*//--CUSTOM*@ 289 290 @* Stock state for Schema.org, start *@ 291 @{ 292 Uri url = Dynamicweb.Context.Current.Request.Url; 293 } 294 295 <link itemprop="url" href="@url"> 296 297 @{ 298 bool IsNeverOutOfStock = product.NeverOutOfstock; 299 } 300 301 @if (IsNeverOutOfStock) 302 { 303 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 304 } 305 else 306 { 307 if (product.StockLevel > 0) 308 { 309 <span itemprop="availability" class="d-none">InStock</span> 310 } 311 else 312 { 313 <span itemprop="availability" class="d-none">OutOfStock</span> 314 } 315 } 316 @* Stock state for Schema.org, stop *@ 317 318 </div> 319 320 @if (showPricesWithVat == "false" && !neverShowVat) 321 { 322 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 323 { 324 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 325 } 326 else 327 { 328 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 329 330 if (product?.VariantInfo?.VariantInfo != null) 331 { 332 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 333 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 334 } 335 if (priceMin != priceMax) 336 { 337 price = priceMin + " - " + priceMax; 338 } 339 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 340 } 341 } 342 343 @*//CUSTOM*@ 344 @if (discountType == "inline" && product.Price.Price != product.PriceBeforeDiscount.Price && !string.IsNullOrEmpty(discountText)) 345 { 346 var discountFontSize = priceFontSize.Contains("h6") ? priceFontSize.Replace("h6", "small") : "small"; 347 348 <div class="@(discountFontSize) mt-1 d-flex flex-wrap @(flexDirection) @(horizontalAlign)"> 349 @discountText 350 </div> 351 } 352 @*//--CUSTOM*@ 353 354 </div> 355 } 356 else if (Pageview.IsVisualEditorMode) 357 { 358 <div class="alert alert-dark m-0" role="alert"> 359 <span>@Translate("No products available")</span> 360 </div> 361 } 362
Error executing template "Designs/Swift/Paragraph/Swift_ProductBadges_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_fe4e63c166214874a0bcb86da4f14f88.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBadges_Custom.cshtml:line 27
   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 System 3 @using System.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Content 7 @using Dynamicweb.Core 8 @using Dynamicweb.Ecommerce.ProductCatalog 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 28 DateTime currentDate = DateTime.Today; 29 bool showComingSoonBadge = currentDate < launchDate && string.Equals( Model.Item.GetRawValueString("NewBadgeDesign"), "comingsoon", StringComparison.InvariantCultureIgnoreCase ); 30 } 31 32 @if (product is object) 33 { 34 var badgeParms = new Dictionary<string, object>(); 35 badgeParms.Add("size", "h7"); 36 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 37 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 38 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 39 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 40 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 41 42 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 46 47 Dictionary<string, ParagraphInfoViewModel> badgeConfigurations; 48 List<string> campaignBadgesValues = Model.Item.GetRawValueString("CampaignBadges") != null ? Model.Item.GetRawValueString("CampaignBadges").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>(); 49 50 if (Dynamicweb.Context.Current.Items.Contains("badgeConfigurations")) 51 { 52 badgeConfigurations = (Dictionary<string, ParagraphInfoViewModel>)Dynamicweb.Context.Current.Items["badgeConfigurations"]; 53 } 54 else 55 { 56 var badgesPage = Pageview.AreaSettings.GetLink("EcommerceBadgesPage") != null ? Pageview.AreaSettings.GetLink("EcommerceBadgesPage").PageId : 0; 57 var allBadges = badgesPage != 0 ? Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(badgesPage) : null; 58 59 badgeConfigurations = new Dictionary<string, ParagraphInfoViewModel>(); 60 61 if ( allBadges != null ) 62 { 63 foreach ( Paragraph badge in allBadges ) 64 { 65 var paragraphviewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel( badge ); 66 string cssClassName = paragraphviewModel.Item.GetString( "CssClassName" )?.Trim().ToLower() ?? string.Empty;; 67 if ( !badgeConfigurations.ContainsKey( cssClassName ) ) 68 { 69 badgeConfigurations.Add( cssClassName, paragraphviewModel ); 70 } 71 } 72 } 73 74 Dynamicweb.Context.Current.Items.Add("badgeConfigurations", badgeConfigurations); 75 } 76 77 int badgesCount = 0; 78 if (badgeConfigurations.Any()) 79 { 80 foreach (string campaign in campaignBadgesValues) 81 { 82 if (!string.IsNullOrEmpty(campaign)) 83 { 84 FieldValueViewModel availableCampaignsObject; 85 product.ProductFields.TryGetValue("Campaign", out availableCampaignsObject); 86 87 if (availableCampaignsObject != null) 88 { 89 string campaignType = string.Empty; 90 91 if (badgeConfigurations.ContainsKey(campaign)) 92 { 93 ParagraphInfoViewModel paragraphviewModel; 94 if (badgeConfigurations.TryGetValue(campaign, out paragraphviewModel)) 95 { 96 campaignType = paragraphviewModel.Item.GetRawValueString("CampaignType"); 97 } 98 } 99 100 List<FieldOptionValueViewModel> availableCampaigns = (List<FieldOptionValueViewModel>)availableCampaignsObject.Value; 101 102 foreach (FieldOptionValueViewModel availableOption in availableCampaigns) 103 { 104 if (campaignType == availableOption.Value) 105 { 106 badgesCount++; 107 break; 108 } 109 } 110 } 111 } 112 } 113 } 114 115 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 116 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 117 DateTime createdDate = product.Created.Value; 118 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 119 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 120 showBadges = (!string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) && badgesCount != 0) || showComingSoonBadge || showBadges; 121 122 if (showBadges) 123 { 124 <div class="@badgeSize @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 125 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 126 </div> 127 } 128 else if (Pageview.IsVisualEditorMode) 129 { 130 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 131 } 132 } 133 else if (Pageview.IsVisualEditorMode) 134 { 135 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 136 } 137 138
Dekanteringskaraffel med køleelement - 0,75 L
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_160448cdee3c46a18a7a094dcad8bbe9.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage_Custom.cshtml:line 32
   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 System @*//CUSTOM*@ 3 @using System.Collections.Generic @*//CUSTOM*@ 4 @using System.Linq @*//CUSTOM*@ 5 @using Dynamicweb.Core @*//CUSTOM*@ 6 @using Dynamicweb.Ecommerce.ProductCatalog 7 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 10 11 @{ 12 ProductViewModel product = null; 13 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 14 { 15 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 16 } 17 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 18 { 19 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 20 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 21 22 if (productList?.Products is object) 23 { 24 product = productList.Products[0]; 25 } 26 } 27 } 28 29 @if (product is object) 30 { 31 //CUSTOM 32 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 33 DateTime currentDate = DateTime.Today; 34 bool showComingSoonBadge = currentDate < launchDate; 35 string brandLogo = Model.Item.GetString("Custom_BrandLogo"); 36 string brandLogoKey = Model.Item.GetString("Custom_BrandLogoKey"); 37 string brandLogoAltText = Model.Item.GetString("Custom_BrandAltText"); 38 int brandLogoWidth = Model.Item.GetInt32("Custom_BrandLogoWidth") > 0 ? Model.Item.GetInt32("Custom_BrandLogoWidth") : 70; 39 string productBrand = product.ProductFields.ContainsKey("Custom_Brand") ? Converter.ToString(product.ProductFields["Custom_Brand"].Value) : ""; 40 bool enableBrandLogo = !string.IsNullOrEmpty(brandLogo) && !string.IsNullOrEmpty(brandLogoKey) && brandLogoKey == productBrand; 41 //--CUSTOM 42 43 string imagePath = product?.DefaultImage?.Value ?? ""; 44 string imagePathUrlEncoded = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 45 46 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 47 ratio = ratio != "0" ? ratio : ""; 48 string ratioCssClass = ratio != "" ? " ratio" : ""; 49 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 50 51 string width = Model.Item.GetRawValueString("Width", "auto"); 52 int smallImageSize = 640; 53 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 54 55 string ImageObjectFit = Model.Item.GetRawValueString("ImageObjectFit", "contain"); 56 57 string imagePathXs = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 58 string imagePathS = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 59 string imagePathFallBack = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 60 61 var badgeParms = new Dictionary<string, object>(); 62 badgeParms.Add("size", "h7"); 63 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 64 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 65 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 66 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 67 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 68 69 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 70 71 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 72 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 73 bool anonymousUser = Pageview.User == null; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 if (!anonymousUser && showFavoritesSelector) 77 { 78 int defaultFavoriteListId = 0; 79 80 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 81 if (favoreiteLists.Count() == 1) 82 { 83 foreach (FavoriteList list in favoreiteLists) 84 { 85 defaultFavoriteListId = list.ListId; 86 } 87 } 88 89 favoriteParameters.Add("ListId", defaultFavoriteListId); 90 } 91 92 MediaViewModel alternativeImage = new MediaViewModel(); 93 if (Model.Item.GetBoolean("ShowAlternativeImageOnHover")) 94 { 95 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 96 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 97 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 98 alternativeImage = allAssetsImages.FirstOrDefault(); 99 } 100 101 string altImagePathXs = string.Empty; 102 string altImagePathS = string.Empty; 103 104 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 105 { 106 altImagePathXs = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 107 altImagePathS = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 108 } 109 110 @* Theme settings *@ 111 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 112 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 113 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 114 115 string imageId = "ProductImage_" + product.Id + product.VariantId.Replace(".", "_"); 116 117 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 118 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 119 DateTime createdDate = product.Created.Value; 120 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 121 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 122 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) || showComingSoonBadge || showBadges; //CUSTOM 123 124 string fullWidth = width == "auto" ? "w-100" : ""; 125 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 126 127 @* -- CUSTOM -- Added image item prop *@ 128 if (!string.IsNullOrEmpty(imagePath)) 129 { 130 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 131 <div class="ratio" style="@(ratioVariable)"> 132 <div class="d-flex justify-content-center align-items-center"> 133 @* CUSTOM *@ 134 @if (enableBrandLogo) 135 { 136 <img src="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogo)" 137 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoAltText)" 138 class="productdefault-brand-logo" 139 width="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoWidth.ToString())" /> 140 } 141 @* CUSTOM END *@ 142 @if (imagePath.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 143 { 144 <img id="@imageId" 145 itemprop="image" 146 srcset=" 147 @imagePathXs @(smallImageSize)w, 148 @imagePathS @(largeImageSize)w" 149 sizes="(max-width: 992px) 50vw, 25vw" 150 src="@imagePathFallBack" 151 @if (Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 152 data-alternative-image=" 153 @altImagePathXs @(smallImageSize)w, 154 @altImagePathS @(largeImageSize)w" 155 onmouseover="swift.Image.swapImage(event)" 156 onmouseout="swift.Image.swapImage(event)" 157 </text> } 158 loading="lazy" 159 decoding="async" 160 class="h-100 w-100 @themePadding" 161 style="object-fit: @ImageObjectFit; @themeBorder" 162 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 163 } 164 //CUSTOM 165 else if (imagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) 166 { 167 <img id="@imageId" 168 itemprop="image" 169 srcset=" 170 @imagePathXs @(smallImageSize)w, 171 @imagePathS @(largeImageSize)w" 172 sizes="(max-width: 992px) 50vw, 25vw" 173 src="@imagePathFallBack" 174 data-alternative-image=" 175 @altImagePathXs @(smallImageSize)w, 176 @altImagePathS @(largeImageSize)w" 177 onmouseover="swift.Image.swapImage(event)" 178 onmouseout="swift.Image.swapImage(event)" 179 loading="lazy" 180 decoding="async" 181 class="h-100 w-100 @themePadding" 182 style="object-fit: @ImageObjectFit; @themeBorder" 183 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 184 } 185 //--CUSTOM 186 else 187 { 188 <img itemprop="image" 189 src="@product.DefaultImage.Value" 190 loading="lazy" 191 class="h-100 w-100 @themePadding" 192 style="object-fit: contain; @themeBorder" 193 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 194 } 195 </div> 196 </div> 197 198 @if (showBadges) 199 { 200 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 201 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 202 </div> 203 } 204 205 @if (!anonymousUser) 206 { 207 if (showFavoritesSelector) 208 { 209 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 210 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 211 </div> 212 } 213 } 214 </div> 215 } 216 } 217 else if (Pageview.IsVisualEditorMode) 218 { 219 <div class="alert alert-dark m-0">@Translate("No products available")</div> 220 } 221

Dekanteringskaraffel med køleelement - 0,75 L

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fb0d18a1de944f3a468232b7643f0eb.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 65
   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.Configuration @*//CUSTOM*@ 3 @using Dynamicweb.Core.Encoders @*//CUSTOM*@ 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 @using System.Globalization 6 @using System.IO @*//CUSTOM*@ 7 8 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 bool productIsDiscontinued = product is object && product.Discontinued; 33 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 34 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 35 } 36 37 @if (product is object && !hidePrice && !isDiscontinued) 38 { 39 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 40 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 41 42 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "h6 justify-content-lg-start"); //CUSTOM 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 45 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 46 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 47 48 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 50 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 51 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 52 53 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 54 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 55 string order = layout == "horizontal" ? string.Empty : "order-2"; 56 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 57 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 61 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 62 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 63 64 //CUSTOM 65 Dictionary<string, FieldValueViewModel> productFields = product.ProductFields; 66 var discountText = ""; 67 bool discountDiscontinued = false; 68 bool discountOnSale = false; 69 70 if (productFields.TryGetValue("Custom_Discontinued", out FieldValueViewModel discontinued)) 71 { 72 var firstValue = (discontinued.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 73 74 if (!string.IsNullOrWhiteSpace(firstValue)) 75 { 76 bool.TryParse(firstValue, out discountDiscontinued); 77 } 78 } 79 80 if (productFields.TryGetValue("Custom_OnSale", out FieldValueViewModel onsale)) 81 { 82 var firstValue = (onsale.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 83 84 if (!string.IsNullOrWhiteSpace(firstValue)) 85 { 86 bool.TryParse(firstValue, out discountOnSale); 87 } 88 } 89 90 if (discountDiscontinued && discountOnSale) 91 { 92 discountText = Translate("Outlet - tilbuddet gælder så længe lager haves"); 93 } 94 else 95 { 96 var discountInfo = Smartpage.EvaSolo.CampaignPrices.Helpers.DiscountHelper.GetDiscountInfo(product); 97 if (discountInfo != null) 98 { 99 discountText = string.Format(Translate(Model.Item.GetRawValueString("Custom_DiscountText", "Tilbuddet gælder {0} - {1}")), $"&zwnj;{discountInfo.ValidFromFormatted}&zwnj;", $"&zwnj;{discountInfo.ValidToFormatted}&zwnj;"); 100 } 101 } 102 string discountType = Model.Item.GetRawValueString("Custom_DiscountType", "none"); 103 string discountTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Custom_DiscountTheme")) ? "theme " + Model.Item.GetRawValueString("Custom_DiscountTheme").Replace(" ", "").Trim().ToLower() : string.Empty; 104 string discountIconColor = Model.Item.GetString("Custom_DiscountIconColor", "text-inherit"); 105 string discountIconSize = Model.Item.GetRawValueString("Custom_DiscountIconSize", "2"); 106 string discountImageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) ? Model.Item.GetFile("Custom_DiscountImage").Path : string.Empty; 107 string discountImagePath = discountImageSrc != string.Empty ? discountImageSrc : Model.Item.GetRawValueString("Custom_DiscountIcon", string.Empty); 108 discountImagePath = Path.GetExtension(discountImagePath).ToLower() != ".svg" ? "/Admin/Public/GetImage.ashx?image=" + discountImagePath + "&height=" + discountIconSize + "&width=" + discountIconSize + "&Crop=0&format=webp" : discountImagePath; 109 string discountImgAltText = Model.Item.GetRawValueString("FeatureAltText", string.Empty); 110 //--CUSTOM 111 112 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 113 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 114 115 string priceMin = ""; 116 string priceMax = ""; 117 118 string liveInfoClass = ""; 119 string productInfoFeed = ""; 120 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 121 if (isLazyLoadingForProductInfoEnabled) 122 { 123 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 124 { 125 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 126 if (!string.IsNullOrEmpty(productInfoFeed)) 127 { 128 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 129 } 130 } 131 liveInfoClass = "js-live-info"; 132 } 133 134 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 135 @if (showInformativePrice && product.PriceInformative.Price != 0) 136 { 137 <div class="opacity-50"> 138 <span>@Translate("RRP") </span> 139 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 140 </div> 141 } 142 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 143 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 144 145 @*//CUSTOM*@ 146 @if (showPricesWithVat == "false" && !neverShowVat) 147 { 148 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 149 { 150 <span class="text-price js-text-price"> 151 <span class="spinner-border" role="status"></span> 152 </span> 153 } 154 else 155 { 156 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 157 158 if (product?.VariantInfo?.VariantInfo != null) 159 { 160 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 161 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 162 } 163 if (priceMin != priceMax) 164 { 165 price = priceMin + " - " + priceMax; 166 } 167 168 <span class="@theme"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 195 <span class="@theme"> 196 <span class="text-price">@price</span> 197 </span> 198 } 199 } 200 201 @if (showPricesWithVat == "false" && !neverShowVat) 202 { 203 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 204 { 205 <span itemprop="price" content="" class="d-none"></span> 206 <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> 207 } 208 else 209 { 210 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 211 212 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 213 214 if (product.Price.Price != product.PriceBeforeDiscount.Price) 215 { 216 <span class="opacity-75 @(order)"> 217 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 218 </span> 219 220 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 221 { 222 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 223 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 224 { 225 PriceWithoutVAT = (product.PriceBeforeDiscount.PriceWithoutVat - product.Price.PriceWithoutVat) 226 }; 227 228 <span class="d-none d-sm-inline opacity-75 @(order)"> 229 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceWithoutVATFormatted)</span> 230 </span> 231 } 232 } 233 } 234 } 235 else 236 { 237 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 238 { 239 <span itemprop="price" content="" class="d-none"></span> 240 <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> 241 } 242 else 243 { 244 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 245 246 <span itemprop="price" content="@product.Price.Price.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 247 248 if (product.Price.Price < product.PriceBeforeDiscount.Price) 249 { 250 <span class="opacity-75 @(order)"> 251 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 252 </span> 253 254 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 255 { 256 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 257 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 258 { 259 PriceWithVAT = (product.PriceBeforeDiscount.Price - product.Price.Price) 260 }; 261 262 <span class="d-none d-sm-inline opacity-75 @(order)"> 263 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceFormatted)</span> 264 </span> 265 } 266 } 267 } 268 } 269 @*//--CUSTOM*@ 270 271 @*//CUSTOM*@ 272 @if (discountType == "icon-tooltip" && product.Price.Price != product.PriceBeforeDiscount.Price && discountText != null) 273 { 274 if ((!string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) || !discountImagePath.ToLower().Contains("none")) && discountImagePath != string.Empty) 275 { 276 <span data-bs-toggle="tooltip" data-bs-custom-class="@(discountTheme)" data-bs-html="true" data-bs-title="@HtmlEncoder.HtmlAttributeEncode(discountText)" data-bs-custom-prevent-event="click" data-bs-custom-click-close-delay="2000"> 277 @if (Path.GetExtension(discountImagePath).ToLower() == ".svg") 278 { 279 <span class="icon-auto @(discountIconColor)" style="vertical-align:text-top;height:@(discountIconSize)px;width:@(discountIconSize)px;">@ReadFile(discountImagePath)</span> 280 } 281 else 282 { 283 <img loading="lazy" src="@(discountImagePath)" alt="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" title="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" style="height:@(discountIconSize)px;width:@(discountIconSize)px;"> 284 } 285 </span> 286 } 287 } 288 @*//--CUSTOM*@ 289 290 @* Stock state for Schema.org, start *@ 291 @{ 292 Uri url = Dynamicweb.Context.Current.Request.Url; 293 } 294 295 <link itemprop="url" href="@url"> 296 297 @{ 298 bool IsNeverOutOfStock = product.NeverOutOfstock; 299 } 300 301 @if (IsNeverOutOfStock) 302 { 303 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 304 } 305 else 306 { 307 if (product.StockLevel > 0) 308 { 309 <span itemprop="availability" class="d-none">InStock</span> 310 } 311 else 312 { 313 <span itemprop="availability" class="d-none">OutOfStock</span> 314 } 315 } 316 @* Stock state for Schema.org, stop *@ 317 318 </div> 319 320 @if (showPricesWithVat == "false" && !neverShowVat) 321 { 322 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 323 { 324 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 325 } 326 else 327 { 328 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 329 330 if (product?.VariantInfo?.VariantInfo != null) 331 { 332 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 333 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 334 } 335 if (priceMin != priceMax) 336 { 337 price = priceMin + " - " + priceMax; 338 } 339 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 340 } 341 } 342 343 @*//CUSTOM*@ 344 @if (discountType == "inline" && product.Price.Price != product.PriceBeforeDiscount.Price && !string.IsNullOrEmpty(discountText)) 345 { 346 var discountFontSize = priceFontSize.Contains("h6") ? priceFontSize.Replace("h6", "small") : "small"; 347 348 <div class="@(discountFontSize) mt-1 d-flex flex-wrap @(flexDirection) @(horizontalAlign)"> 349 @discountText 350 </div> 351 } 352 @*//--CUSTOM*@ 353 354 </div> 355 } 356 else if (Pageview.IsVisualEditorMode) 357 { 358 <div class="alert alert-dark m-0" role="alert"> 359 <span>@Translate("No products available")</span> 360 </div> 361 } 362
Error executing template "Designs/Swift/Paragraph/Swift_ProductBadges_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_fe4e63c166214874a0bcb86da4f14f88.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBadges_Custom.cshtml:line 27
   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 System 3 @using System.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Content 7 @using Dynamicweb.Core 8 @using Dynamicweb.Ecommerce.ProductCatalog 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 28 DateTime currentDate = DateTime.Today; 29 bool showComingSoonBadge = currentDate < launchDate && string.Equals( Model.Item.GetRawValueString("NewBadgeDesign"), "comingsoon", StringComparison.InvariantCultureIgnoreCase ); 30 } 31 32 @if (product is object) 33 { 34 var badgeParms = new Dictionary<string, object>(); 35 badgeParms.Add("size", "h7"); 36 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 37 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 38 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 39 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 40 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 41 42 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 46 47 Dictionary<string, ParagraphInfoViewModel> badgeConfigurations; 48 List<string> campaignBadgesValues = Model.Item.GetRawValueString("CampaignBadges") != null ? Model.Item.GetRawValueString("CampaignBadges").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>(); 49 50 if (Dynamicweb.Context.Current.Items.Contains("badgeConfigurations")) 51 { 52 badgeConfigurations = (Dictionary<string, ParagraphInfoViewModel>)Dynamicweb.Context.Current.Items["badgeConfigurations"]; 53 } 54 else 55 { 56 var badgesPage = Pageview.AreaSettings.GetLink("EcommerceBadgesPage") != null ? Pageview.AreaSettings.GetLink("EcommerceBadgesPage").PageId : 0; 57 var allBadges = badgesPage != 0 ? Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(badgesPage) : null; 58 59 badgeConfigurations = new Dictionary<string, ParagraphInfoViewModel>(); 60 61 if ( allBadges != null ) 62 { 63 foreach ( Paragraph badge in allBadges ) 64 { 65 var paragraphviewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel( badge ); 66 string cssClassName = paragraphviewModel.Item.GetString( "CssClassName" )?.Trim().ToLower() ?? string.Empty;; 67 if ( !badgeConfigurations.ContainsKey( cssClassName ) ) 68 { 69 badgeConfigurations.Add( cssClassName, paragraphviewModel ); 70 } 71 } 72 } 73 74 Dynamicweb.Context.Current.Items.Add("badgeConfigurations", badgeConfigurations); 75 } 76 77 int badgesCount = 0; 78 if (badgeConfigurations.Any()) 79 { 80 foreach (string campaign in campaignBadgesValues) 81 { 82 if (!string.IsNullOrEmpty(campaign)) 83 { 84 FieldValueViewModel availableCampaignsObject; 85 product.ProductFields.TryGetValue("Campaign", out availableCampaignsObject); 86 87 if (availableCampaignsObject != null) 88 { 89 string campaignType = string.Empty; 90 91 if (badgeConfigurations.ContainsKey(campaign)) 92 { 93 ParagraphInfoViewModel paragraphviewModel; 94 if (badgeConfigurations.TryGetValue(campaign, out paragraphviewModel)) 95 { 96 campaignType = paragraphviewModel.Item.GetRawValueString("CampaignType"); 97 } 98 } 99 100 List<FieldOptionValueViewModel> availableCampaigns = (List<FieldOptionValueViewModel>)availableCampaignsObject.Value; 101 102 foreach (FieldOptionValueViewModel availableOption in availableCampaigns) 103 { 104 if (campaignType == availableOption.Value) 105 { 106 badgesCount++; 107 break; 108 } 109 } 110 } 111 } 112 } 113 } 114 115 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 116 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 117 DateTime createdDate = product.Created.Value; 118 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 119 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 120 showBadges = (!string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) && badgesCount != 0) || showComingSoonBadge || showBadges; 121 122 if (showBadges) 123 { 124 <div class="@badgeSize @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 125 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 126 </div> 127 } 128 else if (Pageview.IsVisualEditorMode) 129 { 130 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 131 } 132 } 133 else if (Pageview.IsVisualEditorMode) 134 { 135 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 136 } 137 138
Dekanteringskaraffel - 0.75 L - Mundblæst glas
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_160448cdee3c46a18a7a094dcad8bbe9.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage_Custom.cshtml:line 32
   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 System @*//CUSTOM*@ 3 @using System.Collections.Generic @*//CUSTOM*@ 4 @using System.Linq @*//CUSTOM*@ 5 @using Dynamicweb.Core @*//CUSTOM*@ 6 @using Dynamicweb.Ecommerce.ProductCatalog 7 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 10 11 @{ 12 ProductViewModel product = null; 13 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 14 { 15 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 16 } 17 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 18 { 19 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 20 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 21 22 if (productList?.Products is object) 23 { 24 product = productList.Products[0]; 25 } 26 } 27 } 28 29 @if (product is object) 30 { 31 //CUSTOM 32 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 33 DateTime currentDate = DateTime.Today; 34 bool showComingSoonBadge = currentDate < launchDate; 35 string brandLogo = Model.Item.GetString("Custom_BrandLogo"); 36 string brandLogoKey = Model.Item.GetString("Custom_BrandLogoKey"); 37 string brandLogoAltText = Model.Item.GetString("Custom_BrandAltText"); 38 int brandLogoWidth = Model.Item.GetInt32("Custom_BrandLogoWidth") > 0 ? Model.Item.GetInt32("Custom_BrandLogoWidth") : 70; 39 string productBrand = product.ProductFields.ContainsKey("Custom_Brand") ? Converter.ToString(product.ProductFields["Custom_Brand"].Value) : ""; 40 bool enableBrandLogo = !string.IsNullOrEmpty(brandLogo) && !string.IsNullOrEmpty(brandLogoKey) && brandLogoKey == productBrand; 41 //--CUSTOM 42 43 string imagePath = product?.DefaultImage?.Value ?? ""; 44 string imagePathUrlEncoded = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 45 46 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 47 ratio = ratio != "0" ? ratio : ""; 48 string ratioCssClass = ratio != "" ? " ratio" : ""; 49 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 50 51 string width = Model.Item.GetRawValueString("Width", "auto"); 52 int smallImageSize = 640; 53 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 54 55 string ImageObjectFit = Model.Item.GetRawValueString("ImageObjectFit", "contain"); 56 57 string imagePathXs = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 58 string imagePathS = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 59 string imagePathFallBack = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 60 61 var badgeParms = new Dictionary<string, object>(); 62 badgeParms.Add("size", "h7"); 63 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 64 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 65 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 66 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 67 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 68 69 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 70 71 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 72 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 73 bool anonymousUser = Pageview.User == null; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 if (!anonymousUser && showFavoritesSelector) 77 { 78 int defaultFavoriteListId = 0; 79 80 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 81 if (favoreiteLists.Count() == 1) 82 { 83 foreach (FavoriteList list in favoreiteLists) 84 { 85 defaultFavoriteListId = list.ListId; 86 } 87 } 88 89 favoriteParameters.Add("ListId", defaultFavoriteListId); 90 } 91 92 MediaViewModel alternativeImage = new MediaViewModel(); 93 if (Model.Item.GetBoolean("ShowAlternativeImageOnHover")) 94 { 95 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 96 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 97 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 98 alternativeImage = allAssetsImages.FirstOrDefault(); 99 } 100 101 string altImagePathXs = string.Empty; 102 string altImagePathS = string.Empty; 103 104 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 105 { 106 altImagePathXs = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 107 altImagePathS = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 108 } 109 110 @* Theme settings *@ 111 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 112 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 113 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 114 115 string imageId = "ProductImage_" + product.Id + product.VariantId.Replace(".", "_"); 116 117 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 118 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 119 DateTime createdDate = product.Created.Value; 120 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 121 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 122 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) || showComingSoonBadge || showBadges; //CUSTOM 123 124 string fullWidth = width == "auto" ? "w-100" : ""; 125 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 126 127 @* -- CUSTOM -- Added image item prop *@ 128 if (!string.IsNullOrEmpty(imagePath)) 129 { 130 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 131 <div class="ratio" style="@(ratioVariable)"> 132 <div class="d-flex justify-content-center align-items-center"> 133 @* CUSTOM *@ 134 @if (enableBrandLogo) 135 { 136 <img src="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogo)" 137 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoAltText)" 138 class="productdefault-brand-logo" 139 width="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoWidth.ToString())" /> 140 } 141 @* CUSTOM END *@ 142 @if (imagePath.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 143 { 144 <img id="@imageId" 145 itemprop="image" 146 srcset=" 147 @imagePathXs @(smallImageSize)w, 148 @imagePathS @(largeImageSize)w" 149 sizes="(max-width: 992px) 50vw, 25vw" 150 src="@imagePathFallBack" 151 @if (Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 152 data-alternative-image=" 153 @altImagePathXs @(smallImageSize)w, 154 @altImagePathS @(largeImageSize)w" 155 onmouseover="swift.Image.swapImage(event)" 156 onmouseout="swift.Image.swapImage(event)" 157 </text> } 158 loading="lazy" 159 decoding="async" 160 class="h-100 w-100 @themePadding" 161 style="object-fit: @ImageObjectFit; @themeBorder" 162 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 163 } 164 //CUSTOM 165 else if (imagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) 166 { 167 <img id="@imageId" 168 itemprop="image" 169 srcset=" 170 @imagePathXs @(smallImageSize)w, 171 @imagePathS @(largeImageSize)w" 172 sizes="(max-width: 992px) 50vw, 25vw" 173 src="@imagePathFallBack" 174 data-alternative-image=" 175 @altImagePathXs @(smallImageSize)w, 176 @altImagePathS @(largeImageSize)w" 177 onmouseover="swift.Image.swapImage(event)" 178 onmouseout="swift.Image.swapImage(event)" 179 loading="lazy" 180 decoding="async" 181 class="h-100 w-100 @themePadding" 182 style="object-fit: @ImageObjectFit; @themeBorder" 183 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 184 } 185 //--CUSTOM 186 else 187 { 188 <img itemprop="image" 189 src="@product.DefaultImage.Value" 190 loading="lazy" 191 class="h-100 w-100 @themePadding" 192 style="object-fit: contain; @themeBorder" 193 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 194 } 195 </div> 196 </div> 197 198 @if (showBadges) 199 { 200 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 201 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 202 </div> 203 } 204 205 @if (!anonymousUser) 206 { 207 if (showFavoritesSelector) 208 { 209 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 210 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 211 </div> 212 } 213 } 214 </div> 215 } 216 } 217 else if (Pageview.IsVisualEditorMode) 218 { 219 <div class="alert alert-dark m-0">@Translate("No products available")</div> 220 } 221

Dekanteringskaraffel - 0.75 L - Mundblæst glas

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fb0d18a1de944f3a468232b7643f0eb.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 65
   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.Configuration @*//CUSTOM*@ 3 @using Dynamicweb.Core.Encoders @*//CUSTOM*@ 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 @using System.Globalization 6 @using System.IO @*//CUSTOM*@ 7 8 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 bool productIsDiscontinued = product is object && product.Discontinued; 33 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 34 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 35 } 36 37 @if (product is object && !hidePrice && !isDiscontinued) 38 { 39 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 40 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 41 42 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "h6 justify-content-lg-start"); //CUSTOM 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 45 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 46 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 47 48 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 50 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 51 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 52 53 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 54 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 55 string order = layout == "horizontal" ? string.Empty : "order-2"; 56 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 57 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 61 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 62 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 63 64 //CUSTOM 65 Dictionary<string, FieldValueViewModel> productFields = product.ProductFields; 66 var discountText = ""; 67 bool discountDiscontinued = false; 68 bool discountOnSale = false; 69 70 if (productFields.TryGetValue("Custom_Discontinued", out FieldValueViewModel discontinued)) 71 { 72 var firstValue = (discontinued.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 73 74 if (!string.IsNullOrWhiteSpace(firstValue)) 75 { 76 bool.TryParse(firstValue, out discountDiscontinued); 77 } 78 } 79 80 if (productFields.TryGetValue("Custom_OnSale", out FieldValueViewModel onsale)) 81 { 82 var firstValue = (onsale.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 83 84 if (!string.IsNullOrWhiteSpace(firstValue)) 85 { 86 bool.TryParse(firstValue, out discountOnSale); 87 } 88 } 89 90 if (discountDiscontinued && discountOnSale) 91 { 92 discountText = Translate("Outlet - tilbuddet gælder så længe lager haves"); 93 } 94 else 95 { 96 var discountInfo = Smartpage.EvaSolo.CampaignPrices.Helpers.DiscountHelper.GetDiscountInfo(product); 97 if (discountInfo != null) 98 { 99 discountText = string.Format(Translate(Model.Item.GetRawValueString("Custom_DiscountText", "Tilbuddet gælder {0} - {1}")), $"&zwnj;{discountInfo.ValidFromFormatted}&zwnj;", $"&zwnj;{discountInfo.ValidToFormatted}&zwnj;"); 100 } 101 } 102 string discountType = Model.Item.GetRawValueString("Custom_DiscountType", "none"); 103 string discountTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Custom_DiscountTheme")) ? "theme " + Model.Item.GetRawValueString("Custom_DiscountTheme").Replace(" ", "").Trim().ToLower() : string.Empty; 104 string discountIconColor = Model.Item.GetString("Custom_DiscountIconColor", "text-inherit"); 105 string discountIconSize = Model.Item.GetRawValueString("Custom_DiscountIconSize", "2"); 106 string discountImageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) ? Model.Item.GetFile("Custom_DiscountImage").Path : string.Empty; 107 string discountImagePath = discountImageSrc != string.Empty ? discountImageSrc : Model.Item.GetRawValueString("Custom_DiscountIcon", string.Empty); 108 discountImagePath = Path.GetExtension(discountImagePath).ToLower() != ".svg" ? "/Admin/Public/GetImage.ashx?image=" + discountImagePath + "&height=" + discountIconSize + "&width=" + discountIconSize + "&Crop=0&format=webp" : discountImagePath; 109 string discountImgAltText = Model.Item.GetRawValueString("FeatureAltText", string.Empty); 110 //--CUSTOM 111 112 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 113 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 114 115 string priceMin = ""; 116 string priceMax = ""; 117 118 string liveInfoClass = ""; 119 string productInfoFeed = ""; 120 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 121 if (isLazyLoadingForProductInfoEnabled) 122 { 123 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 124 { 125 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 126 if (!string.IsNullOrEmpty(productInfoFeed)) 127 { 128 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 129 } 130 } 131 liveInfoClass = "js-live-info"; 132 } 133 134 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 135 @if (showInformativePrice && product.PriceInformative.Price != 0) 136 { 137 <div class="opacity-50"> 138 <span>@Translate("RRP") </span> 139 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 140 </div> 141 } 142 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 143 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 144 145 @*//CUSTOM*@ 146 @if (showPricesWithVat == "false" && !neverShowVat) 147 { 148 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 149 { 150 <span class="text-price js-text-price"> 151 <span class="spinner-border" role="status"></span> 152 </span> 153 } 154 else 155 { 156 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 157 158 if (product?.VariantInfo?.VariantInfo != null) 159 { 160 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 161 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 162 } 163 if (priceMin != priceMax) 164 { 165 price = priceMin + " - " + priceMax; 166 } 167 168 <span class="@theme"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 195 <span class="@theme"> 196 <span class="text-price">@price</span> 197 </span> 198 } 199 } 200 201 @if (showPricesWithVat == "false" && !neverShowVat) 202 { 203 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 204 { 205 <span itemprop="price" content="" class="d-none"></span> 206 <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> 207 } 208 else 209 { 210 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 211 212 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 213 214 if (product.Price.Price != product.PriceBeforeDiscount.Price) 215 { 216 <span class="opacity-75 @(order)"> 217 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 218 </span> 219 220 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 221 { 222 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 223 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 224 { 225 PriceWithoutVAT = (product.PriceBeforeDiscount.PriceWithoutVat - product.Price.PriceWithoutVat) 226 }; 227 228 <span class="d-none d-sm-inline opacity-75 @(order)"> 229 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceWithoutVATFormatted)</span> 230 </span> 231 } 232 } 233 } 234 } 235 else 236 { 237 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 238 { 239 <span itemprop="price" content="" class="d-none"></span> 240 <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> 241 } 242 else 243 { 244 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 245 246 <span itemprop="price" content="@product.Price.Price.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 247 248 if (product.Price.Price < product.PriceBeforeDiscount.Price) 249 { 250 <span class="opacity-75 @(order)"> 251 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 252 </span> 253 254 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 255 { 256 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 257 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 258 { 259 PriceWithVAT = (product.PriceBeforeDiscount.Price - product.Price.Price) 260 }; 261 262 <span class="d-none d-sm-inline opacity-75 @(order)"> 263 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceFormatted)</span> 264 </span> 265 } 266 } 267 } 268 } 269 @*//--CUSTOM*@ 270 271 @*//CUSTOM*@ 272 @if (discountType == "icon-tooltip" && product.Price.Price != product.PriceBeforeDiscount.Price && discountText != null) 273 { 274 if ((!string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) || !discountImagePath.ToLower().Contains("none")) && discountImagePath != string.Empty) 275 { 276 <span data-bs-toggle="tooltip" data-bs-custom-class="@(discountTheme)" data-bs-html="true" data-bs-title="@HtmlEncoder.HtmlAttributeEncode(discountText)" data-bs-custom-prevent-event="click" data-bs-custom-click-close-delay="2000"> 277 @if (Path.GetExtension(discountImagePath).ToLower() == ".svg") 278 { 279 <span class="icon-auto @(discountIconColor)" style="vertical-align:text-top;height:@(discountIconSize)px;width:@(discountIconSize)px;">@ReadFile(discountImagePath)</span> 280 } 281 else 282 { 283 <img loading="lazy" src="@(discountImagePath)" alt="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" title="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" style="height:@(discountIconSize)px;width:@(discountIconSize)px;"> 284 } 285 </span> 286 } 287 } 288 @*//--CUSTOM*@ 289 290 @* Stock state for Schema.org, start *@ 291 @{ 292 Uri url = Dynamicweb.Context.Current.Request.Url; 293 } 294 295 <link itemprop="url" href="@url"> 296 297 @{ 298 bool IsNeverOutOfStock = product.NeverOutOfstock; 299 } 300 301 @if (IsNeverOutOfStock) 302 { 303 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 304 } 305 else 306 { 307 if (product.StockLevel > 0) 308 { 309 <span itemprop="availability" class="d-none">InStock</span> 310 } 311 else 312 { 313 <span itemprop="availability" class="d-none">OutOfStock</span> 314 } 315 } 316 @* Stock state for Schema.org, stop *@ 317 318 </div> 319 320 @if (showPricesWithVat == "false" && !neverShowVat) 321 { 322 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 323 { 324 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 325 } 326 else 327 { 328 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 329 330 if (product?.VariantInfo?.VariantInfo != null) 331 { 332 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 333 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 334 } 335 if (priceMin != priceMax) 336 { 337 price = priceMin + " - " + priceMax; 338 } 339 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 340 } 341 } 342 343 @*//CUSTOM*@ 344 @if (discountType == "inline" && product.Price.Price != product.PriceBeforeDiscount.Price && !string.IsNullOrEmpty(discountText)) 345 { 346 var discountFontSize = priceFontSize.Contains("h6") ? priceFontSize.Replace("h6", "small") : "small"; 347 348 <div class="@(discountFontSize) mt-1 d-flex flex-wrap @(flexDirection) @(horizontalAlign)"> 349 @discountText 350 </div> 351 } 352 @*//--CUSTOM*@ 353 354 </div> 355 } 356 else if (Pageview.IsVisualEditorMode) 357 { 358 <div class="alert alert-dark m-0" role="alert"> 359 <span>@Translate("No products available")</span> 360 </div> 361 } 362
Error executing template "Designs/Swift/Paragraph/Swift_ProductBadges_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_fe4e63c166214874a0bcb86da4f14f88.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBadges_Custom.cshtml:line 27
   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 System 3 @using System.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Content 7 @using Dynamicweb.Core 8 @using Dynamicweb.Ecommerce.ProductCatalog 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 28 DateTime currentDate = DateTime.Today; 29 bool showComingSoonBadge = currentDate < launchDate && string.Equals( Model.Item.GetRawValueString("NewBadgeDesign"), "comingsoon", StringComparison.InvariantCultureIgnoreCase ); 30 } 31 32 @if (product is object) 33 { 34 var badgeParms = new Dictionary<string, object>(); 35 badgeParms.Add("size", "h7"); 36 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 37 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 38 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 39 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 40 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 41 42 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 46 47 Dictionary<string, ParagraphInfoViewModel> badgeConfigurations; 48 List<string> campaignBadgesValues = Model.Item.GetRawValueString("CampaignBadges") != null ? Model.Item.GetRawValueString("CampaignBadges").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>(); 49 50 if (Dynamicweb.Context.Current.Items.Contains("badgeConfigurations")) 51 { 52 badgeConfigurations = (Dictionary<string, ParagraphInfoViewModel>)Dynamicweb.Context.Current.Items["badgeConfigurations"]; 53 } 54 else 55 { 56 var badgesPage = Pageview.AreaSettings.GetLink("EcommerceBadgesPage") != null ? Pageview.AreaSettings.GetLink("EcommerceBadgesPage").PageId : 0; 57 var allBadges = badgesPage != 0 ? Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(badgesPage) : null; 58 59 badgeConfigurations = new Dictionary<string, ParagraphInfoViewModel>(); 60 61 if ( allBadges != null ) 62 { 63 foreach ( Paragraph badge in allBadges ) 64 { 65 var paragraphviewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel( badge ); 66 string cssClassName = paragraphviewModel.Item.GetString( "CssClassName" )?.Trim().ToLower() ?? string.Empty;; 67 if ( !badgeConfigurations.ContainsKey( cssClassName ) ) 68 { 69 badgeConfigurations.Add( cssClassName, paragraphviewModel ); 70 } 71 } 72 } 73 74 Dynamicweb.Context.Current.Items.Add("badgeConfigurations", badgeConfigurations); 75 } 76 77 int badgesCount = 0; 78 if (badgeConfigurations.Any()) 79 { 80 foreach (string campaign in campaignBadgesValues) 81 { 82 if (!string.IsNullOrEmpty(campaign)) 83 { 84 FieldValueViewModel availableCampaignsObject; 85 product.ProductFields.TryGetValue("Campaign", out availableCampaignsObject); 86 87 if (availableCampaignsObject != null) 88 { 89 string campaignType = string.Empty; 90 91 if (badgeConfigurations.ContainsKey(campaign)) 92 { 93 ParagraphInfoViewModel paragraphviewModel; 94 if (badgeConfigurations.TryGetValue(campaign, out paragraphviewModel)) 95 { 96 campaignType = paragraphviewModel.Item.GetRawValueString("CampaignType"); 97 } 98 } 99 100 List<FieldOptionValueViewModel> availableCampaigns = (List<FieldOptionValueViewModel>)availableCampaignsObject.Value; 101 102 foreach (FieldOptionValueViewModel availableOption in availableCampaigns) 103 { 104 if (campaignType == availableOption.Value) 105 { 106 badgesCount++; 107 break; 108 } 109 } 110 } 111 } 112 } 113 } 114 115 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 116 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 117 DateTime createdDate = product.Created.Value; 118 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 119 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 120 showBadges = (!string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) && badgesCount != 0) || showComingSoonBadge || showBadges; 121 122 if (showBadges) 123 { 124 <div class="@badgeSize @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 125 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 126 </div> 127 } 128 else if (Pageview.IsVisualEditorMode) 129 { 130 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 131 } 132 } 133 else if (Pageview.IsVisualEditorMode) 134 { 135 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 136 } 137 138
StayCool vinkøler - 15,5 cm - Black
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at CompiledRazorTemplates.Dynamic.RazorEngine_160448cdee3c46a18a7a094dcad8bbe9.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage_Custom.cshtml:line 32
   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 System @*//CUSTOM*@ 3 @using System.Collections.Generic @*//CUSTOM*@ 4 @using System.Linq @*//CUSTOM*@ 5 @using Dynamicweb.Core @*//CUSTOM*@ 6 @using Dynamicweb.Ecommerce.ProductCatalog 7 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 8 9 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 10 11 @{ 12 ProductViewModel product = null; 13 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 14 { 15 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 16 } 17 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 18 { 19 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 20 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 21 22 if (productList?.Products is object) 23 { 24 product = productList.Products[0]; 25 } 26 } 27 } 28 29 @if (product is object) 30 { 31 //CUSTOM 32 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 33 DateTime currentDate = DateTime.Today; 34 bool showComingSoonBadge = currentDate < launchDate; 35 string brandLogo = Model.Item.GetString("Custom_BrandLogo"); 36 string brandLogoKey = Model.Item.GetString("Custom_BrandLogoKey"); 37 string brandLogoAltText = Model.Item.GetString("Custom_BrandAltText"); 38 int brandLogoWidth = Model.Item.GetInt32("Custom_BrandLogoWidth") > 0 ? Model.Item.GetInt32("Custom_BrandLogoWidth") : 70; 39 string productBrand = product.ProductFields.ContainsKey("Custom_Brand") ? Converter.ToString(product.ProductFields["Custom_Brand"].Value) : ""; 40 bool enableBrandLogo = !string.IsNullOrEmpty(brandLogo) && !string.IsNullOrEmpty(brandLogoKey) && brandLogoKey == productBrand; 41 //--CUSTOM 42 43 string imagePath = product?.DefaultImage?.Value ?? ""; 44 string imagePathUrlEncoded = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 45 46 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 47 ratio = ratio != "0" ? ratio : ""; 48 string ratioCssClass = ratio != "" ? " ratio" : ""; 49 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 50 51 string width = Model.Item.GetRawValueString("Width", "auto"); 52 int smallImageSize = 640; 53 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 54 55 string ImageObjectFit = Model.Item.GetRawValueString("ImageObjectFit", "contain"); 56 57 string imagePathXs = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 58 string imagePathS = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 59 string imagePathFallBack = imagePath.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePathUrlEncoded + "&format=webp" : imagePath.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 60 61 var badgeParms = new Dictionary<string, object>(); 62 badgeParms.Add("size", "h7"); 63 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 64 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 65 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 66 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 67 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 68 69 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 70 71 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 72 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 73 bool anonymousUser = Pageview.User == null; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 if (!anonymousUser && showFavoritesSelector) 77 { 78 int defaultFavoriteListId = 0; 79 80 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 81 if (favoreiteLists.Count() == 1) 82 { 83 foreach (FavoriteList list in favoreiteLists) 84 { 85 defaultFavoriteListId = list.ListId; 86 } 87 } 88 89 favoriteParameters.Add("ListId", defaultFavoriteListId); 90 } 91 92 MediaViewModel alternativeImage = new MediaViewModel(); 93 if (Model.Item.GetBoolean("ShowAlternativeImageOnHover")) 94 { 95 var selectedImageCategories = Model.Item.GetRawValueString("GetAlternativeImageFrom").Split(',').ToList(); 96 List<MediaViewModel> allAssetsImages = product.AssetCategories.Where(x => selectedImageCategories.Contains(x.SystemName)).SelectMany(x => x.Assets).ToList(); 97 allAssetsImages.RemoveAll(x => x.Value == product.DefaultImage.Value); 98 alternativeImage = allAssetsImages.FirstOrDefault(); 99 } 100 101 string altImagePathXs = string.Empty; 102 string altImagePathS = string.Empty; 103 104 if (!string.IsNullOrEmpty(alternativeImage?.Value)) 105 { 106 altImagePathXs = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={smallImageSize}x"); //CUSTOM 107 altImagePathS = alternativeImage.Value.StartsWith("/Files/") ? "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + Dynamicweb.Context.Current.Server.UrlEncode(alternativeImage.Value) + "&format=webp" : alternativeImage.Value.Replace("s=1500x1500", $"s={largeImageSize}x"); //CUSTOM 108 } 109 110 @* Theme settings *@ 111 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 112 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 113 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 114 115 string imageId = "ProductImage_" + product.Id + product.VariantId.Replace(".", "_"); 116 117 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 118 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 119 DateTime createdDate = product.Created.Value; 120 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 121 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 122 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) || showComingSoonBadge || showBadges; //CUSTOM 123 124 string fullWidth = width == "auto" ? "w-100" : ""; 125 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 126 127 @* -- CUSTOM -- Added image item prop *@ 128 if (!string.IsNullOrEmpty(imagePath)) 129 { 130 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 131 <div class="ratio" style="@(ratioVariable)"> 132 <div class="d-flex justify-content-center align-items-center"> 133 @* CUSTOM *@ 134 @if (enableBrandLogo) 135 { 136 <img src="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogo)" 137 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoAltText)" 138 class="productdefault-brand-logo" 139 width="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(brandLogoWidth.ToString())" /> 140 } 141 @* CUSTOM END *@ 142 @if (imagePath.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 143 { 144 <img id="@imageId" 145 itemprop="image" 146 srcset=" 147 @imagePathXs @(smallImageSize)w, 148 @imagePathS @(largeImageSize)w" 149 sizes="(max-width: 992px) 50vw, 25vw" 150 src="@imagePathFallBack" 151 @if (Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) { <text> 152 data-alternative-image=" 153 @altImagePathXs @(smallImageSize)w, 154 @altImagePathS @(largeImageSize)w" 155 onmouseover="swift.Image.swapImage(event)" 156 onmouseout="swift.Image.swapImage(event)" 157 </text> } 158 loading="lazy" 159 decoding="async" 160 class="h-100 w-100 @themePadding" 161 style="object-fit: @ImageObjectFit; @themeBorder" 162 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 163 } 164 //CUSTOM 165 else if (imagePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Model.Item.GetBoolean("ShowAlternativeImageOnHover") && !string.IsNullOrEmpty(alternativeImage?.Value)) 166 { 167 <img id="@imageId" 168 itemprop="image" 169 srcset=" 170 @imagePathXs @(smallImageSize)w, 171 @imagePathS @(largeImageSize)w" 172 sizes="(max-width: 992px) 50vw, 25vw" 173 src="@imagePathFallBack" 174 data-alternative-image=" 175 @altImagePathXs @(smallImageSize)w, 176 @altImagePathS @(largeImageSize)w" 177 onmouseover="swift.Image.swapImage(event)" 178 onmouseout="swift.Image.swapImage(event)" 179 loading="lazy" 180 decoding="async" 181 class="h-100 w-100 @themePadding" 182 style="object-fit: @ImageObjectFit; @themeBorder" 183 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> 184 } 185 //--CUSTOM 186 else 187 { 188 <img itemprop="image" 189 src="@product.DefaultImage.Value" 190 loading="lazy" 191 class="h-100 w-100 @themePadding" 192 style="object-fit: contain; @themeBorder" 193 alt="@Dynamicweb.Core.Encoders.HtmlEncoder.HtmlAttributeEncode(product.Name)"> @*//CUSTOM*@ 194 } 195 </div> 196 </div> 197 198 @if (showBadges) 199 { 200 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 201 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 202 </div> 203 } 204 205 @if (!anonymousUser) 206 { 207 if (showFavoritesSelector) 208 { 209 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 210 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 211 </div> 212 } 213 } 214 </div> 215 } 216 } 217 else if (Pageview.IsVisualEditorMode) 218 { 219 <div class="alert alert-dark m-0">@Translate("No products available")</div> 220 } 221

StayCool vinkøler - 15,5 cm - Black

Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_1fb0d18a1de944f3a468232b7643f0eb.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 65
   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.Configuration @*//CUSTOM*@ 3 @using Dynamicweb.Core.Encoders @*//CUSTOM*@ 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 @using System.Globalization 6 @using System.IO @*//CUSTOM*@ 7 8 @* CUSTOMIZED STANDARD SWIFT (v1.25.0) TEMPLATE *@ 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 28 bool anonymousUser = Pageview.User == null; 29 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 30 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 31 32 bool productIsDiscontinued = product is object && product.Discontinued; 33 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 34 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 35 } 36 37 @if (product is object && !hidePrice && !isDiscontinued) 38 { 39 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 40 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 41 42 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "h6 justify-content-lg-start"); //CUSTOM 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 45 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 46 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 47 48 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 50 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 51 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 52 53 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 54 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 55 string order = layout == "horizontal" ? string.Empty : "order-2"; 56 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 57 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 61 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 62 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 63 64 //CUSTOM 65 Dictionary<string, FieldValueViewModel> productFields = product.ProductFields; 66 var discountText = ""; 67 bool discountDiscontinued = false; 68 bool discountOnSale = false; 69 70 if (productFields.TryGetValue("Custom_Discontinued", out FieldValueViewModel discontinued)) 71 { 72 var firstValue = (discontinued.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 73 74 if (!string.IsNullOrWhiteSpace(firstValue)) 75 { 76 bool.TryParse(firstValue, out discountDiscontinued); 77 } 78 } 79 80 if (productFields.TryGetValue("Custom_OnSale", out FieldValueViewModel onsale)) 81 { 82 var firstValue = (onsale.Value as List<FieldOptionValueViewModel>).FirstOrDefault()?.Value; 83 84 if (!string.IsNullOrWhiteSpace(firstValue)) 85 { 86 bool.TryParse(firstValue, out discountOnSale); 87 } 88 } 89 90 if (discountDiscontinued && discountOnSale) 91 { 92 discountText = Translate("Outlet - tilbuddet gælder så længe lager haves"); 93 } 94 else 95 { 96 var discountInfo = Smartpage.EvaSolo.CampaignPrices.Helpers.DiscountHelper.GetDiscountInfo(product); 97 if (discountInfo != null) 98 { 99 discountText = string.Format(Translate(Model.Item.GetRawValueString("Custom_DiscountText", "Tilbuddet gælder {0} - {1}")), $"&zwnj;{discountInfo.ValidFromFormatted}&zwnj;", $"&zwnj;{discountInfo.ValidToFormatted}&zwnj;"); 100 } 101 } 102 string discountType = Model.Item.GetRawValueString("Custom_DiscountType", "none"); 103 string discountTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Custom_DiscountTheme")) ? "theme " + Model.Item.GetRawValueString("Custom_DiscountTheme").Replace(" ", "").Trim().ToLower() : string.Empty; 104 string discountIconColor = Model.Item.GetString("Custom_DiscountIconColor", "text-inherit"); 105 string discountIconSize = Model.Item.GetRawValueString("Custom_DiscountIconSize", "2"); 106 string discountImageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) ? Model.Item.GetFile("Custom_DiscountImage").Path : string.Empty; 107 string discountImagePath = discountImageSrc != string.Empty ? discountImageSrc : Model.Item.GetRawValueString("Custom_DiscountIcon", string.Empty); 108 discountImagePath = Path.GetExtension(discountImagePath).ToLower() != ".svg" ? "/Admin/Public/GetImage.ashx?image=" + discountImagePath + "&height=" + discountIconSize + "&width=" + discountIconSize + "&Crop=0&format=webp" : discountImagePath; 109 string discountImgAltText = Model.Item.GetRawValueString("FeatureAltText", string.Empty); 110 //--CUSTOM 111 112 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 113 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 114 115 string priceMin = ""; 116 string priceMax = ""; 117 118 string liveInfoClass = ""; 119 string productInfoFeed = ""; 120 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 121 if (isLazyLoadingForProductInfoEnabled) 122 { 123 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 124 { 125 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 126 if (!string.IsNullOrEmpty(productInfoFeed)) 127 { 128 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 129 } 130 } 131 liveInfoClass = "js-live-info"; 132 } 133 134 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 135 @if (showInformativePrice && product.PriceInformative.Price != 0) 136 { 137 <div class="opacity-50"> 138 <span>@Translate("RRP") </span> 139 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 140 </div> 141 } 142 <div class="@priceFontSize m-0 d-flex flex-wrap @flexDirection @flexGap @horizontalAlign" style="row-gap: 0 !important" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 143 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 144 145 @*//CUSTOM*@ 146 @if (showPricesWithVat == "false" && !neverShowVat) 147 { 148 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 149 { 150 <span class="text-price js-text-price"> 151 <span class="spinner-border" role="status"></span> 152 </span> 153 } 154 else 155 { 156 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 157 158 if (product?.VariantInfo?.VariantInfo != null) 159 { 160 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 161 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 162 } 163 if (priceMin != priceMax) 164 { 165 price = priceMin + " - " + priceMax; 166 } 167 168 <span class="@theme"> 169 <span class="text-price">@price</span> 170 </span> 171 } 172 } 173 else 174 { 175 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 176 { 177 <span class="text-price js-text-price"> 178 <span class="spinner-border" role="status"></span> 179 </span> 180 } 181 else 182 { 183 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 184 185 if (product?.VariantInfo?.VariantInfo != null) 186 { 187 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 188 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 189 } 190 if (priceMin != priceMax) 191 { 192 price = priceMin + " - " + priceMax; 193 } 194 195 <span class="@theme"> 196 <span class="text-price">@price</span> 197 </span> 198 } 199 } 200 201 @if (showPricesWithVat == "false" && !neverShowVat) 202 { 203 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 204 { 205 <span itemprop="price" content="" class="d-none"></span> 206 <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> 207 } 208 else 209 { 210 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 211 212 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 213 214 if (product.Price.Price != product.PriceBeforeDiscount.Price) 215 { 216 <span class="opacity-75 @(order)"> 217 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 218 </span> 219 220 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 221 { 222 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 223 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 224 { 225 PriceWithoutVAT = (product.PriceBeforeDiscount.PriceWithoutVat - product.Price.PriceWithoutVat) 226 }; 227 228 <span class="d-none d-sm-inline opacity-75 @(order)"> 229 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceWithoutVATFormatted)</span> 230 </span> 231 } 232 } 233 } 234 } 235 else 236 { 237 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 238 { 239 <span itemprop="price" content="" class="d-none"></span> 240 <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> 241 } 242 else 243 { 244 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 245 246 <span itemprop="price" content="@product.Price.Price.ToString(CultureInfo.InvariantCulture)" class="d-none"></span> 247 248 if (product.Price.Price < product.PriceBeforeDiscount.Price) 249 { 250 <span class="opacity-75 @(order)"> 251 <span class="fs-7 text-price text-decoration-line-through">@beforePrice</span> 252 </span> 253 254 if (Model.Item.GetBoolean("Custom_ShowDiscountSavings")) 255 { 256 var currency = Dynamicweb.Ecommerce.Common.Context.Currency; 257 var priceInfo = new Dynamicweb.Ecommerce.Prices.PriceInfo(currency) 258 { 259 PriceWithVAT = (product.PriceBeforeDiscount.Price - product.Price.Price) 260 }; 261 262 <span class="d-none d-sm-inline opacity-75 @(order)"> 263 <span class="fs-7 text-price">@string.Format(Translate("Spar {0}"), priceInfo.PriceFormatted)</span> 264 </span> 265 } 266 } 267 } 268 } 269 @*//--CUSTOM*@ 270 271 @*//CUSTOM*@ 272 @if (discountType == "icon-tooltip" && product.Price.Price != product.PriceBeforeDiscount.Price && discountText != null) 273 { 274 if ((!string.IsNullOrEmpty(Model.Item.GetString("Custom_DiscountImage")) || !discountImagePath.ToLower().Contains("none")) && discountImagePath != string.Empty) 275 { 276 <span data-bs-toggle="tooltip" data-bs-custom-class="@(discountTheme)" data-bs-html="true" data-bs-title="@HtmlEncoder.HtmlAttributeEncode(discountText)" data-bs-custom-prevent-event="click" data-bs-custom-click-close-delay="2000"> 277 @if (Path.GetExtension(discountImagePath).ToLower() == ".svg") 278 { 279 <span class="icon-auto @(discountIconColor)" style="vertical-align:text-top;height:@(discountIconSize)px;width:@(discountIconSize)px;">@ReadFile(discountImagePath)</span> 280 } 281 else 282 { 283 <img loading="lazy" src="@(discountImagePath)" alt="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" title="@HtmlEncoder.HtmlAttributeEncode(discountImgAltText)" style="height:@(discountIconSize)px;width:@(discountIconSize)px;"> 284 } 285 </span> 286 } 287 } 288 @*//--CUSTOM*@ 289 290 @* Stock state for Schema.org, start *@ 291 @{ 292 Uri url = Dynamicweb.Context.Current.Request.Url; 293 } 294 295 <link itemprop="url" href="@url"> 296 297 @{ 298 bool IsNeverOutOfStock = product.NeverOutOfstock; 299 } 300 301 @if (IsNeverOutOfStock) 302 { 303 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 304 } 305 else 306 { 307 if (product.StockLevel > 0) 308 { 309 <span itemprop="availability" class="d-none">InStock</span> 310 } 311 else 312 { 313 <span itemprop="availability" class="d-none">OutOfStock</span> 314 } 315 } 316 @* Stock state for Schema.org, stop *@ 317 318 </div> 319 320 @if (showPricesWithVat == "false" && !neverShowVat) 321 { 322 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 323 { 324 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 325 } 326 else 327 { 328 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 329 330 if (product?.VariantInfo?.VariantInfo != null) 331 { 332 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 333 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 334 } 335 if (priceMin != priceMax) 336 { 337 price = priceMin + " - " + priceMax; 338 } 339 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 340 } 341 } 342 343 @*//CUSTOM*@ 344 @if (discountType == "inline" && product.Price.Price != product.PriceBeforeDiscount.Price && !string.IsNullOrEmpty(discountText)) 345 { 346 var discountFontSize = priceFontSize.Contains("h6") ? priceFontSize.Replace("h6", "small") : "small"; 347 348 <div class="@(discountFontSize) mt-1 d-flex flex-wrap @(flexDirection) @(horizontalAlign)"> 349 @discountText 350 </div> 351 } 352 @*//--CUSTOM*@ 353 354 </div> 355 } 356 else if (Pageview.IsVisualEditorMode) 357 { 358 <div class="alert alert-dark m-0" role="alert"> 359 <span>@Translate("No products available")</span> 360 </div> 361 } 362
Error executing template "Designs/Swift/Paragraph/Swift_ProductBadges_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateView(ProductViewModelSettings settings, ProductFieldValue pfv)
   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetProductFieldValues(ProductViewModelSettings settings, Product product)
   at System.Lazy`1.CreateValue()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Lazy`1.get_Value()
   at CompiledRazorTemplates.Dynamic.RazorEngine_fe4e63c166214874a0bcb86da4f14f88.Execute() in E:\Solutions\Eva Solo\Files\Templates\Designs\Swift\Paragraph\Swift_ProductBadges_Custom.cshtml:line 27
   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 System 3 @using System.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Content 7 @using Dynamicweb.Core 8 @using Dynamicweb.Ecommerce.ProductCatalog 9 10 @{ 11 ProductViewModel product = null; 12 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 13 { 14 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 15 } 16 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 17 { 18 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 19 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 20 21 if (productList?.Products is object) 22 { 23 product = productList.Products[0]; 24 } 25 } 26 27 DateTime launchDate = product.ProductFields.ContainsKey("Custom_LaunchDate") ? Converter.ToDateTime(product.ProductFields["Custom_LaunchDate"].Value) : DateTime.MinValue; 28 DateTime currentDate = DateTime.Today; 29 bool showComingSoonBadge = currentDate < launchDate && string.Equals( Model.Item.GetRawValueString("NewBadgeDesign"), "comingsoon", StringComparison.InvariantCultureIgnoreCase ); 30 } 31 32 @if (product is object) 33 { 34 var badgeParms = new Dictionary<string, object>(); 35 badgeParms.Add("size", "h7"); 36 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 37 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 38 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 39 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 40 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 41 42 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 43 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 44 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 45 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 46 47 Dictionary<string, ParagraphInfoViewModel> badgeConfigurations; 48 List<string> campaignBadgesValues = Model.Item.GetRawValueString("CampaignBadges") != null ? Model.Item.GetRawValueString("CampaignBadges").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>(); 49 50 if (Dynamicweb.Context.Current.Items.Contains("badgeConfigurations")) 51 { 52 badgeConfigurations = (Dictionary<string, ParagraphInfoViewModel>)Dynamicweb.Context.Current.Items["badgeConfigurations"]; 53 } 54 else 55 { 56 var badgesPage = Pageview.AreaSettings.GetLink("EcommerceBadgesPage") != null ? Pageview.AreaSettings.GetLink("EcommerceBadgesPage").PageId : 0; 57 var allBadges = badgesPage != 0 ? Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(badgesPage) : null; 58 59 badgeConfigurations = new Dictionary<string, ParagraphInfoViewModel>(); 60 61 if ( allBadges != null ) 62 { 63 foreach ( Paragraph badge in allBadges ) 64 { 65 var paragraphviewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel( badge ); 66 string cssClassName = paragraphviewModel.Item.GetString( "CssClassName" )?.Trim().ToLower() ?? string.Empty;; 67 if ( !badgeConfigurations.ContainsKey( cssClassName ) ) 68 { 69 badgeConfigurations.Add( cssClassName, paragraphviewModel ); 70 } 71 } 72 } 73 74 Dynamicweb.Context.Current.Items.Add("badgeConfigurations", badgeConfigurations); 75 } 76 77 int badgesCount = 0; 78 if (badgeConfigurations.Any()) 79 { 80 foreach (string campaign in campaignBadgesValues) 81 { 82 if (!string.IsNullOrEmpty(campaign)) 83 { 84 FieldValueViewModel availableCampaignsObject; 85 product.ProductFields.TryGetValue("Campaign", out availableCampaignsObject); 86 87 if (availableCampaignsObject != null) 88 { 89 string campaignType = string.Empty; 90 91 if (badgeConfigurations.ContainsKey(campaign)) 92 { 93 ParagraphInfoViewModel paragraphviewModel; 94 if (badgeConfigurations.TryGetValue(campaign, out paragraphviewModel)) 95 { 96 campaignType = paragraphviewModel.Item.GetRawValueString("CampaignType"); 97 } 98 } 99 100 List<FieldOptionValueViewModel> availableCampaigns = (List<FieldOptionValueViewModel>)availableCampaignsObject.Value; 101 102 foreach (FieldOptionValueViewModel availableOption in availableCampaigns) 103 { 104 if (campaignType == availableOption.Value) 105 { 106 badgesCount++; 107 break; 108 } 109 } 110 } 111 } 112 } 113 } 114 115 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 116 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 117 DateTime createdDate = product.Created.Value; 118 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 119 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 120 showBadges = (!string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) && badgesCount != 0) || showComingSoonBadge || showBadges; 121 122 if (showBadges) 123 { 124 <div class="@badgeSize @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 125 @RenderPartial("Components/EcommerceBadge_Custom.cshtml", product, badgeParms) @*//CUSTOM*@ 126 </div> 127 } 128 else if (Pageview.IsVisualEditorMode) 129 { 130 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 131 } 132 } 133 else if (Pageview.IsVisualEditorMode) 134 { 135 <span class="badge bg-success text-light rounded-0">@Translate("Badge example")</span> 136 } 137 138
13 ud af 13 produkter

Se også

Vinkarafler

En smuk vinkaraffel gør det meget hyggeligere at servere hvid- og rødvin. I stedet for at stille papvinen på bordet, kan du med en karaffel servere den på en elegant måde og skabe en helt anden atmosfære omkring middagen. Desuden opnår du den fordel, at vinkaraflen helt automatisk forstærker vinens aroma, smagsstoffer og dufte.

Vinkarafler er populære blandt de, der på en enkel facon ønsker at øge nydelsen af en god vin. Med deres ofte elegante design og en funktionalitet, der automatisk følger formen, er vinkarafler et must blandt vinentusiaster. Man behøver på ingen måde være vinkender for at opleve fordelene ved vinkarafler.

MUNDBLÆSTE DEKANTERINGSKARAFLER

En dekanteringskaraffel til iltning af vin er en investering. Hvert glas vin kommer til at smage bedre, og hver gang man serverer et glas, bliver det en lidt mere elegant og hyggelig oplevelse.

Eva Solos vinkarafler i glas er elegant udformede og mundblæste. Detaljerne i rustfrit stål og plastik, som komplementerer den smukke karaffel og giver ekstra funktionalitet, er udformet, så de harmonerer med karaflen som helhed. Resultatet bliver en stilren karaffel med god funktionalitet og ergonomi. Man får et godt greb om karaflens hals, og det er nemt at skænke op, selvom karaflen er fuld.

Vinkarafler fra Eva Solo bruges til at ilte og servere både hvid- og rødvin. Til hvidvin kan du med fordel benytte de tilhørende køleelementer til at holde vinen ved rette temperatur gennem mange timer. Eva Solos vinkarafler rummer 75 cl, hvilket svarer til en flaske vin.

INDBYGGET TRAGT TIL EFFEKTIV ILTNING

Det kan tage lidt tid at ilte en vin. Mange sætter pris på det ritual, som iltningen indebærer, men mindst lige så mange ser gerne, at processen foregår så hurtigt som muligt. Eva Solos vinkarafler har en indbygget tragt med mange små huller, som effektivt giver en stor iltning, når vinen løber ud gennem hullerne. Iltningen sker samtidigt skånsomt, så vinen ikke udsættes for alt for megen ilt. For at ilte vinen i karaflen skal du blot hælde vinen direkte fra flasken over i karaflen. 

Karaflens indbyggede tragt sørger også for at udskille eventuelt bundfald fra visse typer rødvin. Det er en stor fordel, som er svær at opnå med andre typer vinkarafler eller ved manuel dekantering.

HVORFOR SKAL MAN ILTE RØDVIN?

Det er næsten altid en fordel at ilte rødvinen inden serveringen. Forskellen mellem en iltet og ikke-iltet vin er tydelig, selv for en nybegynder. Dekanteringen gør, at vinen kommer i kontakt med ilt, hvilket blandt andet indebærer, at der frigøres flere duftemner, og at smagen bliver mere afrundet. Effekten af iltningen kan dog være større eller mindre alt efter vinens karakter. Vin er desuden ikke nogen eksakt videnskab, og ens personlige smag er afgørende.

For hvidvin har dekantering ikke samme effekt. Du kan dog med fordel ilte lidt mere eksklusive vine for at fremhæve det lille ekstra. Med hensyn til hvidvin er det vigtigere at holde den ved rette temperatur. Med Eva Solos vinkarafler til hvidvin med kølelement er det ingen sag, selvom det er varmt ved middagsbordet eller ude på altanen. Du kan med fordel opbevare køleelementerne i fryseren, så du hurtigt kan drage nytte af deres funktion.

By clicking 'Accept All' you consent that we may collect information about you for various purposes, including: Statistics and Marketing