Error executing template "Designs/Swift/eCom/ProductCatalog/ProductViewDetail_Custom.cshtml" System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Dynamicweb.Ecommerce.Products.GroupRelation.GetGroupRelationsByChildId(String childId) at Dynamicweb.Ecommerce.ProductCategoryFieldService.GetCategoriesFromGroups(List`1 categories, HashSet`1& idsHash, IEnumerable`1 groups, Int32 currentLevel, Int32 minLevel, Nullable`1 maxLevel) at Dynamicweb.Ecommerce.ProductCategoryFieldService.GetInheritedCategories(IEnumerable`1 groups, Boolean includeProductProperties) at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetFieldDisplayGroupValues(ProductViewModelSettings settings, Product product, String languageID, Lazy`1 productIds) at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass3_1.<BulkCreateView>b__60() at System.Lazy`1.CreateValue() at System.Lazy`1.LazyInitValue() at CompiledRazorTemplates.Dynamic.RazorEngine_618c57e6e6384509b5d86e0ef5304627.Execute() in E:\WEB\flowconcept.stagingsite.dk\Files\Templates\Designs\Swift\eCom\ProductCatalog\ProductViewDetail_Custom.cshtml:line 57 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 ViewModelTemplate<ProductViewModel> 2 @using System.Collections.Generic 3 @using System.Linq 4 @using Dynamicweb.Rendering 5 @using Dynamicweb.Ecommerce.ProductCatalog 6 @using Dynamicweb.Core 7 8 @{ 9 Dynamicweb.Frontend.PageView.Current().Meta.AddTag("og:image", Model.DefaultImage.Value); 10 Dynamicweb.Frontend.PageView.Current().Meta.AddTag("og:image:alt", Model.Name); 11 Dynamicweb.Frontend.PageView.Current().Meta.AddTag("og:description", string.IsNullOrEmpty(Model.MetaDescription) ? Model.Name : Model.MetaDescription); 12 13 Dynamicweb.Frontend.PageView.Current().Meta.AddTag("twitter:image", Model.DefaultImage.Value); 14 Dynamicweb.Frontend.PageView.Current().Meta.AddTag("twitter:image:alt", Model.Name); 15 Dynamicweb.Frontend.PageView.Current().Meta.AddTag("twitter:description", string.IsNullOrEmpty(Model.MetaDescription) ? Model.Name : Model.MetaDescription); 16 } 17 18 @{ 19 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 20 { 21 Dynamicweb.Context.Current.Items["ProductDetails"] = Model; 22 } 23 else 24 { 25 Dynamicweb.Context.Current.Items.Add("ProductDetails", Model); 26 } 27 28 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]); 29 Dynamicweb.Context.Current.Items.Add("ProductDetailsId", Model.Id); 30 Dynamicweb.Context.Current.Items.Add("ProductDetailsVariantId", Model.VariantId); 31 string googleAnalyticsMeasurementID = Pageview.AreaSettings.GetString("GoogleAnalyticsMeasurementID"); 32 33 if (isLazyLoadingForProductInfoEnabled) 34 { 35 string showPricesWithVat = Pageview.Area.EcomPricesWithVat.ToLower(); 36 bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat); 37 bool hasVariantId = !string.IsNullOrEmpty(Model.VariantId); 38 string variantIdParam = hasVariantId ? $"/{Model.VariantId}" : ""; 39 string priceFilledProperties = $"Price,PriceFormatted{(showPricesWithVat == "false" && !neverShowVat ? ",PriceWithVat,PriceWithVatFormatted" : "")}"; 40 string productInfoFeed = $@"/dwapi/ecommerce/products/{Model.Id}{variantIdParam} 41 ?UserId={Converter.ToString(Pageview.User?.ID)} 42 &LanguageId={Pageview.Area.EcomLanguageId}&CurrencyCode={Pageview.Area.EcomCurrencyId}&CountryCode={Pageview.Area.EcomCountryCode}&ShopId={Pageview.Area.EcomShopId} 43 &FilledProperties=Id,Price,PriceBeforeDiscount,StockLevel,VariantInfo,NeverOutOfstock,Prices 44 &PriceSettings.ShowPricesWithVat={Pageview.Area.EcomPricesWithVat} 45 &PriceSettings.FilledProperties={priceFilledProperties} 46 &getproductinfo=true"; 47 Dynamicweb.Context.Current.Items["ProductInfoFeed"] = productInfoFeed; 48 49 50 <script type="module"> 51 swift.LiveProductInfo.init(); 52 </script> 53 } 54 55 List<CategoryFieldViewModel> displayGroups = new List<CategoryFieldViewModel>(); 56 57 foreach (CategoryFieldViewModel group in Model.FieldDisplayGroups.Values) 58 { 59 displayGroups.Add(group); 60 } 61 62 List<dynamic> specs = new List<dynamic>(); 63 64 CategoryFieldViewModel displayGroupSpecs = Model.FieldDisplayGroups.FirstOrDefault(fdg => fdg.Value.Id == "Frontend_Specifications").Value; 65 66 if (displayGroupSpecs != null && displayGroupSpecs.Fields.Any()) 67 { 68 foreach (KeyValuePair<string, FieldValueViewModel> field in displayGroupSpecs.Fields) 69 { 70 specs.Add(new 71 { 72 label = field.Value.Name, 73 value = field.Value.Value 74 }); 75 } 76 } 77 78 dynamic pdfGeneratorData = Newtonsoft.Json.JsonConvert.SerializeObject(new 79 { 80 logo = "/Files/Templates/Designs/Swift/Assets/Images/pdf-logo.svg", 81 name = Model.Name, 82 number = Model.Number, 83 description = Model.ShortDescription, 84 extraDescription = string.Empty, 85 specs = specs, 86 image = Model.DefaultImage.Value, 87 footer = new 88 { 89 company = "Flowconcept ApS", 90 address = "Kometvej 11", 91 city = "8700 Horsens", 92 web = "flowconcept.dk", 93 mail = "info@flowconcept.dk", 94 phone = "+45 75 61 55 55", 95 cvr = "25554973" 96 }, 97 translations = new 98 { 99 productNumber = Translate("Flowconcept - PDF - ProductNumber - Text", "Varenr."), 100 specsHeader = Translate("Flowconcept - PDF - Specifications - Header", "SPECIFIKATIONER"), 101 webText = Translate("Flowconcept - PDF - Web - Text", "www"), 102 mailText = Translate("Flowconcept - PDF - Mail - Text", "Mail"), 103 phoneText = Translate("Flowconcept - PDF - Phone - Text", "Telefon"), 104 cvrText = Translate("Flowconcept - PDF - Cvr - Text", "CVR"), 105 } 106 }); 107 } 108 109 @if (!string.IsNullOrWhiteSpace(googleAnalyticsMeasurementID)) 110 { 111 <script> 112 gtag("event", "view_item", { 113 currency: "@Model.Price.CurrencyCode", 114 value: @PriceViewModelExtensions.ToStringInvariant(Model.Price), 115 items: [ 116 { 117 item_id: "@Model.Number", 118 item_name: "@Dynamicweb.Core.Encoders.HtmlEncoder.JavaScriptStringEncode(Model.Name)", 119 currency: "@Model.Price.CurrencyCode", 120 price: @PriceViewModelExtensions.ToStringInvariant(Model.Price).Replace(",",".") 121 } 122 ] 123 }); 124 </script> 125 } 126 <script> 127 window.addEventListener('load', function (event) { 128 swift.Video.init(); 129 }); 130 131 window.pdfGeneratorData = @pdfGeneratorData; 132 133 </script> 134 <script src="/Files/Templates/Designs/Swift/Assets/js/custom.pdf-generator.js" crossorigin="anonymous" defer></script> 135 136
Push-in vinkel 10mm
#LE-31021000
Error executing template "Designs/Swift/Paragraph/Swift_ProductSpecification_Custom.cshtml" System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Dynamicweb.Ecommerce.Products.GroupRelation.GetGroupRelationsByChildId(String childId) at Dynamicweb.Ecommerce.ProductCategoryFieldService.GetCategoriesFromGroups(List`1 categories, HashSet`1& idsHash, IEnumerable`1 groups, Int32 currentLevel, Int32 minLevel, Nullable`1 maxLevel) at Dynamicweb.Ecommerce.ProductCategoryFieldService.GetInheritedCategories(IEnumerable`1 groups, Boolean includeProductProperties) at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetFieldDisplayGroupValues(ProductViewModelSettings settings, Product product, String languageID, Lazy`1 productIds) at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass3_1.<BulkCreateView>b__60() 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_668316364c724123ace1748f73646500.Execute() in E:\WEB\flowconcept.stagingsite.dk\Files\Templates\Designs\Swift\Paragraph\Swift_ProductSpecification_Custom.cshtml:line 44 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 is object && !string.IsNullOrEmpty(field.Value.Value.ToString())) 176 { 177 if (field.Value.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) { 178 List<string> options = new List<string>(); 179 foreach (FieldOptionValueViewModel option in field.Value.Value as System.Collections.Generic.List<FieldOptionValueViewModel>) { 180 if (!string.IsNullOrWhiteSpace(option.Value)) { 181 if (option.Value.ToString().Contains("#") && (Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) { 182 string colorSpan = "<span class=\"colorbox-sm\" style=\"background-color: " + option.Value + "\"></span>"; 183 options.Add(colorSpan); 184 } else if (!string.IsNullOrEmpty(option.Value)) { 185 options.Add(option.Name); 186 } 187 } 188 } 189 string optionsString = (string.Join(", ", options.Select(x => x.ToString()).ToArray())); 190 if ((Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) { 191 optionsString = (string.Join(" ", options.Select(x => x.ToString()).ToArray())); 192 } 193 194 if (!hideFieldLabels) { 195 featuresList.Add(field.Value.Name + ": " + optionsString); 196 } else { 197 featuresList.Add(optionsString); 198 } 199 } else { 200 if (!string.IsNullOrWhiteSpace(field.Value.Value.ToString())) { 201 if (field.Value.Value.ToString().Contains("#") && (Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) { 202 string colorSpan = "<span class=\"colorbox-sm\" style=\"background-color: " + field.Value.Value + "\"></span>"; 203 204 if (!hideFieldLabels) { 205 featuresList.Add(field.Value.Name + ": " + colorSpan); 206 } else { 207 featuresList.Add(colorSpan); 208 } 209 } else { 210 if (!hideFieldLabels) { 211 featuresList.Add(field.Value.Name + ": " + field.Value.Value.ToString()); 212 } else { 213 featuresList.Add(field.Value.Value.ToString()); 214 } 215 } 216 } 217 } 218 } 219 } 220 221 string featuresString = (string.Join(", ", featuresList.Select(x => x.ToString()).ToArray())); 222 223 <div class="g-col-12 opacity-75 fs-7">@featuresString</div> 224 } 225 } 226 227 @helper RenderField(FieldValueViewModel field, string layout) { 228 string size = Model.Item.GetRawValueString("Size", "full"); 229 string fieldValue = field?.Value != null ? field.Value.ToString() : ""; 230 bool hideFieldLabels = Model.Item.GetBoolean("HideFieldLabels"); 231 bool noValues = false; 232 233 if (!string.IsNullOrEmpty(fieldValue)) { 234 if (field.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) { 235 System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; 236 noValues = values.Count > 0 ? false : true; 237 } 238 } 239 240 if (!string.IsNullOrEmpty(fieldValue) && noValues == false) { 241 if (layout == "columns") { 242 243 <div class="grid g-col-6 g-col-lg-4 gap-1"> 244 @if(!hideFieldLabels) 245 { 246 <dt class="g-col-12 g-col-lg-4">@field.Name</dt> 247 } 248 <dd class="g-col-12 g-col-lg-8 mb-0 text-break">@RenderFieldValue(field)</dd> 249 </div> 250 } 251 if (layout == "list") { 252 if (!hideFieldLabels) 253 { 254 <dt class="g-col-4">@field.Name</dt> 255 } 256 <dd class="g-col-8 mb-0 text-break"> 257 @RenderFieldValue(field) 258 </dd> 259 } 260 if (layout == "table") { 261 <tr> 262 @if (!hideFieldLabels) 263 { 264 <th class="w-25 w-lg-50" scope="row">@field.Name</th> 265 } 266 <td class="text-break">@RenderFieldValue(field)</td> 267 </tr> 268 } 269 if (layout == "bullets") { 270 <li> 271 @if (!hideFieldLabels) 272 { 273 <strong>@field.Name</strong> 274 } 275 <span>@RenderFieldValue(field)</span> 276 </li> 277 } 278 } 279 } 280 281 @helper RenderFieldValue(FieldValueViewModel field) { 282 string fieldValue = field?.Value != null ? field.Value.ToString() : ""; 283 284 bool isLink = field?.Type == "Link"; 285 bool isColor = false; 286 bool isBrandName = field?.SystemName == "Brand_name"; 287 bool isShortDescription = field?.SystemName == "ProductTempShortDescription"; 288 289 fieldValue = fieldValue == "False" ? Translate("No") : fieldValue; 290 fieldValue = fieldValue == "True" ? Translate("Yes") : fieldValue; 291 292 293 if (field.Value.GetType() == typeof(System.Collections.Generic.List<Dynamicweb.Ecommerce.ProductCatalog.FieldOptionValueViewModel>)) 294 { 295 int valueCount = 0; 296 System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; 297 int totalValues = values.Count; 298 299 foreach (FieldOptionValueViewModel option in values) 300 { 301 if (!string.IsNullOrEmpty(option.Value)) 302 { 303 if (option.Value.Substring(0,1) == "#") { 304 isColor = true; 305 } 306 } 307 308 if (!isColor) { 309 @option.Name 310 } else { 311 <span class="colorbox-sm" style="background-color: @option.Value" title="@option.Name"></span> 312 } 313 314 if (valueCount != totalValues && valueCount < (totalValues - 1)) { 315 if (isColor) { 316 <text> </text> 317 } else { 318 <text>, </text> 319 } 320 } 321 valueCount++; 322 } 323 } 324 else 325 { 326 if (fieldValue.Substring(0,1) == "#") { 327 isColor = true; 328 } 329 330 if (!isColor) { 331 if(isLink) 332 { 333 string linktTitle = !fieldValue.Contains("aspx") ? fieldValue : Translate("Go to link"); 334 string target = Pageview.AreaSettings.GetBoolean("OpenLinksInNewTab") && fieldValue.Contains("http") ? "target=\"_blank\"" : string.Empty; 335 string rel = Pageview.AreaSettings.GetBoolean("OpenLinksInNewTab") && fieldValue.Contains("http") ? "rel=\"noopener\"" : string.Empty; 336 337 <a href="@field.Value" title="@field.Name" @target @rel>@linktTitle</a> 338 } 339 else if (isBrandName) 340 { 341 <span itemprop="brand" itemtype="https://schema.org/Brand" itemscope> 342 <span itemprop="name">@fieldValue</span> 343 </span> 344 } 345 else if(isShortDescription) 346 { 347 <strong>@fieldValue</strong> 348 } 349 else 350 { 351 @fieldValue 352 } 353 354 } else { 355 <span class="colorbox-sm" style="background-color: @fieldValue" title="@fieldValue"></span> 356 } 357 } 358 } 359
Error executing template "Designs/Swift/Paragraph/Swift_ProductSpecification_Custom.cshtml" System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Dynamicweb.Ecommerce.Products.GroupRelation.GetGroupRelationsByChildId(String childId) at Dynamicweb.Ecommerce.ProductCategoryFieldService.GetCategoriesFromGroups(List`1 categories, HashSet`1& idsHash, IEnumerable`1 groups, Int32 currentLevel, Int32 minLevel, Nullable`1 maxLevel) at Dynamicweb.Ecommerce.ProductCategoryFieldService.GetInheritedCategories(IEnumerable`1 groups, Boolean includeProductProperties) at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetFieldDisplayGroupValues(ProductViewModelSettings settings, Product product, String languageID, Lazy`1 productIds) at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass3_1.<BulkCreateView>b__60() 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_eca0a97227f845ccb15358ca9ed8373c.Execute() in E:\WEB\flowconcept.stagingsite.dk\Files\Templates\Designs\Swift\Paragraph\Swift_ProductSpecification_Custom.cshtml:line 44 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 is object && !string.IsNullOrEmpty(field.Value.Value.ToString())) 176 { 177 if (field.Value.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) { 178 List<string> options = new List<string>(); 179 foreach (FieldOptionValueViewModel option in field.Value.Value as System.Collections.Generic.List<FieldOptionValueViewModel>) { 180 if (!string.IsNullOrWhiteSpace(option.Value)) { 181 if (option.Value.ToString().Contains("#") && (Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) { 182 string colorSpan = "<span class=\"colorbox-sm\" style=\"background-color: " + option.Value + "\"></span>"; 183 options.Add(colorSpan); 184 } else if (!string.IsNullOrEmpty(option.Value)) { 185 options.Add(option.Name); 186 } 187 } 188 } 189 string optionsString = (string.Join(", ", options.Select(x => x.ToString()).ToArray())); 190 if ((Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) { 191 optionsString = (string.Join(" ", options.Select(x => x.ToString()).ToArray())); 192 } 193 194 if (!hideFieldLabels) { 195 featuresList.Add(field.Value.Name + ": " + optionsString); 196 } else { 197 featuresList.Add(optionsString); 198 } 199 } else { 200 if (!string.IsNullOrWhiteSpace(field.Value.Value.ToString())) { 201 if (field.Value.Value.ToString().Contains("#") && (Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) { 202 string colorSpan = "<span class=\"colorbox-sm\" style=\"background-color: " + field.Value.Value + "\"></span>"; 203 204 if (!hideFieldLabels) { 205 featuresList.Add(field.Value.Name + ": " + colorSpan); 206 } else { 207 featuresList.Add(colorSpan); 208 } 209 } else { 210 if (!hideFieldLabels) { 211 featuresList.Add(field.Value.Name + ": " + field.Value.Value.ToString()); 212 } else { 213 featuresList.Add(field.Value.Value.ToString()); 214 } 215 } 216 } 217 } 218 } 219 } 220 221 string featuresString = (string.Join(", ", featuresList.Select(x => x.ToString()).ToArray())); 222 223 <div class="g-col-12 opacity-75 fs-7">@featuresString</div> 224 } 225 } 226 227 @helper RenderField(FieldValueViewModel field, string layout) { 228 string size = Model.Item.GetRawValueString("Size", "full"); 229 string fieldValue = field?.Value != null ? field.Value.ToString() : ""; 230 bool hideFieldLabels = Model.Item.GetBoolean("HideFieldLabels"); 231 bool noValues = false; 232 233 if (!string.IsNullOrEmpty(fieldValue)) { 234 if (field.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) { 235 System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; 236 noValues = values.Count > 0 ? false : true; 237 } 238 } 239 240 if (!string.IsNullOrEmpty(fieldValue) && noValues == false) { 241 if (layout == "columns") { 242 243 <div class="grid g-col-6 g-col-lg-4 gap-1"> 244 @if(!hideFieldLabels) 245 { 246 <dt class="g-col-12 g-col-lg-4">@field.Name</dt> 247 } 248 <dd class="g-col-12 g-col-lg-8 mb-0 text-break">@RenderFieldValue(field)</dd> 249 </div> 250 } 251 if (layout == "list") { 252 if (!hideFieldLabels) 253 { 254 <dt class="g-col-4">@field.Name</dt> 255 } 256 <dd class="g-col-8 mb-0 text-break"> 257 @RenderFieldValue(field) 258 </dd> 259 } 260 if (layout == "table") { 261 <tr> 262 @if (!hideFieldLabels) 263 { 264 <th class="w-25 w-lg-50" scope="row">@field.Name</th> 265 } 266 <td class="text-break">@RenderFieldValue(field)</td> 267 </tr> 268 } 269 if (layout == "bullets") { 270 <li> 271 @if (!hideFieldLabels) 272 { 273 <strong>@field.Name</strong> 274 } 275 <span>@RenderFieldValue(field)</span> 276 </li> 277 } 278 } 279 } 280 281 @helper RenderFieldValue(FieldValueViewModel field) { 282 string fieldValue = field?.Value != null ? field.Value.ToString() : ""; 283 284 bool isLink = field?.Type == "Link"; 285 bool isColor = false; 286 bool isBrandName = field?.SystemName == "Brand_name"; 287 bool isShortDescription = field?.SystemName == "ProductTempShortDescription"; 288 289 fieldValue = fieldValue == "False" ? Translate("No") : fieldValue; 290 fieldValue = fieldValue == "True" ? Translate("Yes") : fieldValue; 291 292 293 if (field.Value.GetType() == typeof(System.Collections.Generic.List<Dynamicweb.Ecommerce.ProductCatalog.FieldOptionValueViewModel>)) 294 { 295 int valueCount = 0; 296 System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; 297 int totalValues = values.Count; 298 299 foreach (FieldOptionValueViewModel option in values) 300 { 301 if (!string.IsNullOrEmpty(option.Value)) 302 { 303 if (option.Value.Substring(0,1) == "#") { 304 isColor = true; 305 } 306 } 307 308 if (!isColor) { 309 @option.Name 310 } else { 311 <span class="colorbox-sm" style="background-color: @option.Value" title="@option.Name"></span> 312 } 313 314 if (valueCount != totalValues && valueCount < (totalValues - 1)) { 315 if (isColor) { 316 <text> </text> 317 } else { 318 <text>, </text> 319 } 320 } 321 valueCount++; 322 } 323 } 324 else 325 { 326 if (fieldValue.Substring(0,1) == "#") { 327 isColor = true; 328 } 329 330 if (!isColor) { 331 if(isLink) 332 { 333 string linktTitle = !fieldValue.Contains("aspx") ? fieldValue : Translate("Go to link"); 334 string target = Pageview.AreaSettings.GetBoolean("OpenLinksInNewTab") && fieldValue.Contains("http") ? "target=\"_blank\"" : string.Empty; 335 string rel = Pageview.AreaSettings.GetBoolean("OpenLinksInNewTab") && fieldValue.Contains("http") ? "rel=\"noopener\"" : string.Empty; 336 337 <a href="@field.Value" title="@field.Name" @target @rel>@linktTitle</a> 338 } 339 else if (isBrandName) 340 { 341 <span itemprop="brand" itemtype="https://schema.org/Brand" itemscope> 342 <span itemprop="name">@fieldValue</span> 343 </span> 344 } 345 else if(isShortDescription) 346 { 347 <strong>@fieldValue</strong> 348 } 349 else 350 { 351 @fieldValue 352 } 353 354 } else { 355 <span class="colorbox-sm" style="background-color: @fieldValue" title="@fieldValue"></span> 356 } 357 } 358 } 359
Produktmedier
| Navn | Download | Fil type | |
|---|---|---|---|
| Download produktark | ~300 KB |