GF14-212130-850N

14-32675-14-0850
Gassfjær C200/E468 M10 gjenger
Error executing template "Designs/Swift/Paragraph/Swift_ProductSpecification.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_14cd82e7c8cb4fadb8060b0541397e24.Execute() in E:\Solutions\JSKomponenter2024\Files\Templates\Designs\Swift\Paragraph\Swift_ProductSpecification.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 = null; 6 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 7 { 8 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 9 } 10 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 11 { 12 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 13 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 14 15 if (productList?.Products is object) 16 { 17 product = productList.Products[0]; 18 } 19 } 20 } 21 22 @if (product is object) 23 { 24 IEnumerable<string> selectedDisplayGroupIds = Model.Item.GetRawValueString("DisplayGroups").Split(',').ToList(); 25 List<CategoryFieldViewModel> displayGroups = new List<CategoryFieldViewModel>(); 26 27 foreach (var selection in selectedDisplayGroupIds) 28 { 29 foreach (CategoryFieldViewModel group in product.FieldDisplayGroups.Values) 30 { 31 if (selection == group.Id) 32 { 33 int fieldsWithNoValueOrZero = 0; 34 35 foreach (var field in group.Fields) 36 { 37 if (string.IsNullOrEmpty(field.Value.Value.ToString())) 38 { 39 fieldsWithNoValueOrZero++; 40 } 41 } 42 43 if (fieldsWithNoValueOrZero != group.Fields.Count) 44 { 45 displayGroups.Add(group); 46 } 47 } 48 } 49 } 50 51 bool showProductFields = Model.Item.GetBoolean("ProductFields"); 52 53 bool hideTitle = Model.Item.GetBoolean("HideTitle"); 54 55 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 56 57 string titleFontSize = Model.Item.GetRawValueString("TitleFontSize", "display-4"); 58 59 string contentPadding = Model.Item.GetRawValueString("ContentPadding", ""); 60 contentPadding = contentPadding == "none" ? string.Empty : contentPadding; 61 contentPadding = contentPadding == "small" ? " p-2 p-md-3" : contentPadding; 62 contentPadding = contentPadding == "large" ? " p-4 p-md-5" : contentPadding; 63 64 string layout = Model.Item.GetRawValueString("Layout", "list"); 65 string size = Model.Item.GetRawValueString("Size", "full"); 66 string gaps = size == "full" ? " gap-4" : " gap-2"; 67 68 69 if (Pageview.IsVisualEditorMode && displayGroups.Count() == 0) 70 { 71 product.ProductFields.Clear(); 72 product.ProductFields.Add(Translate("Width"), new FieldValueViewModel { Name = Translate("Width"), Value = "99cm" }); 73 product.ProductFields.Add(Translate("Height"), new FieldValueViewModel { Name = Translate("Height"), Value = "195cm" }); 74 showProductFields = true; 75 } 76 77 if (layout == "commas") 78 { 79 gaps = size == "full" ? " gap-4" : " gap-2"; 80 81 } 82 83 <div class="h-100@(theme)@(contentPadding) item_@Model.Item.SystemName.ToLower()"> 84 <div class="grid@(gaps)"> 85 @if ((product.ProductFields != null && Model.Item.GetBoolean("ProductFields")) || (product.ProductCategories != null && Model.Item.GetBoolean("CategoryFields")) || (displayGroups.Count != 0)) 86 { 87 if (!hideTitle) 88 { 89 <h2 class="g-col-12 @titleFontSize">@Model.Item.GetString("Title")</h2> 90 } 91 } 92 93 @if (displayGroups.Count != 0) 94 { 95 if (layout != "accordion") 96 { 97 foreach (var group in displayGroups) 98 { 99 bool hideHeader = Model.Item.GetBoolean("HideGroupHeaders"); 100 101 if (!hideHeader) 102 { 103 <h4 class="g-col-12 h4 mb-0">@group.Name</h4> 104 } 105 106 { @RenderFieldsFromList(group.Fields, layout) } 107 108 } 109 } 110 else 111 { 112 <div class="g-col-12"> 113 <div class="accordion accordion-flush w-100" id="Specifications_@Model.ID"> 114 @foreach (var group in displayGroups) 115 { 116 <div class="accordion-item"> 117 <h2 class="accordion-header" id="SpecificationHeading_@group.Id"> 118 <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#SpecificationItem_@group.Id" aria-expanded="false" aria-controls="SpecificationItem_@group.Id"> 119 @group.Name 120 </button> 121 </h2> 122 <div id="SpecificationItem_@group.Id" class="accordion-collapse collapse" aria-labelledby="SpecificationHeading_@group.Id" data-bs-parent="#Specifications_@Model.ID"> 123 <div class="accordion-body"> 124 @{ @RenderFieldsFromList(group.Fields, "list") } 125 </div> 126 </div> 127 </div> 128 } 129 </div> 130 </div> 131 } 132 } 133 134 @if (product.ProductFields != null && showProductFields) 135 { 136 if (product.ProductFields.Count > 0) 137 { 138 if (layout != "accordion") 139 { 140 {@RenderFieldsFromList(product.ProductFields, layout) } 141 } 142 else 143 { 144 <div class="g-col-12"> 145 <div class="accordion accordion-flush w-100" id="Specifications_@Model.ID"> 146 <div class="accordion-item"> 147 <h2 class="accordion-header" id="SpecificationHeading_@Model.ID"> 148 <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#SpecificationItem_@Model.ID" aria-expanded="false" aria-controls="SpecificationItem_@Model.ID"> 149 @Translate("Specifications") 150 </button> 151 </h2> 152 <div id="SpecificationItem_@Model.ID" class="accordion-collapse" aria-labelledby="SpecificationHeading_@Model.ID" data-bs-parent="#Specifications_@Model.ID"> 153 <div class="accordion-body"> 154 @{ @RenderFieldsFromList(product.ProductFields, "List") } 155 </div> 156 </div> 157 </div> 158 </div> 159 </div> 160 } 161 } 162 } 163 164 @if (product.ProductCategories != null && Model.Item.GetBoolean("CategoryFields")) 165 { 166 if (product.ProductCategories.Count > 0) 167 { 168 if (layout != "accordion") 169 { 170 foreach (var group in product.ProductCategories) 171 { 172 CategoryFieldViewModel category = group.Value; 173 bool hideHeader = Model.Item.GetBoolean("HideGroupHeaders"); 174 175 if (!hideHeader) 176 { 177 <h4 class="g-col-12 h4 mb-0">@group.Value.Name</h4> 178 } 179 180 { @RenderFieldsFromList(category.Fields, layout) } 181 } 182 } 183 else 184 { 185 <div class="g-col-12"> 186 <div class="accordion accordion-flush w-100" id="Specifications_@Model.ID"> 187 @foreach (var group in product.ProductCategories) 188 { 189 CategoryFieldViewModel category = group.Value; 190 191 <div class="accordion-item"> 192 <h2 class="accordion-header" id="SpecificationHeading_@group.Value.Id"> 193 <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#SpecificationItem_@group.Value.Id" aria-expanded="false" aria-controls="SpecificationItem_@group.Value.Id"> 194 @group.Value.Name 195 </button> 196 </h2> 197 <div id="SpecificationItem_@group.Value.Id" class="accordion-collapse" aria-labelledby="SpecificationHeading_@group.Value.Id" data-bs-parent="#Specifications_@Model.ID"> 198 <div class="accordion-body"> 199 @{ @RenderFieldsFromList(category.Fields, "list") } 200 </div> 201 </div> 202 </div> 203 } 204 </div> 205 </div> 206 } 207 } 208 } 209 </div> 210 </div> 211 } 212 else if (Pageview.IsVisualEditorMode) 213 { 214 <div class="alert alert-warning m-0">@Translate("No products available")</div> 215 } 216 217 @helper RenderFieldsFromList(Dictionary<string, FieldValueViewModel> fields, string layout) 218 { 219 string size = Model.Item.GetRawValueString("Size", "full"); 220 string gaps = size != "full" ? " gap-1" : string.Empty; 221 bool hideFieldLabels = Model.Item.GetBoolean("HideFieldLabels"); 222 bool hideFieldsWithZeroValue = Model.Item.GetBoolean("HideFieldsWithZeroValue"); 223 224 if (layout == "columns") 225 { 226 <div class="g-col-12"> 227 <div class="grid@(gaps)"> 228 @foreach (var field in fields) 229 { 230 {@RenderField(field.Value, layout)} 231 } 232 </div> 233 </div> 234 } 235 if (layout == "list") 236 { 237 <div class="g-col-12"> 238 <dl class="grid@(gaps)"> 239 @foreach (var field in fields) 240 { 241 {@RenderField(field.Value, layout)} 242 } 243 </dl> 244 </div> 245 } 246 if (layout == "table") 247 { 248 string tableSize = size == "full" ? "" : " table-sm"; 249 <div class="g-col-12 table-responsive"> 250 <table class="table @(tableSize)"> 251 @foreach (var field in fields) 252 { 253 {@RenderField(field.Value, layout)} 254 } 255 </table> 256 </div> 257 } 258 if (layout == "bullets") 259 { 260 string listSize = size == "full" ? "" : "m-0 p-0 lh-1 fs-7 opacity-75"; 261 string listStyle = size == "full" ? "" : "style=\"list-style-position: inside\""; 262 <div class="g-col-12"> 263 <ul class="@listSize" @listStyle> 264 @foreach (var field in fields) 265 { 266 {@RenderField(field.Value, layout)} 267 } 268 </ul> 269 </div> 270 } 271 if (layout == "commas") 272 { 273 List<string> featuresList = new List<string>(); 274 275 foreach (var field in fields) 276 { 277 string firstListItemValue = string.Empty; //Hack to support field type providers with a single value 278 279 if (field.Value?.Value != null) 280 { 281 if (field.Value.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) 282 { 283 System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; 284 285 //Hack to support field type providers with a single value 286 if (values.FirstOrDefault() != null) 287 { 288 firstListItemValue = values.FirstOrDefault().Value; 289 } 290 } 291 } 292 293 if (!hideFieldsWithZeroValue || (firstListItemValue != "0" && firstListItemValue != "0.0" && field.Value.Value.ToString() != "0" && field.Value.Value.ToString() != "0.0")) 294 { 295 if (field.Value.Value is object && !string.IsNullOrEmpty(field.Value.Value.ToString())) 296 { 297 if (field.Value.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) 298 { 299 List<string> options = new List<string>(); 300 foreach (FieldOptionValueViewModel option in field.Value.Value as System.Collections.Generic.List<FieldOptionValueViewModel>) 301 { 302 if (!string.IsNullOrWhiteSpace(option.Value)) 303 { 304 if ((option.Value.ToString().Contains("#") || option.Value.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) && (Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) 305 { 306 string colorSpan = "<span class=\"colorbox-sm\" style=\"background-color: " + option.Value + "\"></span>"; 307 if (option.Value.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 308 { 309 colorSpan = $"<img src=\"/Admin/Public/GetImage.ashx?width=16&height=16&image={option.Value}\">"; 310 } 311 options.Add(colorSpan); 312 } 313 else if (!string.IsNullOrEmpty(option.Value)) 314 { 315 options.Add(option.Name); 316 } 317 } 318 } 319 string optionsString = (string.Join(", ", options.Select(x => x.ToString()).ToArray())); 320 if ((Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) 321 { 322 optionsString = (string.Join(" ", options.Select(x => x.ToString()).ToArray())); 323 } 324 325 if (!string.IsNullOrEmpty(optionsString)) 326 { 327 if (!hideFieldLabels) 328 { 329 featuresList.Add(field.Value.Name + ": " + optionsString); 330 } 331 else 332 { 333 featuresList.Add(optionsString); 334 } 335 } 336 } 337 else 338 { 339 if (!string.IsNullOrWhiteSpace(field.Value.Value.ToString())) 340 { 341 if ((field.Value.Value.ToString().Contains("#") || field.Value.Value.ToString().StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) && (Translate(field.Value.Name) == Translate("Color") || Translate(field.Value.Name) == Translate("Colour"))) 342 { 343 string colorSpan = "<span class=\"colorbox-sm\" style=\"background-color: " + field.Value.Value + "\"></span>"; 344 if(field.Value.Value.ToString().StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 345 { 346 colorSpan = $"<img src=\"/Admin/Public/GetImage.ashx?width=16&height=16&image={field.Value.Value}\">"; 347 } 348 349 if (!hideFieldLabels) 350 { 351 featuresList.Add(field.Value.Name + ": " + colorSpan); 352 } 353 else 354 { 355 featuresList.Add(colorSpan); 356 } 357 } 358 else 359 { 360 if (!hideFieldLabels) 361 { 362 featuresList.Add(field.Value.Name + ": " + field.Value.Value.ToString()); 363 } 364 else 365 { 366 featuresList.Add(field.Value.Value.ToString()); 367 } 368 } 369 } 370 } 371 } 372 } 373 } 374 375 string featuresString = (string.Join(", ", featuresList.Select(x => x.ToString()).ToArray())); 376 377 <div class="g-col-12 opacity-75 fs-7">@featuresString</div> 378 } 379 } 380 381 @helper RenderField(FieldValueViewModel field, string layout) 382 { 383 string size = Model.Item.GetRawValueString("Size", "full"); 384 string fieldValue = field?.Value != null ? field.Value.ToString() : ""; 385 bool hideFieldLabels = Model.Item.GetBoolean("HideFieldLabels"); 386 bool noValues = false; 387 string firstListItemValue = string.Empty; //Hack to support field type providers with a single value 388 bool hideFieldsWithZeroValue = Model.Item.GetBoolean("HideFieldsWithZeroValue"); 389 390 if (!string.IsNullOrEmpty(fieldValue)) 391 { 392 if (field.Value.GetType() == typeof(System.Collections.Generic.List<FieldOptionValueViewModel>)) 393 { 394 System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; 395 noValues = values.Count > 0 ? false : true; 396 397 //Hack to support field type providers with a single value 398 if (values.FirstOrDefault() != null) 399 { 400 firstListItemValue = values.FirstOrDefault().Value; 401 } 402 } 403 } 404 405 if (!string.IsNullOrEmpty(fieldValue) && noValues == false) 406 { 407 if (!hideFieldsWithZeroValue || (firstListItemValue != "0" && firstListItemValue != "0.0" && field.Value.ToString() != "0" && field.Value.ToString() != "0.0")) 408 { 409 if (layout == "columns") 410 { 411 <div class="grid g-col-6 g-col-lg-4 gap-1"> 412 @if (!hideFieldLabels) 413 { 414 <dt class="g-col-12 g-col-lg-4">@field.Name</dt> 415 } 416 <dd class="g-col-12 g-col-lg-8 mb-0 text-break"> 417 @{ @RenderFieldValue(field) } 418 </dd> 419 </div> 420 } 421 if (layout == "list") 422 { 423 if (!hideFieldLabels) 424 { 425 <dt class="g-col-4">@field.Name</dt> 426 } 427 <dd class="g-col-8 mb-0 text-break"> 428 @{ @RenderFieldValue(field) } 429 </dd> 430 } 431 if (layout == "table") 432 { 433 <tr> 434 @if (!hideFieldLabels) 435 { 436 <td style="width: 35%;" scope="row">@field.Name</td> 437 } 438 <td class="text-break"> 439 @{ @RenderFieldValue(field) } 440 </td> 441 </tr> 442 } 443 if (layout == "bullets") 444 { 445 <li> 446 @if (!hideFieldLabels) 447 { 448 <strong>@field.Name</strong> 449 } 450 <span> 451 @{ @RenderFieldValue(field) } 452 </span> 453 </li> 454 } 455 } 456 } 457 } 458 459 @helper RenderFieldValue(FieldValueViewModel field) 460 { 461 string fieldValue = field?.Value != null ? field.Value.ToString() : ""; 462 463 bool isLink = field?.Type == "Link"; 464 bool isColor = false; 465 bool isBrandName = field?.SystemName == "Brand_name"; 466 467 fieldValue = fieldValue == "False" ? Translate("No") : fieldValue; 468 fieldValue = fieldValue == "True" ? Translate("Yes") : fieldValue; 469 470 471 if (field.Value.GetType() == typeof(System.Collections.Generic.List<Dynamicweb.Ecommerce.ProductCatalog.FieldOptionValueViewModel>)) 472 { 473 int valueCount = 0; 474 System.Collections.Generic.List<FieldOptionValueViewModel> values = field.Value as System.Collections.Generic.List<FieldOptionValueViewModel>; 475 int totalValues = values.Count; 476 477 foreach (FieldOptionValueViewModel option in values) 478 { 479 if (!string.IsNullOrEmpty(option.Value)) 480 { 481 if (option.Value.StartsWith("#", StringComparison.OrdinalIgnoreCase) || option.Value.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 482 { 483 isColor = true; 484 } 485 } 486 487 if (!isColor) 488 { 489 @option.Name 490 } 491 else 492 { 493 if (option.Value.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 494 { 495 <img src="/Admin/Public/GetImage.ashx?width=16&height=16&image=@option.Value" title="@option.Name"> 496 } 497 else 498 { 499 <span class="colorbox-sm" style="background-color: @option.Value" title="@option.Name"></span> 500 } 501 } 502 503 if (valueCount != totalValues && valueCount < (totalValues - 1)) 504 { 505 if (isColor) 506 { 507 <text> </text> 508 } 509 else 510 { 511 <text>, </text> 512 } 513 } 514 valueCount++; 515 } 516 } 517 else 518 { 519 if (!string.IsNullOrEmpty(fieldValue)) 520 { 521 if (fieldValue.StartsWith("#", StringComparison.OrdinalIgnoreCase) || fieldValue.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 522 { 523 isColor = true; 524 } 525 } 526 527 if (!isColor) 528 { 529 if (isLink) 530 { 531 string linktTitle = !fieldValue.Contains("aspx") ? fieldValue : Translate("Go to link"); 532 string target = Pageview.AreaSettings.GetBoolean("OpenLinksInNewTab") && fieldValue.Contains("http") ? "target=\"_blank\"" : string.Empty; 533 string rel = Pageview.AreaSettings.GetBoolean("OpenLinksInNewTab") && fieldValue.Contains("http") ? "rel=\"noopener\"" : string.Empty; 534 535 <a href="@field.Value" title="@field.Name" @target @rel>@linktTitle</a> 536 } 537 else if (isBrandName) 538 { 539 <span itemprop="brand" itemtype="https://schema.org/Brand" itemscope> 540 <span itemprop="name">@fieldValue</span> 541 </span> 542 } 543 else 544 { 545 @fieldValue 546 } 547 548 } 549 else 550 { 551 if (fieldValue.StartsWith("/Files/", StringComparison.OrdinalIgnoreCase)) 552 { 553 <img src="/Admin/Public/GetImage.ashx?width=16&height=16&image=@fieldValue"> 554 } 555 else 556 { 557 <span class="colorbox-sm" style="background-color: @fieldValue"></span> 558 } 559 } 560 } 561 } 562