Error executing template "Designs/Swift/eCom/ProductCatalog/ProductSearchDropdownResponse.cshtml" System.ArgumentNullException: Value cannot be null. Parameter name: source at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source) at CompiledRazorTemplates.Dynamic.RazorEngine_99d3c411b3d34703aca466aa5fb96490.Execute() in F:\Domains\Sites\dev-krvc.mydwsitec.com\Files\Templates\Designs\Swift\eCom\ProductCatalog\ProductSearchDropdownResponse.cshtml:line 94 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<ProductListViewModel> 2 @using Dynamicweb.Rendering 3 @using Dynamicweb.Ecommerce.ProductCatalog 4 5 @{ 6 string searchTerm = string.Empty; 7 string layout = Dynamicweb.Context.Current.Request["SearchLayout"] != null ? Dynamicweb.Context.Current.Request["SearchLayout"].ToString() : "field"; 8 string itemPadding = layout == "icon" ? "px-1" : "px-1"; 9 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/"; 10 11 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request["eq"])) 12 { 13 searchTerm = Dynamicweb.Context.Current.Request["eq"].Trim(); 14 } 15 Dictionary<string, string> suggestions = new Dictionary<string, string>(); 16 17 string resultsPage = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl("Default.aspx?ID=" + GetPageIdByNavigationTag("Shop")); 18 } 19 20 @functions{ 21 string Highlight(string input, string textToHighlight) 22 { 23 if (string.IsNullOrEmpty(textToHighlight)) 24 { 25 return input; 26 } 27 input = input.ToLower(); 28 input = input.Replace(textToHighlight, "</mark>" + textToHighlight + "<mark>"); 29 30 return "<span class=\"js-suggestion flex-fill text-break\" data-suggestion-value=\"\"><mark>" + input + "</mark></span>"; 31 } 32 33 string ProductNameHighlight(string input, string textToHighlight) 34 { 35 if (string.IsNullOrEmpty(textToHighlight)) 36 { 37 return input; 38 } 39 input = input.ToLower(); 40 input = input.Replace(textToHighlight, "</mark>" + textToHighlight + "<mark>"); 41 42 return "<span class=\"js-suggestion flex-fill text-break\" data-suggestion-value=\"\">" + input + "</span>"; 43 } 44 45 string escape(string input) 46 { 47 return Dynamicweb.Core.Encoders.HtmlEncoder.JavaScriptStringEncode(input); 48 } 49 50 void AddSuggestion(string suggestion, string group, Dictionary<string, string> suggestions) 51 { 52 suggestion = suggestion.ToLower(); 53 if (!suggestions.ContainsKey(suggestion)) 54 { 55 suggestions.Add(suggestion, group); 56 } 57 } 58 } 59 60 @if (Model.SpellCheckerSuggestions != null && Model.SpellCheckerSuggestions.Any()) 61 { 62 List<string> validSuggestions = new List<string>(); 63 foreach (string suggestion in Model.SpellCheckerSuggestions) 64 { 65 if (!validSuggestions.Contains(suggestion)) 66 { 67 validSuggestions.Add(suggestion); 68 } 69 } 70 if (validSuggestions.Count == 0) 71 { 72 foreach (string suggestion in Model.SpellCheckerSuggestions) 73 { 74 if (!validSuggestions.Contains(suggestion)) 75 { 76 validSuggestions.Add(suggestion); 77 } 78 } 79 } 80 if (validSuggestions.Count > 0) 81 { 82 foreach (string suggestion in validSuggestions.Take(5)) 83 { 84 AddSuggestion(suggestion, "Did you mean", suggestions); 85 <li class="dropdown-item d-flex flex-row align-items-center py-2 px-0 text-wrap text-decoration-underline-hover"> 86 <span class="dropdown-item-search-icon d-flex align-items-center justify-content-center" aria-hidden="true" onclick="swift.Typeahead.selectSuggestion(this.parentElement);"></span> 87 <span class="flex-fill" onclick="swift.Typeahead.selectSuggestion(this.parentElement);">@Highlight(suggestion, searchTerm)</span> 88 <span class="dropdown-item-arrow-icon d-flex d-lg-none align-items-center justify-content-center" aria-hidden="true" onclick="swift.Typeahead.setSuggestion(this.parentElement);"></span> 89 </li> 90 } 91 } 92 } 93 94 @if (Model.FacetGroups.Any()) 95 { 96 var maxSuggestions = 5; 97 foreach (var facetGroup in Model.FacetGroups) 98 { 99 foreach (var facetItem in facetGroup.Facets) 100 { 101 var facetOptionCount = facetItem.OptionCount; 102 var optionActiveCount = facetItem.OptionActiveCount; 103 var facetOptionResultTotalCount = facetItem.OptionResultTotalCount; 104 var queryParameter = facetItem.QueryParameter; 105 var template = facetItem.RenderType; 106 107 var maxValue = facetItem.MaximumFacetValue; 108 var minValue = facetItem.MinimumFacetValue; 109 110 List<FacetOptionViewModel> validOptions = new List<FacetOptionViewModel>(); 111 112 foreach (var facetOption in facetItem.Options.OrderByDescending(option => option.Count)) 113 { 114 if (searchTerm != null && validOptions.Count < maxSuggestions) 115 { 116 validOptions.Add(facetOption); 117 } 118 } 119 120 if (validOptions.Count > 0) 121 { 122 <li class="text-wrap"> 123 <h6 class="dropdown-header ps-5 pe-3 py-3">@facetItem.Name</h6> 124 </li> 125 foreach (var facetOption in validOptions) 126 { 127 AddSuggestion(facetOption.Label, facetItem.Name, suggestions); 128 <li class="dropdown-item @itemPadding" onclick="swift.Typeahead.selectSuggestion(this);" data-param="@queryParameter" data-paramvalue="@facetOption.Value"> 129 @Highlight(facetOption.Label, searchTerm) 130 <div class="">@facetOption.Count</div> 131 </li> 132 } 133 } 134 135 } 136 } 137 } 138 139 @if (Model.Products.Count() > 0) 140 { 141 var validSuggestions = new List<ProductViewModel>(); 142 string label = Translate("Products"); 143 if (Model.Group != null) 144 { 145 label = Model.Group.Name; 146 } 147 148 foreach (var product in Model.Products) 149 { 150 if (searchTerm != null && product.Name.IndexOf(searchTerm, StringComparison.InvariantCultureIgnoreCase) >= 0 || true) 151 { 152 AddSuggestion(product.Name, label, suggestions); 153 validSuggestions.Add(product); 154 } 155 } 156 if (validSuggestions.Count > 0) 157 { 158 foreach (var suggestion in validSuggestions) 159 { 160 var defaultGroupId = suggestion.PrimaryOrDefaultGroup.Id; 161 var selectedDetailsPage = $"Default.aspx?ID={GetPageIdByNavigationTag("Shop").ToString()}"; 162 string variantParameter = null; 163 if (!string.IsNullOrEmpty(suggestion.VariantId)) { 164 variantParameter = $"&VariantID={suggestion.VariantId}"; 165 } 166 string productDetailLink = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl($"{selectedDetailsPage}&GroupID={defaultGroupId}&ProductID={suggestion.Id}{variantParameter}"); 167 168 <li class="dropdown-item d-flex flex-lg-row-reverse align-items-center text-wrap px-0 py-2 text-wrap text-decoration-underline-hover" onclick="swift.Typeahead.selectSuggestion(this);" data-param="ProductId" data-selected-details-page="@productDetailLink" data-paramvalue="@suggestion.Id"> 169 <span aria-hidden="true" class="d-lg-none dropdown-item-search-icon d-flex align-items-center justify-content-center"></span> 170 @ProductNameHighlight(suggestion.Name + " - " + suggestion.Number, searchTerm) 171 <img class="mx-2" src="/admin/public/getimage.ashx?image=@Dynamicweb.Context.Current.Server.UrlEncode(suggestion.DefaultImage.Value)&width=32&height=32&format=webp&Crop=5&fillcanvas=true" height="32" width="32" alt="@suggestion.Name"> 172 </li> 173 } 174 } 175 } 176 177 @if (!string.IsNullOrEmpty(searchTerm)) 178 { 179 if (Model.TotalProductsCount > 0) 180 { 181 <li class="dropdown-item text-center p-2 text-wrap" id="ViewAllProductResults" onclick="swift.Typeahead.selectSuggestion(this);" data-all-results-page="@resultsPage"> 182 <span class="text-break text-decoration-underline">@Translate("View all") @Model.TotalProductsCount @Translate("products for")<mark> "<span class="js-suggestion">@searchTerm</span>"</mark></span> 183 </li> 184 } 185 else 186 { 187 <li class="dropdown-item text-center text-wrap @itemPadding" id="NoProductResults"> 188 @Translate("We have no product results for")<mark> "<span class="js-suggestion">@searchTerm</span>"</mark> 189 </li> 190 } 191 } 192