Error executing template "Designs/Swift/Paragraph/Swift_RelatedProductsList.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Dynamicweb.Content.Items.Metadata.FieldOptionMetadataItemSource.get_Values()
at Dynamicweb.Content.Items.Editors.ListEditor`1.ViewModelOptionsFactory(List`1 converted, ItemField field, Boolean allowSorting)
at Dynamicweb.Frontend.ListViewModel.get_Options()
at Dynamicweb.Frontend.ListViewModel.get_SelectedOptions()
at Dynamicweb.Frontend.ListViewModel.get_SelectedValues()
at CompiledRazorTemplates.Dynamic.RazorEngine_33e5ceca44e74ab081882693faa1f96a.Execute() in E:\WEB\flowconcept.stagingsite.dk\Files\Templates\Designs\Swift\Paragraph\Swift_RelatedProductsList.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 @using Dynamicweb.Frontend
4
5 @{
6 ProductViewModel product = new ProductViewModel();
7
8 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
9 {
10 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
11 }
12
13 string servicePageId = Model.Item.GetLink("ServicePage") != null ? Model.Item.GetLink("ServicePage").PageId.ToString() : "";
14 servicePageId = servicePageId == "" && GetPageIdByNavigationTag("RelatedProductsListService") != 0 ? GetPageIdByNavigationTag("RelatedProductsListService").ToString() : servicePageId;
15 string pageSize = Model.Item.GetInt32("PageSize") != 0 ? Model.Item.GetString("PageSize") : "10";
16
17 IEnumerable<string> selectedDisplayGroups = Model.Item.GetRawValueString("Fields").Split(',').ToList();
18 string selectedDisplayGroupsString = selectedDisplayGroups.Count() > 0 ? (string.Join(",", selectedDisplayGroups.Select(x => x.ToString()).ToArray())) : "";
19
20 string title = !string.IsNullOrEmpty(Model.Item.GetString("Title")) ? Model.Item.GetString("Title") : "";
21 string hideTitle = Model.Item.GetBoolean("HideTitle").ToString();
22 string hideImage = Model.Item.GetBoolean("HideImage").ToString();
23 string hideProductNumber = Model.Item.GetBoolean("HideProductNumber").ToString();
24 string hideProductName = Model.Item.GetBoolean("HideProductName").ToString();
25 string hideStock = (Model.Item.GetBoolean("HideStock") || Pageview.AreaSettings.GetBoolean("ErpDownHideStock") && !Dynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplatesHelper.IsWebServiceConnectionAvailable()).ToString();
26 string quantitySelector = Model.Item.GetBoolean("QuantitySelector").ToString();
27
28 string campaignValues = string.Join(",", Model.Item.GetList("CampaignBadges").SelectedValues.ToArray());
29
30 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : "";
31 string modalTheme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("ModalTheme")) ? " theme " + Model.Item.GetRawValueString("ModalTheme").Replace(" ", "").Trim().ToLower() : "";
32 string titleFontSize = Model.Item.GetRawValueString("TitleFontSize", "display-6");
33
34 string contentPadding = Model.Item.GetRawValueString("ContentPadding", "");
35 contentPadding = contentPadding == "small" ? "p-2 p-md-3" : contentPadding;
36 contentPadding = contentPadding == "large" ? "p-4 p-md-5" : contentPadding;
37
38 //Source type
39 string sourceType = Model.Item.GetRawValueString("SourceType", "variants");
40 IList<string> relateFromProductIds = new List<string>{};
41
42 //--- RELATED PRODUCTS ---
43 if (sourceType == "related-products" && product?.RelatedGroups != null) {
44 foreach (var group in product.RelatedGroups)
45 {
46 foreach (var relatedProduct in group.Products)
47 {
48 relateFromProductIds.Add(relatedProduct.ProductId);
49 }
50 }
51 }
52
53 //Create group id collection and products id collection strings
54 string groupId = product.PrimaryOrDefaultGroup.Id;
55 string productIds = sourceType == "related-products" ? string.Join(",", relateFromProductIds) : product.Id;
56
57 bool isLazyLoadingForProductInfoEnabled = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsLazyLoadingForProductInfoEnabled"]);
58 }
59
60 @if (!Pageview.IsVisualEditorMode)
61 {
62 <div id="RelatedProductsListContainer_@Pageview.CurrentParagraph.ID" class="item_@Model.Item.SystemName.ToLower()">
63 @* Initial form for first load (We pass all the settings to the actual template) *@
64 <form action="/Default.aspx?ID=@servicePageId" id="RelatedProductsListForm_@Pageview.CurrentParagraph.ID" data-response-target-element="RelatedProductsListContainer_@Pageview.CurrentParagraph.ID">
65 <input type="hidden" name="SortOrder" value="DESC">
66 <input type="hidden" name="ID" value="@servicePageId">
67 <input type="hidden" name="SourceType" value="@sourceType">
68 <input type="hidden" name="ParagraphID" value="@Pageview.CurrentParagraph.ID">
69 <input type="hidden" name="PageSize" value="@pageSize" id="RelatedProductsListPageSize_@Pageview.CurrentParagraph.ID">
70 <input type="hidden" name="PageSizeSetting" value="@pageSize">
71 <input type="hidden" name="Title" value="@title">
72 <input type="hidden" name="HideTitle" value="@hideTitle">
73 <input type="hidden" name="SelectedDisplayGroups" value="@selectedDisplayGroupsString">
74 <input type="hidden" name="HideImage" value="@hideImage">
75 <input type="hidden" name="HideProductNumber" value="@hideProductNumber">
76 <input type="hidden" name="HideProductName" value="@hideProductName">
77 <input type="hidden" name="HideStock" value="@hideStock">
78 <input type="hidden" name="QuantitySelector" value="@quantitySelector">
79 <input type="hidden" name="Theme" value="@theme">
80 <input type="hidden" name="ModalTheme" value="@modalTheme">
81 <input type="hidden" name="TitleFontSize" value="@titleFontSize">
82 <input type="hidden" name="ContentPadding" value="@contentPadding">
83 @if (isLazyLoadingForProductInfoEnabled)
84 {
85 <input type="hidden" name="getproductinfo" value="true">
86 }
87
88 @*--- VARIANTS ---*@
89 @if (sourceType == "variants")
90 {
91 <input type="hidden" name="MainProductID" value="@productIds">
92 }
93
94 @*--- MOST SOLD ---*@
95 @if (sourceType == "most-sold")
96 {
97 <input type="hidden" name="SortBy" value="OrderCount">
98 <input type="hidden" name="GroupId" value="@groupId">
99 }
100
101 @*--- TRENDING ---*@
102 @if (sourceType == "trending")
103 {
104 <input type="hidden" name="SortBy" value="OrderCountGrowth">
105 <input type="hidden" name="GroupId" value="@groupId">
106 }
107
108 @*--- LATEST ---*@
109 @if (sourceType == "latest")
110 {
111 <input type="hidden" name="SortBy" value="Created">
112 <input type="hidden" name="GroupId" value="@groupId">
113 }
114
115 @*--- FREQUENTLY BOUGHT ---*@
116 @if (sourceType == "frequently")
117 {
118 <input type="hidden" name="BoughtWithProductIds" value="[@productIds]">
119 }
120
121 @*--- RELATED PRODUCTS ---*@
122 @if (sourceType == "related-products")
123 {
124 <input type="hidden" name="MainProductID" value="@productIds">
125 }
126
127 @if (sourceType != "variants")
128 {
129 <input type="hidden" name="isVariant" value="false">
130 }
131 else
132 {
133 <input type="hidden" name="isVariant" value="true">
134 }
135
136 <input type="hidden" name="SaleBadgeType" value="@Model.Item.GetRawValue("SaleBadgeType")">
137 <input type="hidden" name="SaleBadgeCssClassName" value="@Model.Item.GetRawValue("SaleBadgeDesign")">
138 <input type="hidden" name="NewBadgeCssClassName" value="@Model.Item.GetRawValue("NewBadgeDesign")">
139 <input type="hidden" name="NewPublicationDays" value="@Model.Item.GetInt32("NewPublicationDays")">
140
141 @if (campaignValues != "")
142 {
143 <input type="hidden" name="CampaignBadgesValues" value="@campaignValues">
144 }
145 </form>
146 </div>
147
148 <script type="module">
149 swift.PageUpdater.Update(document.querySelector("#RelatedProductsListForm_@Pageview.CurrentParagraph.ID"));
150 </script>
151
152 <script>
153 var UpdateRelatedProductsList = function(event, type, id) {
154 var targetElement = "RelatedProductsListContainer_" + id;
155
156 if (type == "UpdateFacets") {
157 targetElement = "RelatedProductsListFacets_" + id;
158 }
159
160 document.querySelector('#RelatedProductsListRequestType_' + id).value = type;
161 document.querySelector('#RelatedProductsListForm_' + id).setAttribute("data-response-target-element", targetElement);
162
163 swift.PageUpdater.Update(document.querySelector("#RelatedProductsListForm_" + id));
164 };
165 </script>
166 } else {
167 <div class="alert alert-info" role="alert">
168 <span>@Translate("Related products list")</span>
169 </div>
170 }
171