Komponent editor til: Brons - Pris, detalje og køb
Error executing template "/Designs/Swift/Paragraph/Swift_ProductPrice_Custom.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at CompiledRazorTemplates.Dynamic.RazorEngine_7e396829ab104331a6b8b125b1d8d34b.Execute() in D:\dynamicweb.net\Solutions\Dynamicweb\bronsmaskinforretning.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice_Custom.cshtml:line 31 at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader) at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer) at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter) at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template) at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template) at Dynamicweb.Rendering.Template.RenderRazorTemplate()
1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> 2 @using Dynamicweb.Ecommerce.ProductCatalog 3 @using CustomCode 4 5 @{ 6 ProductViewModel product = null; 7 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 8 { 9 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 10 } 11 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 12 { 13 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 14 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 15 16 if (productList?.Products is object) 17 { 18 product = productList.Products[0]; 19 } 20 } 21 22 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 23 bool anonymousUser = Pageview.User == null; 24 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 25 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 26 27 bool productIsDiscontinued = product is object && product.Discontinued; 28 bool doNotShowPriceIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowPriceIfProductIsDiscontinued"); 29 var isDiscontinued = productIsDiscontinued && doNotShowPriceIfProductIsDiscontinued; 30 31 string itemDiscountGroup = (string)product.ProductFields.FirstOrDefault(o => o.Value.SystemName == "ItemDiscountGroup").Value?.Value ?? ""; 32 33 var user = Dynamicweb.Security.UserManagement.User.GetCurrentFrontendUser(); 34 bool isDealer = user!=null?user.CanSeeItemDiscountGroups(): false; 35 36 itemDiscountGroup = isDealer ? itemDiscountGroup : string.Empty; 37 38 } 39 40 @if (product is object && !hidePrice && !isDiscontinued) 41 { 42 bool showInformativePrice = Model.Item.GetBoolean("ShowInformativePrice"); 43 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : string.Empty; 44 45 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "fs-2"); 46 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 47 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 48 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 49 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 50 51 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 52 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 53 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 54 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 55 56 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 57 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 58 string order = layout == "horizontal" ? string.Empty : "order-2"; 59 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 60 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 61 62 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 63 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 64 contentPadding = contentPadding == "small" ? "p-1 px-md-2 py-md-1" : contentPadding; 65 contentPadding = contentPadding == "large" ? "p-2 px-md-3 py-md-2" : contentPadding; 66 67 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 68 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 69 70 string priceMin = ""; 71 string priceMax = ""; 72 73 string liveInfoClass = ""; 74 string productInfoFeed = ""; 75 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 76 if (isLazyLoadingForProductInfoEnabled) 77 { 78 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 79 { 80 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 81 if (!string.IsNullOrEmpty(productInfoFeed)) 82 { 83 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 84 } 85 } 86 liveInfoClass = "js-live-info"; 87 } 88 89 90 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 91 @if (showInformativePrice && product.PriceInformative.Price != 0) 92 { 93 <div class="opacity-50"> 94 <span>@Translate("RRP") </span> 95 <span class="text-decoration-line-through text-price">@product.PriceInformative.PriceFormatted</span> 96 </div> 97 } 98 <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"> 99 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 100 101 102 @if (showPricesWithVat == "false" && !neverShowVat) 103 { 104 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 105 { 106 <span itemprop="price" content="" class="d-none"></span> 107 <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> 108 } 109 else 110 { 111 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceWithoutVatFormatted : product.PriceBeforeDiscount.PriceWithoutVatFormatted; 112 113 <span itemprop="price" content="@product.Price.PriceWithoutVat.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture)" class="d-none"></span> 114 if (product.Price.Price != product.PriceBeforeDiscount.Price) 115 { 116 <span class="text-decoration-line-through opacity-75 @order">@beforePrice</span> 117 } 118 } 119 } 120 else 121 { 122 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 123 { 124 <span itemprop="price" content="" class="d-none"></span> 125 <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> 126 } 127 else 128 { 129 string beforePrice = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).PriceBeforeDiscount.PriceFormatted : product.PriceBeforeDiscount.PriceFormatted; 130 131 <span itemprop="price" content="@product.Price.Price.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture)" class="d-none"></span> 132 133 if (product.Price.Price != product.PriceBeforeDiscount.Price) 134 { 135 <span class="text-decoration-line-through opacity-75 @order"> 136 <span class="text-price">@beforePrice</span> 137 </span> 138 } 139 } 140 } 141 142 @if (showPricesWithVat == "false" && !neverShowVat) 143 { 144 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 145 { 146 <span class="text-price js-text-price"> 147 <span class="spinner-border" role="status"></span> 148 </span> 149 } 150 else 151 { 152 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithoutVatFormatted : product.Price.PriceWithoutVatFormatted; 153 154 if (product?.VariantInfo?.VariantInfo != null) 155 { 156 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 157 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 158 } 159 if (priceMin != priceMax) 160 { 161 price = priceMin + " - " + priceMax; 162 } 163 <span class="@theme @contentPadding"> 164 <span class="text-price">@price</span> 165 </span> 166 } 167 } 168 else 169 { 170 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 171 { 172 <span class="text-price js-text-price"> 173 <span class="spinner-border" role="status"></span> 174 </span> 175 } 176 else 177 { 178 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceFormatted : product.Price.PriceFormatted; 179 180 if (product?.VariantInfo?.VariantInfo != null) 181 { 182 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 183 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 184 } 185 if (priceMin != priceMax) 186 { 187 price = priceMin + " - " + priceMax; 188 } 189 <span class="@theme @contentPadding"> 190 <span class="text-price">@price</span> 191 </span> 192 } 193 } 194 195 @* Stock state for Schema.org, start *@ 196 @{ 197 Uri url = Dynamicweb.Context.Current.Request.Url; 198 } 199 200 <link itemprop="url" href="@url"> 201 202 @{ 203 bool IsNeverOutOfStock = product.NeverOutOfstock; 204 } 205 206 @if (IsNeverOutOfStock) 207 { 208 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 209 } 210 else 211 { 212 if (product.StockLevel > 0) 213 { 214 <span itemprop="availability" class="d-none">InStock</span> 215 } 216 else 217 { 218 <span itemprop="availability" class="d-none">OutOfStock</span> 219 } 220 } 221 @* Stock state for Schema.org, stop *@ 222 223 @if (!string.IsNullOrWhiteSpace(itemDiscountGroup)) 224 { 225 <div class="opacity-85 fst-normal">(@itemDiscountGroup)</div> 226 } 227 </div> 228 229 @if (showPricesWithVat == "false" && !neverShowVat) 230 { 231 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 232 { 233 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 234 } 235 else 236 { 237 string price = !string.IsNullOrEmpty(unitId) ? product.GetPrice(unitId).Price.PriceWithVatFormatted : product.Price.PriceWithVatFormatted; 238 239 if (product?.VariantInfo?.VariantInfo != null) 240 { 241 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 242 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 243 } 244 if (priceMin != priceMax) 245 { 246 price = priceMin + " - " + priceMax; 247 } 248 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 249 } 250 } 251 </div> 252 } 253 else if (Pageview.IsVisualEditorMode) 254 { 255 <div class="alert alert-dark m-0" role="alert"> 256 <span>@Translate("No products available")</span> 257 </div> 258 } 259
Error executing template "Designs/Swift/Paragraph/Swift_ProductAddToFavorites_Custom.cshtml" System.NullReferenceException: Object reference not set to an instance of an object. at CompiledRazorTemplates.Dynamic.RazorEngine_95c6615cbf5c4297b2fc878e56bed67a.Execute() in D:\dynamicweb.net\Solutions\Dynamicweb\bronsmaskinforretning.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\Paragraph\Swift_ProductAddToFavorites_Custom.cshtml:line 100 at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader) at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer) at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter) at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template) at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template) at Dynamicweb.Rendering.Template.RenderRazorTemplate()
1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> 2 @using Dynamicweb.Ecommerce.ProductCatalog 3 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 4 @using System.Globalization 5 6 7 @functions { 8 string DoubleToString(double? value) 9 { 10 if (value.HasValue) 11 { 12 return value.Value.ToString(CultureInfo.InvariantCulture); 13 } 14 return null; 15 } 16 } 17 18 @{ 19 ProductViewModel product = null; 20 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 21 { 22 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 23 } 24 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 25 { 26 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 27 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 28 29 if (productList?.Products is object) 30 { 31 product = productList.Products[0]; 32 } 33 } 34 35 bool anonymousUser = Pageview.User == null; 36 37 bool productIsDiscontinued = product is object && product.Discontinued; 38 bool disableAddToCartIfProductIsDiscontinued = Model.Item.GetBoolean("DoNotShowFavoriteButtonIfProductIsDiscontinued"); 39 bool isDiscontinued = productIsDiscontinued && disableAddToCartIfProductIsDiscontinued; 40 41 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", string.Empty); 42 horizontalAlign = horizontalAlign == "center" ? "justify-content-center" : horizontalAlign; 43 horizontalAlign = horizontalAlign == "end" ? "justify-content-end" : horizontalAlign; 44 horizontalAlign = horizontalAlign == "full" ? string.Empty : horizontalAlign; 45 46 string buttonSize = Model.Item.GetRawValueString("ButtonSize", "regular"); 47 buttonSize = buttonSize == "small" ? " btn-sm" : buttonSize; 48 buttonSize = buttonSize == "regular" ? string.Empty : buttonSize; 49 buttonSize = buttonSize == "large" ? " btn-lg" : buttonSize; 50 51 string buttonStyle = Model.Item.GetRawValueString("ButtonStyle", "secondary"); 52 string buttonStyleClass = string.Empty; 53 54 switch (buttonStyle) 55 { 56 case "primary": 57 buttonStyleClass = " btn-primary"; 58 break; 59 case "secondary": 60 buttonStyleClass = " btn-secondary"; 61 break; 62 case "link": 63 buttonStyleClass = " btn-link"; 64 break; 65 } 66 67 string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 68 if (!url.Contains("LayoutTemplate")) 69 { 70 url += url.Contains("?") ? "&LayoutTemplate=Swift_MiniCart.cshtml" : "?LayoutTemplate=Swift_MiniCart.cshtml"; 71 } 72 73 string fullWidth = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "w-100" : ""; 74 75 var favoriteParameters = new Dictionary<string, object>(); 76 int defaultFavoriteListId = 0; 77 78 if (Pageview?.User?.ID != null) 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 90 favoriteParameters.Add("ListId", defaultFavoriteListId); 91 favoriteParameters.Add("ButtonSize", buttonSize); 92 favoriteParameters.Add("ButtonStyle", buttonStyleClass); 93 favoriteParameters.Add("ButtonWidth", fullWidth); 94 95 if (!Model.Item.GetBoolean("HideButtonText")) 96 { 97 favoriteParameters.Add("ShowButtonText", true); 98 } 99 100 double? stepQty = product.PurchaseQuantityStep > 0 ? product.PurchaseQuantityStep : 1; 101 double? minQty = product.PurchaseMinimumQuantity > 0 ? product.PurchaseMinimumQuantity : 1; 102 double? valueQty = minQty > stepQty ? minQty : stepQty; 103 double? maxQty = null; 104 if (product.ProductType == Dynamicweb.Ecommerce.Products.ProductType.Stock && !product.NeverOutOfstock) 105 { 106 maxQty = product.StockLevel; 107 } 108 109 } 110 111 @if ((product is object && !anonymousUser && !isDiscontinued) || (product is object && Pageview.IsVisualEditorMode)) 112 { 113 <div class="d-flex @horizontalAlign @fullWidth item_@Model.Item.SystemName.ToLower()"> 114 <input class="form-control d-inline-block swift_quantity-field" style="min-width: 60px; max-width: 100px; z-index: 1" type="number" id="Quantity_@product.Id" name="Quantity" value="@DoubleToString(valueQty)" step="@DoubleToString(stepQty)" min="@DoubleToString(minQty)" max="@DoubleToString(maxQty)"> 115 @RenderPartial("Components/ToggleFavorite_Custom.cshtml", product, favoriteParameters) 116 </div> 117 } 118 119 else if (Pageview.IsVisualEditorMode) 120 { 121 <div class="alert alert-dark m-0">@Translate("No products available")</div> 122 } 123