Developer forum

Forum » Development » Stopping/redirecting products to right page

Stopping/redirecting products to right page

Paul Nilsson
Reply
I have two pages with the e-com productlist module and they have each a different group selected.
the thing is that it is possible to show a produkt from the other group on the wrong page if you know the productid.
Can I somehow stop the wrong products from showing up on the wrong page or redirect then to the right page?
   

Replies

 
Vladimir
Reply
Hi!
You can do this using NotificationSubscriber.
For example, so:
 
  [Subscribe(Dynamicweb.Notifications.eCommerce.Product.BeforeRender)]
    public class BeforeProductRenderObserver : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs args)
        {
            var arg = args as Dynamicweb.Notifications.eCommerce.Product.BeforeRenderArgs;
            if (arg != null)
            {
                int pageID = PageView.Current().ID;
                Dynamicweb.Content.Paragraph paragraph = Dynamicweb.Content.Paragraph.GetParagraphsByPageID(pageID).Where( par => par.ModuleSystemName == "eCom_Catalog" ).FirstOrDefault();
                if (!paragraph.ModuleProperties.get_Value("Groups").Split(',').Contains(arg.Product.Groups.get_Item(0).ID))
                    HttpContext.Current.Response.Redirect("/Default.aspx");
            }
            base.OnNotify(notification, args);
        }
    }
Best regards,
Vladimir

 

You must be logged in to post in the forum