Error executing template "Designs/Swift/_parsed/Swift_MiniCart_Custom.parsed.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_a96d516538044491b2ec00ca8834999f.Execute() in D:\dynamicweb.net\Solutions\Co3\flowconcept.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\_parsed\Swift_MiniCart_Custom.parsed.cshtml:line 14
   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 @using System 2 @using System.Linq 3 @using Dynamicweb.Ecommerce.Common 4 @using Dynamicweb.Security.UserManagement 5 @using Dynamicweb.Security.UserManagement.Common.CustomFields 6 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel> 7 8 @{ 9 bool renderOrderlineCountInsteadOfProductCount = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("RenderOrderlineCountInsteadOfProductCount")) ? Convert.ToBoolean(Dynamicweb.Context.Current.Request.Form.Get("RenderOrderlineCountInsteadOfProductCount")) : false; 10 11 User currentUser = User.GetCurrentUser(); 12 double count = 0; 13 14 CustomFieldValue freeFreightCustomField = currentUser.CustomFieldValues.FirstOrDefault(cfv => cfv.CustomField.SystemName == "AccessUser_CustomFreeShippingText"); 15 double freeFreightCustomFieldValue = 0; 16 17 18 19 if (!renderOrderlineCountInsteadOfProductCount) 20 { 21 count = Model.Cart.TotalProductsCount; 22 } 23 else 24 { 25 count = Model.Cart.OrderlinesCount; 26 } 27 28 dynamic JSON = new 29 { 30 count = count 31 }; 32 33 if (freeFreightCustomField != null && double.TryParse(freeFreightCustomField.Value?.ToString(), out freeFreightCustomFieldValue)) 34 { 35 36 37 double amountUntilFreeFreight = freeFreightCustomFieldValue - Model.Cart.TotalPrice.PriceWithoutVat.Value; 38 39 40 JSON = new 41 { 42 count = count, 43 amountUntilFreeFreight = amountUntilFreeFreight, 44 format = new { 45 currency = Context.Country.CurrencyCode, 46 culture = Context.Country.CultureInfo 47 } 48 }; 49 } 50 } 51 @Newtonsoft.Json.JsonConvert.SerializeObject(JSON) 52 53