Developer forum

Forum » Development » Group and sort products in list

Group and sort products in list


Reply
Hey,

I am running into a problem here. I need to group products by serialno and sort the products by a variantno. Products is imported from NAV - and because of productgroup structure - sort isn't an option there.

I tried to inherit the ProductListTemplateExtender and make the group sort on a generic list of products and push it back to the ProductCollection and assign it to the original base.ProductList reference.

I hoped I would be able to overrule the standard sort, but it looks like it's not possible.

What to do?

- Allan

Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
Hi Allan

You can sort your products in a custom way by hooking into the notification "Notifications.eCommerce.ProductList.BeforePaging". That notification is broadcast just after the standard eCom product sort has completed. From the notification args object (after you've cast it to "Notification.eCommerce.ProductList.BeforePagingArgs") you can get the ProductCollection object and manipulate it any way you'd like.

- Jeppe
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
The type you cast the notification args object to is of course "Notifications.eCommerce.ProductList.BeforePagingArgs". Forgot the "s" in my previous post, sorry :-)
 
Reply
Hey,

How do I referer to my sorted productcollection afterwards?

The productlist from the argument is readonly.

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
The product list should contain the products you want, but not the correct sorting. You can simply sort the collection.

If, however, you the collection doesn't contain the products you want, then Clear the collection and add you products. That way you keep the product reference.

 

You must be logged in to post in the forum