Error executing template "Designs/Swift-v2/Paragraph/Swift-v2_BackInStockNotification.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_657de0bf01354671a0fb9c8d0f7e1baa.ExecuteAsync()
at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.DynamicWrapperService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass23_0.<Run>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template) in /_/src/Application/Providers/Dynamicweb.Rendering.Providers.NetCore/Razor/RazorTemplateRenderingProvider.cs:line 68
at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template) in E:\dw10agent2\_w\3\s\src\Core\Dynamicweb.Core\Rendering\TemplateRenderingService.cs:line 14
at Dynamicweb.Rendering.Template.RenderRazorTemplate() in E:\dw10agent2\_w\3\s\src\Core\Dynamicweb.Core\Rendering\Template.cs:line 805
1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@using System.Linq
@using Dynamicweb.Ecommerce
@using Dynamicweb.Ecommerce.ProductCatalog
@using Dynamicweb.Ecommerce.Products
@using Dynamicweb.Ecommerce.Stocks
@functions
{
private static bool BackInStockRegisteredForUser(ProductViewModel product, string unitId = "", long stocklocationId = 0)
{
if (!Dynamicweb.Security.UserManagement.User.IsExtranetUserLoggedIn()) return false;
Product productObject = Services.Products.GetProductById(product.Id, product.VariantId, product.LanguageId);
StockLocation stockLocation = Services.StockService.GetStockLocation(stocklocationId);
double unitStock = productObject.GetUnitStock(stockLocation, unitId);
return unitStock <= 0d && ProductBackInStockNotification.BackInStockNotificationExists(productObject, unitId);
}
}
@{
ProductViewModel product = null;
if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
{
product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
}
}
@if ((product is object && product.ProductType == Dynamicweb.Ecommerce.Products.ProductType.Stock))
{
bool productInStock = product.StockLevel > 0 || product.NeverOutOfstock;
if (!productInStock)
{
string notifiedMessage = Model.Item.GetString("NotifiedMessage");
string notifiedMessageId = $"NotifiedMessage_item_{Model.Item.SystemName.ToLower()}_{product.Id}_{product.VariantId.Replace(".", "_")}";
string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", "");
horizontalAlign = horizontalAlign == "center" ? "justify-content-center" : horizontalAlign;
horizontalAlign = horizontalAlign == "end" ? "justify-content-end" : horizontalAlign;
horizontalAlign = horizontalAlign == "full" ? "" : horizontalAlign;
string flexFill = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "flex-fill" : "";
string fullWidth = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "w-100" : "";
bool notificationRegisteredForUser = BackInStockRegisteredForUser(product);
<div class="d-flex flex-row w-100 @horizontalAlign @fullWidth item_@Model.Item.SystemName.ToLower()">
<div class="@horizontalAlign @fullWidth @(notificationRegisteredForUser ? "" : "d-none")" id="@notifiedMessageId">
@notifiedMessage
</div>
@if (!notificationRegisteredForUser)
{
string notifyIcon = Model.Item.GetString("Icon");
string notifyLabel = !notifyIcon.Contains("_none") ? "<span class=\"icon-2\">" + ReadFile(notifyIcon) + "</span>" : "";
notifyLabel += " " + Translate("Notify me when available");
string modalId = $"modal_item_{Model.Item.SystemName.ToLower()}_{product.Id}_{product.VariantId.Replace(".", "_")}";
string formId = $"NotificationForm_item_{Model.Item.SystemName.ToLower()}_{product.Id}_{product.VariantId.Replace(".", "_")}";
string notificationButtonId = $"NotificationButton_item_{Model.Item.SystemName.ToLower()}_{product.Id}_{product.VariantId.Replace(".", "_")}";
string notificationOnClick = !Pageview.IsVisualEditorMode ? $"swift.BackInStockNotification.SubmitNotification('{formId}', '{modalId}', '{notifiedMessageId}', '{notificationButtonId}')" : "";
string productPage = $"Default.aspx?ID={GetPageIdByNavigationTag("ProductDetailPage")}";
<div class="d-flex @horizontalAlign @fullWidth js-input-group">
<div class="input-group input-primary-button-group flex-nowrap">
<button type="button" class="btn btn-primary @flexFill" data-dw-button="primary" id="@notificationButtonId" data-bs-toggle="modal" data-bs-target="#@modalId">
<span class="text-nowrap d-flex align-items-center justify-content-center gap-2">
@notifyLabel
</span>
</button>
</div>
</div>
<div class="modal fade" id="@modalId" tabindex="-1" aria-labelledby="label_@modalId" aria-hidden="true">
<div class="modal-dialog pt-8">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="label_@modalId">@Translate("Back in stock")</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="@Translate("Close")"></button>
</div>
<div class="modal-body">
<form name="@product.Id" id="@formId" method="post" action="@productPage">
<input type="hidden" name="ProductID" value="@product.Id" />
<input type="hidden" name="VariantID" value="@product.VariantId" />
<input type="hidden" name="LanguageID" value="@product.LanguageId" />
<input type="hidden" name="CartCmd" value="createnotificationforthisproduct" />
<div class="m-2">
@Translate("Send me an email when the product is in stock.")
</div>
<div class="form-floating m-2">
<input class="form-control" type="text" id="NotificationEmail" value="@(Pageview.User != null ? Pageview.User.Email : "")" name="NotificationEmail" placeholder="@Translate("Email")" required="required" aria-required="aria-required" />
<label for="NotificationEmail" class="form-label">@Translate("Email")</label>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dw-button="primary" onclick="@notificationOnClick">@Translate("Submit")</button>
</div>
</div>
</div>
</div>
}
</div>
}
}
else if (Pageview.IsVisualEditorMode)
{
<div class="alert alert-dark m-0">@Translate("Back in stock notification will be shown here")</div>
}
Error executing template "Designs/Swift-v2/Paragraph/Swift-v2_BackInStockNotification.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_657de0bf01354671a0fb9c8d0f7e1baa.ExecuteAsync()
at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.DynamicWrapperService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass23_0.<Run>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template) in /_/src/Application/Providers/Dynamicweb.Rendering.Providers.NetCore/Razor/RazorTemplateRenderingProvider.cs:line 68
at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template) in E:\dw10agent2\_w\3\s\src\Core\Dynamicweb.Core\Rendering\TemplateRenderingService.cs:line 14
at Dynamicweb.Rendering.Template.RenderRazorTemplate() in E:\dw10agent2\_w\3\s\src\Core\Dynamicweb.Core\Rendering\Template.cs:line 805
1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@using System.Linq
@using Dynamicweb.Ecommerce
@using Dynamicweb.Ecommerce.ProductCatalog
@using Dynamicweb.Ecommerce.Products
@using Dynamicweb.Ecommerce.Stocks
@functions
{
private static bool BackInStockRegisteredForUser(ProductViewModel product, string unitId = "", long stocklocationId = 0)
{
if (!Dynamicweb.Security.UserManagement.User.IsExtranetUserLoggedIn()) return false;
Product productObject = Services.Products.GetProductById(product.Id, product.VariantId, product.LanguageId);
StockLocation stockLocation = Services.StockService.GetStockLocation(stocklocationId);
double unitStock = productObject.GetUnitStock(stockLocation, unitId);
return unitStock <= 0d && ProductBackInStockNotification.BackInStockNotificationExists(productObject, unitId);
}
}
@{
ProductViewModel product = null;
if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
{
product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
}
}
@if ((product is object && product.ProductType == Dynamicweb.Ecommerce.Products.ProductType.Stock))
{
bool productInStock = product.StockLevel > 0 || product.NeverOutOfstock;
if (!productInStock)
{
string notifiedMessage = Model.Item.GetString("NotifiedMessage");
string notifiedMessageId = $"NotifiedMessage_item_{Model.Item.SystemName.ToLower()}_{product.Id}_{product.VariantId.Replace(".", "_")}";
string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", "");
horizontalAlign = horizontalAlign == "center" ? "justify-content-center" : horizontalAlign;
horizontalAlign = horizontalAlign == "end" ? "justify-content-end" : horizontalAlign;
horizontalAlign = horizontalAlign == "full" ? "" : horizontalAlign;
string flexFill = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "flex-fill" : "";
string fullWidth = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "w-100" : "";
bool notificationRegisteredForUser = BackInStockRegisteredForUser(product);
<div class="d-flex flex-row w-100 @horizontalAlign @fullWidth item_@Model.Item.SystemName.ToLower()">
<div class="@horizontalAlign @fullWidth @(notificationRegisteredForUser ? "" : "d-none")" id="@notifiedMessageId">
@notifiedMessage
</div>
@if (!notificationRegisteredForUser)
{
string notifyIcon = Model.Item.GetString("Icon");
string notifyLabel = !notifyIcon.Contains("_none") ? "<span class=\"icon-2\">" + ReadFile(notifyIcon) + "</span>" : "";
notifyLabel += " " + Translate("Notify me when available");
string modalId = $"modal_item_{Model.Item.SystemName.ToLower()}_{product.Id}_{product.VariantId.Replace(".", "_")}";
string formId = $"NotificationForm_item_{Model.Item.SystemName.ToLower()}_{product.Id}_{product.VariantId.Replace(".", "_")}";
string notificationButtonId = $"NotificationButton_item_{Model.Item.SystemName.ToLower()}_{product.Id}_{product.VariantId.Replace(".", "_")}";
string notificationOnClick = !Pageview.IsVisualEditorMode ? $"swift.BackInStockNotification.SubmitNotification('{formId}', '{modalId}', '{notifiedMessageId}', '{notificationButtonId}')" : "";
string productPage = $"Default.aspx?ID={GetPageIdByNavigationTag("ProductDetailPage")}";
<div class="d-flex @horizontalAlign @fullWidth js-input-group">
<div class="input-group input-primary-button-group flex-nowrap">
<button type="button" class="btn btn-primary @flexFill" data-dw-button="primary" id="@notificationButtonId" data-bs-toggle="modal" data-bs-target="#@modalId">
<span class="text-nowrap d-flex align-items-center justify-content-center gap-2">
@notifyLabel
</span>
</button>
</div>
</div>
<div class="modal fade" id="@modalId" tabindex="-1" aria-labelledby="label_@modalId" aria-hidden="true">
<div class="modal-dialog pt-8">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="label_@modalId">@Translate("Back in stock")</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="@Translate("Close")"></button>
</div>
<div class="modal-body">
<form name="@product.Id" id="@formId" method="post" action="@productPage">
<input type="hidden" name="ProductID" value="@product.Id" />
<input type="hidden" name="VariantID" value="@product.VariantId" />
<input type="hidden" name="LanguageID" value="@product.LanguageId" />
<input type="hidden" name="CartCmd" value="createnotificationforthisproduct" />
<div class="m-2">
@Translate("Send me an email when the product is in stock.")
</div>
<div class="form-floating m-2">
<input class="form-control" type="text" id="NotificationEmail" value="@(Pageview.User != null ? Pageview.User.Email : "")" name="NotificationEmail" placeholder="@Translate("Email")" required="required" aria-required="aria-required" />
<label for="NotificationEmail" class="form-label">@Translate("Email")</label>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dw-button="primary" onclick="@notificationOnClick">@Translate("Submit")</button>
</div>
</div>
</div>
</div>
}
</div>
}
}
else if (Pageview.IsVisualEditorMode)
{
<div class="alert alert-dark m-0">@Translate("Back in stock notification will be shown here")</div>
}