Hi we configured the backinstock notifications for a customer following: https://doc.dynamicweb.com/documentation-9/marketing/other/back-in-stock-notifications
In our template we use:
{{EmailMarketing:Email.ContentLink.Clean}}
So the customer can check the email also on the website. I couldnt get the products to load in the template following that link. I did some digging in the the code and it seems the ViewContext doesnt get set when visiting that link. I guess this is a bug? or i didnt configure it correctly?
Any how for now i fixed it by setting the ViewContext using a NotificationSubcriber on OnBeforeRenderParagraphs with the following code to make it work:
/**
* BUG IN DW?
* Below is to check if recipientId and RecipientSecret in current request so we can set the needed Context which is needed to render the email content.
* This situation occurse when people use the show in browser link in the send email.
*/
var recipientId = Context.Current.Request.GetInt32("RecipientId");
var recipientSecret = Context.Current.Request["RecipientSecret"];
if (recipientId == 0 || string.IsNullOrWhiteSpace(recipientSecret) || beforeRenderArgs.PageView.Context != null)
{
return;
}
var recipient = Recipient.GetRecipientById(recipientId);
if (recipient == null || recipient.Secret != recipientSecret) return;
var marketingEmail = Dynamicweb.EmailMarketing.Email.GetEmailByMessageId(recipient.MessageId);
if (!(marketingEmail?.RecipientProvider is BackInStockRecipientProvider provider)) return;
var viewContext = provider.GetRecipientContentContext(recipient);
beforeRenderArgs.PageView.Context = viewContext;