Component builder for: Ian Test Product detail info

Please Login to see pricing.

In stock In stock
On Backorder On Backorder
Expected back in stock:
Error executing template "Designs/Swift/Paragraph/Custom__ShipDate.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_a8721d993abe488388f2fcb5a895ad5c.Execute() in F:\Domains\Sites\uat-ic.mydwsite.com\Files\Templates\Designs\Swift\Paragraph\Custom__ShipDate.cshtml:line 32
   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 @* 2 Ian notes 8/12/2025: pulled in the manual expected date using the line "DateTime? ManualDate =...", the added the integration expected date using "DateTime? ExpectedDate =...", 3 then created DisplayDateValue so it would only show 1 of the dates and edited the bool section so it would look at displaydatevalue. 4 5 Also, can use template in the future when trying to pull a custom field into a template, use the manual date as example. 6 *@ 7 8 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> 9 @using System 10 @using System.Linq 11 @using Dynamicweb.Ecommerce.ProductCatalog 12 13 @{ 14 ProductViewModel product = null; 15 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 16 { 17 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 18 } 19 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode) 20 { 21 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 22 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 23 24 if (productList?.Products is object) 25 { 26 product = productList.Products[0]; 27 } 28 } 29 30 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]); 31 bool hideStock = Pageview.AreaSettings.GetBoolean("ErpDownHideStock") && isErpConnectionDown; 32 DateTime? ManualDate = product.ProductFields.ContainsKey("ManualProductExpectedDelivery") && DateTime.TryParse(product.ProductFields["ManualProductExpectedDelivery"]?.ToString(), out var dt) ? dt : (DateTime?)null; 33 DateTime? ExpectedDate = product.ExpectedDelivery; 34 DateTime? DisplayDateValue = ExpectedDate ?? ManualDate; 35 bool hasDisplayDate = DisplayDateValue != null && DisplayDateValue > DateTime.Now; 36 } 37 38 39 @if ((product is object && !hideStock) && (hasDisplayDate)) 40 { 41 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 42 horizontalAlign = horizontalAlign == "center" ? "text-center" : horizontalAlign; 43 horizontalAlign = horizontalAlign == "end" ? "text-end" : horizontalAlign; 44 string DisplayDate = DisplayDateValue?.ToShortDateString() ?? ""; 45 46 string liveInfoClass = ""; 47 string productInfoFeed = ""; 48 bool isLazyLoadingForProductInfoEnabled = Dna.Ecommerce.LiveIntegration.TemplatesHelper.IsLazyLoadingForProductInfoEnabled; 49 50 if (isLazyLoadingForProductInfoEnabled) 51 { 52 if (Dynamicweb.Context.Current.Items.Contains("ProductInfoFeed")) 53 { 54 productInfoFeed = Dynamicweb.Context.Current.Items["ProductInfoFeed"]?.ToString(); 55 if (!string.IsNullOrEmpty(productInfoFeed)) 56 { 57 productInfoFeed = $"data-product-info-feed=\"{productInfoFeed}\""; 58 } 59 } 60 liveInfoClass = "js-live-info"; 61 62 <div class="js-stock-state @horizontalAlign item_@Model.Item.SystemName.ToLower() @liveInfoClass" data-product-id="@product.Id" data-variant-id="@product.VariantId" @productInfoFeed> 63 <div class="js-stock-state spinner-border"> 64 <p class="d-none" data-show-if="LiveProductInfo.product.StockLevel <= 0"> 65 <span class="js-text-stock d-none"></span> 66 <span>@Translate("Expected Ship Date"): </span> 67 <span>@DisplayDate</span> 68 </p> 69 </div> 70 </div> 71 } 72 else 73 { 74 string firstUnitId = product?.UnitOptions?.FirstOrDefault() != null ? product.UnitOptions.FirstOrDefault().Id : ""; 75 string defaultUnitId = !string.IsNullOrEmpty(product.DefaultUnitId) ? product.DefaultUnitId : firstUnitId; 76 string unitId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.Form.Get("UnitId")) ? Dynamicweb.Context.Current.Request.Form.Get("UnitId") : defaultUnitId; 77 78 var reserveMode = Dynamicweb.Ecommerce.Frontend.Cart.ProductReserve.Mode; 79 double? reservedAmount = 0; 80 if (reserveMode == Dynamicweb.Ecommerce.Frontend.Cart.ProductReserveMode.AddToCart) 81 { 82 reservedAmount = Dynamicweb.Ecommerce.Frontend.Cart.ProductReserve.GetReservedAmount(product.Id, product.VariantId, 0, unitId); 83 } 84 double? currentStockLevel = product.StockLevel - reservedAmount; 85 86 <div class="js-stock-state @horizontalAlign item_@Model.Item.SystemName.ToLower()"> 87 @if (currentStockLevel <= 0) 88 { 89 <p> 90 <span>@Translate("Expected Ship Date"): </span> 91 <span>@DisplayDate</span> 92 </p> 93 } 94 </div> 95 } 96 } else if (Pageview.IsVisualEditorMode) 97 { 98 <div class="alert alert-info">@Translate("Expected Ship Date will be rendered here")</div> 99 }
By clicking 'Accept All' you consent that we may collect information about you for various purposes, including: Functionality, Statistics and Marketing