Komponent editor til: Product list card

Error executing template "Designs/Swift/Paragraph/Swift_ProductHeader.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_11438a06388f4700944b5275045b4787.Execute() in D:\dynamicweb.net\Solutions\Flex Media\baagoe.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\Paragraph\Swift_ProductHeader.cshtml:line 30
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> 2 @using Dynamicweb.Ecommerce.ProductCatalog 3 4 @{ 5 ProductViewModel product = new ProductViewModel(); 6 7 ProductViewModelSettings productSetting = new ProductViewModelSettings 8 { 9 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 10 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 11 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 12 ShopId = Pageview.Area.EcomShopId 13 }; 14 15 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 16 { 17 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 18 } 19 else if (Pageview.Item["DummyProduct"] != null) 20 { 21 string dummyProductId = ""; 22 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 23 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 24 if (productList.Products != null) 25 { 26 foreach (var p in productList.Products) { dummyProductId = p.Id; } 27 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 28 product = dummyProduct; 29 } else { 30 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 31 } 32 } else if (Pageview.Item["DummyProduct"] == null) { 33 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 34 } 35 36 string titleFontSize = Model.Item.GetRawValueString("FontSize", "fs-6"); 37 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 38 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 39 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 40 } 41 42 43 @if (product.Id != null) { 44 <h2 class="@titleFontSize m-0 @horizontalAlign" itemprop="name">@product.Name</h2> 45 } else if (Pageview.IsVisualEditorMode) { 46 <div class="alert alert-dark m-0">@Translate("No products available")</div> 47 } 48
Error executing template "Designs/Swift/Paragraph/Swift_ProductNumber.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_5c0fa67753cf4b4e85097c7609d93197.Execute() in D:\dynamicweb.net\Solutions\Flex Media\baagoe.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\Paragraph\Swift_ProductNumber.cshtml:line 28
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> 2 @using Dynamicweb.Ecommerce.ProductCatalog 3 4 @{ 5 ProductViewModel product = new ProductViewModel(); 6 7 ProductViewModelSettings productSetting = new ProductViewModelSettings 8 { 9 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 10 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 11 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 12 ShopId = Pageview.Area.EcomShopId 13 }; 14 15 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 16 { 17 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 18 } else if (Pageview.Item["DummyProduct"] != null) { 19 string dummyProductId = ""; 20 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 21 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 22 if (productList.Products != null) 23 { 24 foreach (var p in productList.Products) { dummyProductId = p.Id; } 25 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 26 product = dummyProduct; 27 } else { 28 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 29 } 30 } else if (Pageview.Item["DummyProduct"] == null) { 31 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 32 } 33 34 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 35 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 36 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 37 } 38 39 @if (!Model.Item.GetBoolean("HideProductNumber") && product.Id != null) { 40 <div class="fs-7 opacity-85 @horizontalAlign item_@Model.Item.SystemName.ToLower()" itemprop="sku">@product.Number</div> 41 } else if (Pageview.IsVisualEditorMode) { 42 <div class="alert alert-warning">@Translate("No products available")</div> 43 } 44
Error executing template "Designs/Swift/Paragraph/Swift_ProductSpecification.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_1a81f04931564270b209fb7a159cc614.Execute() in D:\dynamicweb.net\Solutions\Flex Media\baagoe.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\Paragraph\Swift_ProductSpecification.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 4 @{ 5 bool isVisualEditor = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("VisualEdit")) ? Convert.ToBoolean(Dynamicweb.Context.Current.Request.QueryString.Get("VisualEdit")) : false; 6 7 ProductViewModel product = new ProductViewModel(); 8 9 ProductViewModelSettings productSetting = new ProductViewModelSettings 10 { 11 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 12 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 13 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 14 ShopId = Pageview.Area.EcomShopId 15 }; 16 17 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 18 { 19 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 20 } else if (Pageview.Item["DummyProduct"] != null) { 21 22 string dummyProductId = ""; 23 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 24 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 25 if (productList.Products != null) 26 { 27 foreach (var p in productList.Products) { dummyProductId = p.Id; } 28 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 29 product = dummyProduct; 30 } else { 31 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 32 } 33 } else if (Pageview.Item["DummyProduct"] == null) { 34 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 35 } 36 } 37 38 @if (product?.Id != null) { 39 IEnumerable<string> selectedDisplayGroupIds = Model.Item.GetRawValueString("DisplayGroups").Split(',').ToList(); 40 List<CategoryFieldViewModel> displayGroups = new List<CategoryFieldViewModel>(); 41 42 foreach (var selection in selectedDisplayGroupIds) 43 { 44 foreach (CategoryFieldViewModel group in product.FieldDisplayGroups.Values) 45 { 46 if (selection == group.Id) 47 { 48 displayGroups.Add(group); 49 } 50 } 51 } 52 53 bool showProductFields = Model.Item.GetBoolean("ProductFields"); 54 55 bool hideTitle = Model.Item.GetBoolean("HideTitle"); 56 57 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 58 59 string titleFontSize = Model.Item.GetRawValueString("TitleFontSize", "display-4"); 60 61 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 62 contentPadding = contentPadding == "none" ? string.Empty : contentPadding; 63 contentPadding = contentPadding == "small" ? " p-2 p-md-3" : contentPadding; 64 contentPadding = contentPadding == "large" ? " p-4 p-md-5" : contentPadding; 65 66 string layout = Model.Item.GetRawValueString("Layout", "list"); 67 string size = Model.Item.GetRawValueString("Size", "full"); 68 string gaps = size == "full" ? " gap-4" : " gap-2"; 69 70 71 if (Pageview.IsVisualEditorMode && displayGroups.Count() == 0) 72 { 73 product.ProductFields.Clear(); 74 product.ProductFields.Add(Translate("Width"), new FieldValueViewModel { Name = Translate("Width"), Value = "99cm" }); 75 product.ProductFields.Add(Translate("Height"), new FieldValueViewModel { Name = Translate("Height"), Value = "195cm" }); 76 showProductFields = true; 77 } 78 79 if (layout == "commas") 80 { 81 gaps = size == "full" ? " gap-4" : " gap-2"; 82 83 } 84 85 <div class="grid h-100@(gaps)@(theme)@(contentPadding) item_@Model.Item.SystemName.ToLower()"> 86 @if ((product.ProductFields != null && Model.Item.GetBoolean("ProductFields")) || (product.ProductCategories != null && Model.Item.GetBoolean("CategoryFields")) || (displayGroups.Count != 0)) { 87 if (!hideTitle) 88 { 89 <h2 class="g-col-12 @titleFontSize mb-0">@Model.Item.GetString("Title")</h2> 90 } 91 } 92 93 @if (displayGroups.Count != 0) { 94 foreach (var group in displayGroups) { 95 bool hideHeader = Model.Item.GetBoolean("HideGroupHeaders"); 96 97 if (!hideHeader) { 98 <h4 class="g-col-12 h4 mb-0">@group.Name</h4> 99 } 100 101 @RenderFieldsFromList(group.Fields, layout); 102 } 103 } 104 105 @if (product.ProductFields != null && showProductFields) { 106 if (product.ProductFields.Count > 0) { 107 @RenderFieldsFromList(product.ProductFields, layout); 108 } 109 } 110 111 @if (product.ProductCategories != null && Model.Item.GetBoolean("CategoryFields")) { 112 if (product.ProductCategories.Count > 0) { 113 foreach (var group in product.ProductCategories) { 114 CategoryFieldViewModel category = group.Value; 115 bool hideHeader = Model.Item.GetBoolean("HideGroupHeaders"); 116 117 if (!hideHeader) { 118 <h4 class="g-col-12 h4 mb-0">@group.Value.Name</h4> 119 } 120 121 @RenderFieldsFromList(category.Fields, layout); 122 } 123 } 124 } 125 </div> 126 } else if (Pageview.IsVisualEditorMode) { 127 <div class="alert alert-warning m-0">@Translate("No products available")</div> 128 } 129 130 @helper RenderFieldsFromList(Dictionary<string, FieldValueViewModel> fields, string layout) { 131 string size = Model.Item.GetRawValueString("Size", "full"); 132 string gaps = size != "full" ? " gap-1" : string.Empty; 133 bool hideFieldLabels = Model.Item.GetBoolean("HideFieldLabels"); 134 135 if (layout == "columns") { 136 <div class="g-col-12 grid@(gaps)"> 137 @foreach (var field in fields) { 138 @RenderField(field.Value, layout) 139 } 140 </div> 141 } 142 if (layout == "list") { 143 <dl class="g-col-12 grid@(gaps)"> 144 @foreach (var field in fields) { 145 @RenderField(field.Value, layout) 146 } 147 </dl> 148 } 149 if (layout == "table") { 150 string tableSize = size == "full" ? "" : " table-sm"; 151 <div class="g-col-12"> 152 <table class="table table-striped@(tableSize)"> 153 @foreach (var field in fields) { 154 @RenderField(field.Value, layout) 155 } 156 </table> 157 </div> 158 } 159 if (layout == "bullets") { 160 string listSize = size == "full" ? "" : "m-0 p-0 lh-1 fs-7 opacity-75"; 161 string listStyle = size == "full" ? "" : "style=\"list-style-position: inside\""; 162 <div class="g-col-12"> 163 <ul class="@listSize" @listStyle> 164 @foreach (var field in fields) { 165 @RenderField(field.Value, layout) 166 } 167 </ul> 168 </div> 169 } 170 if (layout == "commas") { 171 List<string> featuresList = new List<string>(); 172 173 foreach (var field in fields) 174 { 175 if (field.Value.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) { 176 List<string> options = new List<string>(); 177 foreach (FieldOptionValueViewModel option in field.Value.Value as System.Collections.Generic.List<FieldOptionValueViewModel>) { 178 if (!string.IsNullOrWhiteSpace(option.Value)) { 179 if (option.Value.ToString().Contains("#") && (Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) { 180 string colorSpan = "<span class=\"colorbox-sm\" style=\"background-color: " + option.Value + "\"></span>"; 181 options.Add(colorSpan); 182 } else if (!string.IsNullOrEmpty(option.Value)) { 183 options.Add(option.Name); 184 } 185 } 186 } 187 string optionsString = (string.Join(", ", options.Select(x => x.ToString()).ToArray())); 188 if ((Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) { 189 optionsString = (string.Join(" ", options.Select(x => x.ToString()).ToArray())); 190 } 191 192 if (!hideFieldLabels) { 193 featuresList.Add(field.Value.Name + ": " + optionsString); 194 } else { 195 featuresList.Add(optionsString); 196 } 197 } else { 198 if (!string.IsNullOrWhiteSpace(field.Value.Value.ToString())) { 199 if (field.Value.Value.ToString().Contains("#") && (Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) { 200 string colorSpan = "<span class=\"colorbox-sm\" style=\"background-color: " + field.Value.Value + "\"></span>"; 201 202 if (!hideFieldLabels) { 203 featuresList.Add(field.Value.Name + ": " + colorSpan); 204 } else { 205 featuresList.Add(colorSpan); 206 } 207 } else { 208 if (!hideFieldLabels) { 209 featuresList.Add(field.Value.Name + ": " + field.Value.Value.ToString()); 210 } else { 211 featuresList.Add(field.Value.Value.ToString()); 212 } 213 } 214 } 215 } 216 } 217 218 string featuresString = (string.Join(", ", featuresList.Select(x => x.ToString()).ToArray())); 219 220 <div class="g-col-12 opacity-75 fs-7">@featuresString</div> 221 } 222 } 223 224 @helper RenderField(FieldValueViewModel field, string layout) { 225 string size = Model.Item.GetRawValueString("Size", "full"); 226 string fieldValue = field?.Value != null ? field.Value.ToString() : ""; 227 bool hideFieldLabels = Model.Item.GetBoolean("HideFieldLabels"); 228 bool noValues = false; 229 230 if (!string.IsNullOrEmpty(fieldValue)) { 231 if (field.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) { 232 System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; 233 noValues = values.Count > 0 ? false : true; 234 } 235 } 236 237 if (!string.IsNullOrEmpty(fieldValue) && noValues == false) { 238 if (layout == "columns") { 239 240 <div class="grid g-col-6 g-col-lg-4 gap-1"> 241 @if(!hideFieldLabels) 242 { 243 <dt class="g-col-12 g-col-lg-4">@field.Name</dt> 244 } 245 <dd class="g-col-12 g-col-lg-8 mb-0 text-break">@RenderFieldValue(field)</dd> 246 </div> 247 } 248 if (layout == "list") { 249 if (!hideFieldLabels) 250 { 251 <dt class="g-col-4">@field.Name</dt> 252 } 253 <dd class="g-col-8 mb-0 text-break"> 254 @RenderFieldValue(field) 255 </dd> 256 } 257 if (layout == "table") { 258 <tr> 259 @if (!hideFieldLabels) 260 { 261 <th class="w-25 w-lg-50" scope="row">@field.Name</th> 262 } 263 <td class="text-break">@RenderFieldValue(field)</td> 264 </tr> 265 } 266 if (layout == "bullets") { 267 <li> 268 @if (!hideFieldLabels) 269 { 270 <strong>@field.Name</strong> 271 } 272 <span>@RenderFieldValue(field)</span> 273 </li> 274 } 275 } 276 } 277 278 @helper RenderFieldValue(FieldValueViewModel field) { 279 string fieldValue = field?.Value != null ? field.Value.ToString() : ""; 280 281 bool isLink = field?.Type == "Link"; 282 bool isColor = false; 283 bool isBrandName = field?.SystemName == "Brand_name"; 284 285 fieldValue = fieldValue == "False" ? Translate("No") : fieldValue; 286 fieldValue = fieldValue == "True" ? Translate("Yes") : fieldValue; 287 288 289 if (field.Value.GetType() == typeof(System.Collections.Generic.List<Dynamicweb.Ecommerce.ProductCatalog.FieldOptionValueViewModel>)) 290 { 291 int valueCount = 0; 292 System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; 293 int totalValues = values.Count; 294 295 foreach (FieldOptionValueViewModel option in values) 296 { 297 if (!string.IsNullOrEmpty(option.Value)) 298 { 299 if (option.Value.Substring(0,1) == "#") { 300 isColor = true; 301 } 302 } 303 304 if (!isColor) { 305 @option.Name 306 } else { 307 <span class="colorbox-sm" style="background-color: @option.Value" title="@option.Name"></span> 308 } 309 310 if (valueCount != totalValues && valueCount < (totalValues - 1)) { 311 if (isColor) { 312 <text> </text> 313 } else { 314 <text>, </text> 315 } 316 } 317 valueCount++; 318 } 319 } 320 else 321 { 322 if (fieldValue.Substring(0,1) == "#") { 323 isColor = true; 324 } 325 326 if (!isColor) { 327 if(isLink) 328 { 329 string linktTitle = !fieldValue.Contains("aspx") ? fieldValue : Translate("Go to link"); 330 string target = Pageview.AreaSettings.GetBoolean("OpenLinksInNewTab") && fieldValue.Contains("http") ? "target=\"_blank\"" : string.Empty; 331 string rel = Pageview.AreaSettings.GetBoolean("OpenLinksInNewTab") && fieldValue.Contains("http") ? "rel=\"noopener\"" : string.Empty; 332 333 <a href="@field.Value" title="@field.Name" @target @rel>@linktTitle</a> 334 } 335 else if (isBrandName) 336 { 337 <span itemprop="brand" itemtype="https://schema.org/Brand" itemscope> 338 <span itemprop="name">@fieldValue</span> 339 </span> 340 } 341 else 342 { 343 @fieldValue 344 } 345 346 } else { 347 <span class="colorbox-sm" style="background-color: @fieldValue" title="@fieldValue"></span> 348 } 349 } 350 } 351
Error executing template "Designs/Swift/Paragraph/Swift_ProductDefaultImage.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_854b21fd178e485083165b6429aeea7e.Execute() in D:\dynamicweb.net\Solutions\Flex Media\baagoe.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\Paragraph\Swift_ProductDefaultImage.cshtml:line 33
   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 5 @{ 6 ProductViewModel product = new ProductViewModel(); 7 8 ProductViewModelSettings productSetting = new ProductViewModelSettings 9 { 10 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 11 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 12 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 13 ShopId = Pageview.Area.EcomShopId 14 }; 15 16 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 17 { 18 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 19 } 20 else if (Pageview.Item["DummyProduct"] != null) 21 { 22 string dummyProductId = ""; 23 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 24 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 25 if (productList.Products != null) 26 { 27 foreach (var p in productList.Products) { dummyProductId = p.Id; } 28 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 29 product = dummyProduct; 30 } 31 else 32 { 33 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 34 } 35 } 36 else if (Pageview.Item["DummyProduct"] == null) 37 { 38 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 39 } 40 41 string imagePath = product?.DefaultImage?.Value ?? ""; 42 imagePath = Dynamicweb.Context.Current.Server.UrlEncode(imagePath); 43 44 string ratio = Model.Item.GetRawValueString("ImageAspectRatio", ""); 45 ratio = ratio != "0" ? ratio : ""; 46 string ratioCssClass = ratio != "" ? " ratio" : ""; 47 string ratioVariable = ratio != "" ? "--bs-aspect-ratio: " + ratio : ""; 48 49 string width = Model.Item.GetRawValueString("Width", "auto"); 50 int smallImageSize = 640; 51 int largeImageSize = width == "auto" ? 1280 : Convert.ToInt32(width); 52 53 string imagePathXs = "/Admin/Public/GetImage.ashx?width=" + smallImageSize + "&image=" + imagePath + "&format=webp"; 54 string imagePathS = "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePath + "&format=webp"; 55 string imagePathFallBack = "/Admin/Public/GetImage.ashx?width=" + largeImageSize + "&image=" + imagePath + "&format=webp"; 56 57 var badgeParms = new Dictionary<string, object>(); 58 badgeParms.Add("size", "h7"); 59 badgeParms.Add("saleBadgeType", Model.Item.GetRawValue("SaleBadgeType")); 60 badgeParms.Add("saleBadgeCssClassName", Model.Item.GetRawValue("SaleBadgeDesign")); 61 badgeParms.Add("newBadgeCssClassName", Model.Item.GetRawValue("NewBadgeDesign")); 62 badgeParms.Add("newPublicationDays", Model.Item.GetInt32("NewPublicationDays")); 63 badgeParms.Add("campaignBadgesValues", Model.Item.GetRawValueString("CampaignBadges")); 64 65 string badgeSize = Model.Item.GetRawValueString("BadgeSize", "fs-2"); 66 67 bool showFavoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 68 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 69 bool anonymousUser = Pageview.User == null; 70 71 var favoriteParameters = new Dictionary<string, object>(); 72 if (!anonymousUser && showFavoritesSelector) 73 { 74 int defaultFavoriteListId = 0; 75 76 IEnumerable<FavoriteList> favoreiteLists = Pageview.User.GetFavoriteLists(); 77 if (favoreiteLists.Count() == 1) 78 { 79 foreach (FavoriteList list in favoreiteLists) 80 { 81 defaultFavoriteListId = list.ListId; 82 } 83 } 84 85 favoriteParameters.Add("ListId", defaultFavoriteListId); 86 } 87 88 @* Theme settings *@ 89 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 90 string themeBorder = !string.IsNullOrWhiteSpace(theme) ? "border: 1px solid rgba(0,0,0,0)" : ""; 91 string themePadding = !string.IsNullOrWhiteSpace(theme) ? "p-2 p-lg-3" : ""; 92 } 93 94 @if (product.Id != null) 95 { 96 string imageId = "ProductImage_" + product.Id + product.VariantId; 97 98 bool saleBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("SaleBadgeDesign")) && Model.Item.GetRawValueString("SaleBadgeDesign") != "none" ? true : false; 99 bool newBadgeEnabled = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("NewBadgeDesign")) && Model.Item.GetRawValueString("NewBadgeDesign") != "none" ? true : false; 100 DateTime createdDate = product.Created.Value; 101 bool showBadges = saleBadgeEnabled && product.Discount.Price != 0 ? true : false; 102 showBadges = (newBadgeEnabled && Model.Item.GetInt32("NewPublicationDays") == 0) || (newBadgeEnabled && (createdDate.AddDays(Model.Item.GetInt32("NewPublicationDays")) > DateTime.Now)) ? true : showBadges; 103 showBadges = !string.IsNullOrEmpty(Model.Item.GetRawValueString("CampaignBadges")) ? true : showBadges; 104 105 string fullWidth = width == "auto" ? "w-100" : ""; 106 string customWidth = width != "auto" ? "style=\"width: " + width + "px\"" : "style=\"min-width: 60px\""; 107 108 if (!string.IsNullOrEmpty(imagePath)) 109 { 110 <div class="h-100 @fullWidth @theme position-relative item_@Model.Item.SystemName.ToLower()" @customWidth> 111 <div class="ratio" style="@(ratioVariable)"> 112 <div class="d-flex justify-content-center align-items-center"> 113 <img id="@imageId" 114 srcset=" 115 @imagePathXs @(smallImageSize)w, 116 @imagePathS @(largeImageSize)w" 117 sizes="(min-width: 992px) 33vw, 50vw" 118 src="@imagePathFallBack" 119 loading="lazy" 120 decoding="async" 121 class="h-100 w-100 @themePadding" 122 style="object-fit: contain; @themeBorder" 123 alt="@product.Name"> 124 </div> 125 </div> 126 127 @if (showBadges) 128 { 129 <div class="position-absolute top-0 left-0 p-2 p-lg-3 ps-0 ps-lg-0 @badgeSize"> 130 @RenderPartial("Components/EcommerceBadge.cshtml", product, badgeParms) 131 </div> 132 } 133 134 @if (!anonymousUser && showFavoritesSelector && product.VariantInfo.VariantInfo == null) 135 { 136 <div class="position-absolute top-0 end-0 my-3" style="z-index: 2"> 137 @RenderPartial("Components/ToggleFavorite.cshtml", product, favoriteParameters) 138 </div> 139 } 140 </div> 141 } 142 } 143 else if (Pageview.IsVisualEditorMode) 144 { 145 <div class="alert alert-dark m-0">@Translate("No products available")</div> 146 } 147
Error executing template "Designs/Swift/Paragraph/Swift_ProductPrice.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_b812fa6e85384cafa2d4b73f78a3f20e.Execute() in D:\dynamicweb.net\Solutions\Flex Media\baagoe.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\Paragraph\Swift_ProductPrice.cshtml:line 29
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> 2 @using Dynamicweb.Ecommerce.ProductCatalog 3 4 @{ 5 ProductViewModel product = new ProductViewModel(); 6 7 ProductViewModelSettings productSetting = new ProductViewModelSettings 8 { 9 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 10 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 11 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 12 ShopId = Pageview.Area.EcomShopId 13 }; 14 15 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 16 { 17 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 18 } else if (Pageview.Item["DummyProduct"] != null) { 19 20 string dummyProductId = ""; 21 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 22 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 23 if (productList.Products != null) 24 { 25 foreach (var p in productList.Products) { dummyProductId = p.Id; } 26 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 27 product = dummyProduct; 28 } else { 29 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 30 } 31 } else if (Pageview.Item["DummyProduct"] == null) { 32 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 33 } 34 35 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 36 bool anonymousUser = Pageview.User == null; 37 bool isErpConnectionDown = !Dynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplatesHelper.IsWebServiceConnectionAvailable(); 38 bool hidePrice = anonymousUsersLimitations.Contains("price") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHidePrices") && isErpConnectionDown; 39 40 string priceFontSize = Model.Item.GetRawValueString("PriceSize", "fs-2"); 41 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 42 string layout = Model.Item.GetRawValueString("Layout", "horizontal"); 43 string textAlign = horizontalAlign == "center" ? "text-center" : string.Empty; 44 textAlign = horizontalAlign == "end" ? "text-end" : textAlign; 45 46 horizontalAlign = horizontalAlign == "center" && layout == "horizontal" ? "justify-content-center" : horizontalAlign; 47 horizontalAlign = horizontalAlign == "end" && layout == "horizontal" ? "justify-content-end" : horizontalAlign; 48 horizontalAlign = horizontalAlign == "center" && layout == "vertical" ? "align-items-center" : horizontalAlign; 49 horizontalAlign = horizontalAlign == "end" && layout == "vertical" ? "align-items-end" : horizontalAlign; 50 51 string flexDirection = layout == "horizontal" ? string.Empty : "flex-column"; 52 string flexGap = layout == "horizontal" ? "gap-3" : string.Empty; 53 string order = layout == "horizontal" ? string.Empty : "order-2"; 54 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? "px-2 theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 55 theme = GetViewParameter("theme") != null ? GetViewParameterString("theme") : theme; 56 } 57 58 @if (!hidePrice && product.Id != null) 59 { 60 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 61 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 62 63 string priceMin = ""; 64 string priceMax = ""; 65 66 string liveInfoClass = ""; 67 string productInfoFeed = ""; 68 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplatesHelper.IsLazyLoadingForProductInfoEnabled; 69 if (isLazyLoadingForProductInfoEnabled) 70 { 71 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 72 { 73 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 74 if (!string.IsNullOrEmpty(productInfoFeed)) 75 { 76 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 77 } 78 } 79 liveInfoClass = "js-live-info"; 80 } 81 82 <div class="@textAlign @liveInfoClass item_@Model.Item.SystemName.ToLower()" data-product-id="@product.Id" @productInfoFeed> 83 <div class="@priceFontSize m-0 d-flex @flexDirection @flexGap @horizontalAlign" itemprop="offers" itemscope itemtype="https://schema.org/Offer"> 84 <span itemprop="priceCurrency" content="@product.Price.CurrencyCode" class="d-none"></span> 85 86 @if (showPricesWithVat == "false" && !neverShowVat) 87 { 88 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 89 { 90 <span itemprop="price" content="" class="d-none"></span> 91 <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> 92 } 93 else 94 { 95 string beforePrice = product.PriceBeforeDiscount.PriceWithoutVatFormatted; 96 97 <span itemprop="price" content="@product.Price.PriceWithoutVat" class="d-none"></span> 98 if (product.Price.Price != product.PriceBeforeDiscount.Price) 99 { 100 <span class="text-decoration-line-through opacity-75 @order">@beforePrice</span> 101 } 102 } 103 } 104 else 105 { 106 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 107 { 108 <span itemprop="price" content="" class="d-none"></span> 109 <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> 110 } 111 else 112 { 113 string beforePrice = product.PriceBeforeDiscount.PriceFormatted; 114 115 <span itemprop="price" content="@product.Price.Price" class="d-none"></span> 116 117 if (product.Price.Price != product.PriceBeforeDiscount.Price) 118 { 119 <span class="text-decoration-line-through opacity-75 @order"> 120 <span class="text-price">@beforePrice</span> 121 </span> 122 } 123 } 124 } 125 126 @if (showPricesWithVat == "false" && !neverShowVat) 127 { 128 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 129 { 130 <span class="text-price js-text-price"> 131 <div class="spinner-border" role="status"></div> 132 </span> 133 } 134 else 135 { 136 string price = product.Price.PriceWithoutVatFormatted; 137 if (product?.VariantInfo?.VariantInfo != null) 138 { 139 priceMin = product?.VariantInfo?.PriceMin?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithoutVatFormatted : ""; 140 priceMax = product?.VariantInfo?.PriceMax?.PriceWithoutVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithoutVatFormatted : ""; 141 } 142 if (priceMin != priceMax) 143 { 144 price = priceMin + " - " + priceMax; 145 } 146 <span class="@theme"> 147 <span class="text-price">@price</span> 148 </span> 149 } 150 } 151 else 152 { 153 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 154 { 155 <span class="text-price js-text-price"> 156 <div class="spinner-border" role="status"></div> 157 </span> 158 } 159 else 160 { 161 string price = product.Price.PriceFormatted; 162 if (product?.VariantInfo?.VariantInfo != null) 163 { 164 priceMin = product?.VariantInfo?.PriceMin?.PriceFormatted != null ? product.VariantInfo.PriceMin.PriceFormatted : ""; 165 priceMax = product?.VariantInfo?.PriceMax?.PriceFormatted != null ? product.VariantInfo.PriceMax.PriceFormatted : ""; 166 } 167 if (priceMin != priceMax) 168 { 169 price = priceMin + " - " + priceMax; 170 } 171 <span class="@theme"> 172 <span class="text-price">@price</span> 173 </span> 174 } 175 } 176 177 @* Stock state for Schema.org, start *@ 178 @{ 179 Uri url = Dynamicweb.Context.Current.Request.Url; 180 } 181 182 <link itemprop="url" href="@url" /> 183 184 @{ 185 bool IsNeverOutOfStock = product.NeverOutOfstock; 186 } 187 188 @if (IsNeverOutOfStock) 189 { 190 <span itemprop="availability" class="d-none">@Translate("Available in stock")</span> 191 } 192 else 193 { 194 if (product.StockLevel > 0) 195 { 196 <span itemprop="availability" class="d-none">InStock</span> 197 } 198 else 199 { 200 <span itemprop="availability" class="d-none">OutOfStock</span> 201 } 202 } 203 @* Stock state for Schema.org, stop *@ 204 205 </div> 206 207 @if (showPricesWithVat == "false" && !neverShowVat) 208 { 209 if (isLazyLoadingForProductInfoEnabled && !Pageview.IsVisualEditorMode) 210 { 211 <small class="opacity-85 fst-normal js-text-price-with-vat d-none" data-suffix="@Translate("Incl. VAT")"></small> 212 } 213 else 214 { 215 string price = product.Price.PriceWithVatFormatted; 216 if (product?.VariantInfo?.VariantInfo != null) 217 { 218 priceMin = product?.VariantInfo?.PriceMin?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMin.PriceWithVatFormatted : ""; 219 priceMax = product?.VariantInfo?.PriceMax?.PriceWithVatFormatted != null ? product.VariantInfo.PriceMax.PriceWithVatFormatted : ""; 220 } 221 if (priceMin != priceMax) 222 { 223 price = priceMin + " - " + priceMax; 224 } 225 <small class="opacity-85 fst-normal">@price @Translate("Incl. VAT")</small> 226 } 227 } 228 </div> 229 } else if (Pageview.IsVisualEditorMode) { 230 <div class="alert alert-dark m-0" role="alert"> 231 <span>@Translate("No products available")</span> 232 </div> 233 } 234
Error executing template "Designs/Swift/Paragraph/Swift_ProductAddToCart.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_f0919c22f9354921947dfa315ac1aac4.Execute() in D:\dynamicweb.net\Solutions\Flex Media\baagoe.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\Paragraph\Swift_ProductAddToCart.cshtml:line 30
   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 5 @{ 6 ProductViewModel product = new ProductViewModel(); 7 8 ProductViewModelSettings productSetting = new ProductViewModelSettings 9 { 10 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 11 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 12 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 13 ShopId = Pageview.Area.EcomShopId 14 }; 15 16 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 17 { 18 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 19 } else if (Pageview.Item["DummyProduct"] != null) { 20 21 string dummyProductId = ""; 22 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 23 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 24 if (productList.Products != null) 25 { 26 foreach (var p in productList.Products) { dummyProductId = p.Id; } 27 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 28 product = dummyProduct; 29 } else { 30 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 31 } 32 } else if (Pageview.Item["DummyProduct"] == null) { 33 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 34 } 35 36 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 37 horizontalAlign = horizontalAlign == "center" ? "justify-content-center" : horizontalAlign; 38 horizontalAlign = horizontalAlign == "end" ? "justify-content-end" : horizontalAlign; 39 horizontalAlign = horizontalAlign == "full" ? "" : horizontalAlign; 40 41 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 42 bool anonymousUser = Pageview.User == null; 43 bool isErpConnectionDown = !Dynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplatesHelper.IsWebServiceConnectionAvailable(); 44 bool hideAddToCart = anonymousUsersLimitations.Contains("cart") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHideAddToCart") && isErpConnectionDown; 45 hideAddToCart = Pageview.IsVisualEditorMode ? false : hideAddToCart; 46 bool favoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 47 bool quantitySelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowQuantitySelector")) ? Model.Item.GetBoolean("ShowQuantitySelector") : false; 48 bool hideInventory = !string.IsNullOrEmpty(Model.Item.GetString("HideInventory")) ? Model.Item.GetBoolean("HideInventory") : false; 49 bool hideStockState = !string.IsNullOrEmpty(Model.Item.GetString("HideStockState")) ? Model.Item.GetBoolean("HideStockState") : false; 50 51 string buttonSize = Model.Item.GetRawValueString("ButtonSize", "regular"); 52 buttonSize = buttonSize == "small" ? " btn-sm" : buttonSize; 53 buttonSize = buttonSize == "regular" ? string.Empty : buttonSize; 54 buttonSize = buttonSize == "large" ? " btn-lg" : buttonSize; 55 } 56 57 58 @if (!hideAddToCart && product.Id != null) { 59 string iconPath = "/Files/icons/"; 60 string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 61 if (!url.Contains("LayoutTemplate")) 62 { 63 url += url.Contains("?") ? "&LayoutTemplate=Swift_MiniCart.cshtml" : "?LayoutTemplate=Swift_MiniCart.cshtml"; 64 } 65 66 string disableAddToCart = (product.StockLevel <= 0) ? "disabled" : ""; 67 bool isNeverOutOfStock = product.NeverOutOfstock; 68 disableAddToCart = isNeverOutOfStock ? "" : disableAddToCart; 69 70 string whenVariantsExist = Model.Item.GetRawValueString("WhenVariantsExist", "hide"); 71 72 string flexFill = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "flex-fill" : ""; 73 string fullWidth = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "w-100" : ""; 74 string addToCartIcon = Model.Item.GetRawValueString("Icon", iconPath + "shopping-cart.svg"); 75 string addToCartLabel = !addToCartIcon.Contains("_none") ? "<span class=\"icon-2\">" + ReadFile(addToCartIcon) + "</span>" : ""; 76 addToCartLabel += !addToCartIcon.Contains("_none") && !Model.Item.GetBoolean("HideButtonText") ? " " : ""; 77 addToCartLabel += !Model.Item.GetBoolean("HideButtonText") ? Translate("Add to cart") : ""; 78 79 if (product.VariantInfo.VariantInfo == null || whenVariantsExist == "disable") { 80 string minQty = product.PurchaseMinimumQuantity != 1 ? "min=\"" + product.PurchaseMinimumQuantity.ToString() + "\"" : "min=\"1\""; 81 string stepQty = product.PurchaseQuantityStep > 1 ? product.PurchaseQuantityStep.ToString() : "1"; 82 string valueQty = product.PurchaseMinimumQuantity > product.PurchaseQuantityStep ? product.PurchaseMinimumQuantity.ToString() : stepQty; 83 string qtyValidCheck = stepQty != "1" ? "onkeyup=\"swift.Cart.QuantityValidate(event)\"" : ""; 84 disableAddToCart = product.VariantInfo.VariantInfo != null && string.IsNullOrEmpty(product.VariantId) ? "disabled" : disableAddToCart; 85 86 <div class="d-flex @horizontalAlign @fullWidth item_@Model.Item.SystemName.ToLower()"> 87 <form method="post" action="@url" class="@fullWidth" style="z-index: 1"> 88 <input type="hidden" name="redirect" value="false" /> 89 <input type="hidden" name="ProductId" value="@product.Id" /> 90 <input type="hidden" name="ProductName" value="@product.Name" /> 91 <input type="hidden" name="ProductVariantName" value="@product.VariantName" /> 92 <input type="hidden" name="ProductCurrency" value="@Dynamicweb.Ecommerce.Common.Context.Currency.Code" /> 93 <input type="hidden" name="ProductPrice" value="@product.Price.Price" /> 94 <input type="hidden" name="ProductReferer" value="component_ProductAddToCart" /> 95 <input type="hidden" name="cartcmd" value="add" /> 96 97 @if (!string.IsNullOrEmpty(product.VariantId)) { 98 <input type="hidden" name="VariantId" value="@product.VariantId" /> 99 } 100 101 @if (quantitySelector || (!anonymousUser && favoritesSelector && product.VariantInfo.VariantInfo == null)) { 102 <div class="d-flex flex-row w-100"> 103 @if (!anonymousUser && favoritesSelector && product.VariantInfo.VariantInfo == null) { 104 @RenderPartial("Components/ToggleFavorite.cshtml", product) 105 } 106 107 <div class="input-group input-primary-button-group flex-nowrap"> 108 <input id="Quantity_@(product.Id)_@product.VariantId" name="Quantity" value="@valueQty" step="@stepQty" @minQty class="form-control" style="min-width: 60px; max-width: 100px; z-index: 1" type="number" onkeydown="swift.Cart.UpdateOnEnterKey(event)"> 109 <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary @(buttonSize) @flexFill js-add-to-cart-button" style="white-space: nowrap" @disableAddToCart title="@Translate("Add to cart")" id="AddToCartButton@(product.Id)_@Pageview.CurrentParagraph.ID"> 110 @if (!Model.Item.GetBoolean("HideButtonText")) 111 { 112 <span class="text-nowrap d-flex align-items-center justify-content-center gap-2"> 113 @addToCartLabel 114 </span> 115 } 116 else 117 { 118 @addToCartLabel 119 } 120 </button> 121 122 </div> 123 @if (stepQty != "1") { 124 <div class="invalid-feedback d-none"> 125 @Translate("Please select a quantity that is dividable by") @stepQty 126 </div> 127 } 128 </div> 129 } else { 130 <div class="d-flex flex-row w-100" style="z-index: 1;"> 131 @if (!anonymousUser && favoritesSelector && product.VariantInfo.VariantInfo == null) { 132 @RenderPartial("Components/ToggleFavorite.cshtml", product) 133 } 134 <input id="Quantity_@(product.Id)_@product.VariantId" name="Quantity" value="@valueQty" type="hidden"> 135 <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary@(buttonSize) @flexFill js-add-to-cart-button" @disableAddToCart title="@Translate("Add to cart")" id="AddToCartButton@(product.Id)_@Pageview.CurrentParagraph.ID"> 136 @if (!Model.Item.GetBoolean("HideButtonText")) 137 { 138 <span class="text-nowrap d-flex align-items-center justify-content-center gap-2"> 139 @addToCartLabel 140 </span> 141 } 142 else 143 { 144 @addToCartLabel 145 } 146 </button> 147 </div> 148 } 149 </form> 150 </div> 151 } else if (whenVariantsExist == "modal") { 152 string buttonText = Translate("Select"); 153 154 string variantSelectorServicePageId = !string.IsNullOrEmpty(Model.Item.GetString("VariantSelectorServicePageId")) ? Model.Item.GetLink("VariantSelectorServicePageId").PageId.ToString() : ""; 155 variantSelectorServicePageId = variantSelectorServicePageId != "" ? variantSelectorServicePageId : GetPageIdByNavigationTag("VariantSelectorService").ToString(); 156 157 <div class="d-flex @horizontalAlign w-100 item_@Model.Item.SystemName.ToLower()"> 158 <form action="/Default.aspx?ID=@variantSelectorServicePageId" data-response-target-element="DynamicModalContent" data-preloader="inline" style="z-index: 1" class="@fullWidth"> 159 <input type="hidden" name="ProductID" value="@product.Id" /> 160 <input type="hidden" name="QuantitySelector" value="@quantitySelector.ToString()" /> 161 <input type="hidden" name="HideInventory" value="@hideInventory.ToString()" /> 162 <input type="hidden" name="HideStockState" value="@hideStockState.ToString()" /> 163 <input type="hidden" name="VariantSelectorServicePage" value="@variantSelectorServicePageId" /> 164 <input type="hidden" name="ViewType" value="ModalContent" /> 165 <button type="button" onclick="swift.PageUpdater.Update(event)" class="btn btn-primary @fullWidth" title="@Translate("Select")" data-bs-toggle="modal" data-bs-target="#DynamicModal" id="OpenVariantSelectorModal@(product.Id)_@Pageview.CurrentParagraph.ID">@buttonText</button> 166 </form> 167 </div> 168 } 169 } else if (Pageview.IsVisualEditorMode) { 170 <div class="alert alert-dark m-0">@Translate("No products available")</div> 171 } 172