How about simply decorating your category, product and variant controllers with [ViewedPageCriterion]?
Oh I just commented the same thing on your ticket :). While I'm not 100% sure, it seems to be the way
Well that actually triggerd:
private criterionEvents_VisitedPage(object sender, CriterionEventArgs e)
But since e.GetPageLink(); gets you a PageReference it wont work. It always gives me the start page when visiting Commerce content.
Maybe I can use e.HttpContext in some way to get the actually visited Commerce content or how do I do to get the content?
I tried to rip and rewrite some code from e.GetPageLink:
var contentReference = e.HttpContext.GetService<IContentRouteHelper>().ContentLink
But it wont compile with the error: The non-generic method 'HttpContextBase.GetService(Type)' cannot be used with type arguments
Thanks!
/Kristoffer
Sure, you can use HttpContext.RequestContext.GetRoutedData<IContent>() if you want the actual content. Then you can simply check if that content is a Catalog, Product or Variant by doing smth like:
var content = e.HttpContext.RequestContext.GetRoutedData<IContent>();
if (content is KristoffersProductContent product)
{
// implement
}
If you only want the content link, you can simply run e.HttpContext.RequestContext.GetContentLink().
Thanks for the guidance, this is what solved it:
var c = e.HttpContext.Request.RequestContext.GetContentLink();
In combination with
[ViewedPageCriterion]
public class CategoryController : ContentController<Node> { }
Thanks all for your help!
/Kristoffer
Hi!
I'm trying to create a visitor group criterion for when a user is visting a Commerce category, product or variant. Similar to the page visited that is built in in the CMS.
The event handler:
This only triggers when I access CMS content and not Commerce content? I guess there might be a ICriterionEvents for Commerce content or should the one in EPiServer.Personalization.VisitorGroups also handle Commerce content?
Thanks!
/Kristoffer