Developer forum

Forum » Development » Change amount of products displayed in a ProductList with the standard eCom Product list module

Change amount of products displayed in a ProductList with the standard eCom Product list module

Bo Møller
Reply
Hi everybody,

I would like to know if it's possible to change the amount of products displayed in a ProductList generated by the standard module for such lists in Dynamicweb. The setting can be accessed today through the module-settings, but I would like to make the setting specific for the user who is browsing the website.

What I'm asking for, is a way to set the amount of products displayed in the frontend - for a specific user - without changing what other users see.

Any suggestions?

Replies

 
Dmitriy Benyuk
Reply
Hi,

you can write the custom module with Notification Subscriber: Dynamicweb.Notifications.eCommerce.ProductList.BeforeSort.
This notification subscriber sample is available in the VisualStudio Templates for Dynamicweb in DW8->eCommerce->ProductList->BeforeSort.

You should override then OnNotify(string notification, NotificationArgs args) method:

public override void OnNotify(string notification, NotificationArgs args)
        {          
            if (User.GetCurrentUser() == null)
                return;
            if(User.Name != "Some User")
                return;
            var myArgs = (Dynamicweb.Notifications.eCommerce.ProductList.BeforeSortArgs)args;
           
            var products = new ProductCollection();
            // FilterProducts for the current user
            foreach(var product in args.Products){
                //some filtering can be there
                if(product.Name == "sample")
                    products.Add(product);
            }
            
            // Remove unavailable products for the current user
            args.Products.Clear();

            //apply filtered products
            foreach (Product product in products)
                args.Products.Add(product);
}

 

You must be logged in to post in the forum