Component builder for: Detail Page - Top Detail - Mobile

Lagerbestand:

Error executing template "Designs/Swift/Paragraph/IDN_PlannedReorderDate.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_863fda3700614cfa870a133d10e8f11c.Execute() in D:\dynamicweb.net\Solutions\Kumavision\iden.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\Paragraph\IDN_PlannedReorderDate.cshtml:line 49
   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 Newtonsoft.Json 4 @using Newtonsoft.Json.Linq 5 @using Dynamicweb.Solutions.Iden.Domain.Products 6 @using Dynamicweb.Solutions.Iden.Infrastructure.Extensions 7 8 9 @functions 10 { 11 public string GetCurrentStockLocationStockAmount(string payload , string currentStockLocationName) 12 { 13 if (string.IsNullOrEmpty(payload) || string.IsNullOrEmpty(currentStockLocationName)) return "0"; 14 15 try 16 { 17 var stockLocationsArr = JArray.Parse(payload); 18 JObject[] currentStockLocationObject = stockLocationsArr.Where(o => (string)o["location"] == currentStockLocationName).Select(o=> (JObject)o).ToArray(); 19 return currentStockLocationObject[0]["value"].ToString(); 20 } 21 catch (Exception e) 22 { 23 return "none"; 24 } 25 26 } 27 } 28 29 @{ 30 ProductViewModel product = null; 31 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 32 { 33 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 34 } 35 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 36 { 37 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 38 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 39 40 if (productList?.Products is object) 41 { 42 product = productList.Products[0]; 43 } 44 } 45 46 ProductLiveInfo productLiveInfo = null; 47 48 FieldValueViewModel preorderable; 49 product.ProductFields.TryGetValue("Preordable", out preorderable); 50 51 FieldValueViewModel nextAvailableDateProductField; 52 product.ProductFields.TryGetValue("NextAvailableDate", out nextAvailableDateProductField); 53 DateTime nextAvailableDate = nextAvailableDateProductField?.Value != null ? DateTime.Parse(nextAvailableDateProductField.Value.ToString()) : new DateTime(2000, 12, 12); 54 55 FieldValueViewModel productStockLocations; 56 product.ProductFields.TryGetValue("KVS_StockLocations", out productStockLocations); 57 58 productLiveInfo = ProductExtensions.GetLiveInfo(product, Pageview); 59 string stockLocations = productLiveInfo != null ? productLiveInfo.KVS_StockLocations : string.Empty; 60 61 @*<div class="d-none-"> 62 @JsonConvert.SerializeObject(productLiveInfo, Newtonsoft.Json.Formatting.Indented); 63 </div>*@ 64 65 var locations = Dynamicweb.Ecommerce.Services.StockService.GetStockLocations(); 66 @* For invited users , set the currentUser equal to parent user *@ 67 var user = Dynamicweb.Security.UserManagement.User.GetCurrentExtranetUser(); 68 var parentUserId = !string.IsNullOrEmpty(user?.CustomFieldValues.FirstOrDefault(cfv => cfv.CustomField.SystemName.Equals("AccessUser_ParentUserId"))?.Value.ToString()) ? 69 Dynamicweb.Core.Converter.ToInt32(user.CustomFieldValues.FirstOrDefault(cfv => cfv.CustomField.SystemName.Equals("AccessUser_ParentUserId")).Value) : 0; 70 bool isInvitedUser = parentUserId > 0; 71 var currentUser = isInvitedUser ? Dynamicweb.Security.UserManagement.User.GetUserByID(parentUserId) : Dynamicweb.Security.UserManagement.User.GetCurrentExtranetUser(); 72 73 var currentStockLocationName = locations.FirstOrDefault(location => location.ID == currentUser.StockLocationID)?.Name ?? string.Empty; 74 string currentStockAmount = GetCurrentStockLocationStockAmount(productStockLocations?.Value?.ToString() , currentStockLocationName); 75 string title = Model.Item?.GetString("Title"); 76 string titleFontSize = Model.Item?.GetRawValueString("TitleSize", "h6"); 77 string titleColor = Model.Item?.GetString("TitleColor", "text-inherit"); 78 string maxWidth = Model.Item?.GetRawValueString("TextReadability", "max-width-on"); 79 maxWidth = maxWidth == "max-width-on" ? " mw-75ch" : maxWidth; 80 maxWidth = maxWidth == "max-width-off" ? string.Empty : maxWidth; 81 bool hideTitle = Model.Item?.GetBoolean("HideTitle") ?? false; 82 83 string contentPadding = Model.Item?.GetRawValueString("ContentPadding", string.Empty); 84 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 85 contentPadding = contentPadding == "small" ? "p-3 p-md-3" : contentPadding; 86 contentPadding = contentPadding == "large" ? "p-5 p-md-5" : contentPadding; 87 88 string horizontalAlign = Model.Item?.GetRawValueString("Alignment", ""); 89 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 90 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 91 92 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 93 } 94 95 @if (Pageview.IsVisualEditorMode) 96 { 97 <div class="alert alert-dark m-0" role="alert"> 98 <span>@Translate("Planned reorder date container will be rendered here")</span> 99 </div> 100 } 101 102 @if (!string.IsNullOrEmpty(currentStockAmount)) 103 { 104 <div class="@(theme) @(contentPadding) @(horizontalAlign) item_@Model.Item.SystemName.ToLower()"> 105 @if (!hideTitle) 106 { 107 <div class="@(titleFontSize) @(titleColor)">@title</div> 108 } 109 110 111 @{ 112 bool isPreorderable = Convert.ToBoolean(preorderable?.Value); 113 bool isOutOfStock = Convert.ToDouble(currentStockAmount) == 0; 114 bool hasExpectedDeliveryDate = nextAvailableDate > DateTime.Now; 115 116 117 if (isOutOfStock) 118 { 119 if (hasExpectedDeliveryDate) 120 { 121 var message = Translate("The product is out of stock. Expected back in stock: {{date}}"); 122 message = message.Replace("{{date}}", nextAvailableDate.ToString("dd.MM.yyyy")); 123 <div><p class="m-0">@message</p></div> 124 } 125 else 126 { 127 if (isPreorderable) 128 { 129 if (hasExpectedDeliveryDate) 130 { 131 var message = Translate("The product is available for preorder. The expected delivery date will be from {{date}}"); 132 message = message.Replace("{{date}}", nextAvailableDate.ToString("dd.MM.yyyy")); 133 <div><p class="m-0">@message</p></div> 134 } 135 else 136 { 137 var message = Translate("The product is available for preorder"); 138 <div><p class="m-0">@message</p></div> 139 } 140 141 } 142 } 143 } 144 else 145 { 146 if (hasExpectedDeliveryDate) 147 { 148 var message = Translate("The product has not yet been released but is available for preorder. The expected delivery date will be from {{date}}"); 149 message = message.Replace("{{date}}", nextAvailableDate.ToString("dd.MM.yyyy")); 150 <div><p class="m-0">@message</p></div> 151 } 152 } 153 } 154 </div> 155 } 156
Wir verwenden Cookies, um Ihnen einen optimalen Service anzubieten und diesen immer weiter zu verbessern. Durch Klicken auf „Alle akzeptieren“ gestatten Sie uns Informationen zu verschiedenen Zwecken zu sammeln, einschließlich: Funktionalität, Statistik und Marketing. Weitere Details finden Sie unter „Einstellungen anpassen“ und in unserer Datenschutzerklärung.