Developer forum

Forum » Development » ProductListTemplateExtender

ProductListTemplateExtender


Reply
Hey, i have a ProductListTemplateExtender, where i want to filter out some products, but can't seem to get it to work.

Even if i do the following:

 public override void ExtendTemplate(Dynamicweb.Templatev2.Template Template)
 {
         ProductList.Clear();
 }

all products are still on my frontend, what am i missing.

Replies

 
Reply

Hi,

In the productListtemplateExtender you can't modifie the ProductList. Fore some reason the extender is called after the products is rendered.  Instead you must use the ProductList Notification.

[Subscribe(Dynamicweb.Notifications.eCommerce.ProductList.BeforeSort)]
    public class ProductListModifier : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs argsBase)
        {
            Dynamicweb.Notifications.eCommerce.ProductList.BeforeSortArgs args = (Dynamicweb.Notifications.eCommerce.ProductList.BeforeSortArgs)argsBase;

            for (int i = args.Products.Count - 1; i >= 0; i--)
            {
                    if (args.Products[i].ID == 'PROD100')
                        args.Products.RemoveAt(i);
              
            }
        }
    }

 

You must be logged in to post in the forum