Developer forum

Forum » Development » Productlist NotificationSubscriber

Productlist NotificationSubscriber

Aki Ruuskanen
Aki Ruuskanen
Reply

Hi,

I trying to create a NotificationSubscriber in DW9 to manipulate the productlist before its sent to frontend. 

I have tried the BeforeRender, BeforeSort and BeforePaging. None of these gives me the whole productcollection. They only give me the current page. 

Even though BeforeRender has "Products" and "PageProducts" they both contain the product for the first page. 

For example if the paging is set to 30 product, both contain 30 products. 

I am using the "Index" as source for products so the "Optimize product" checkbox is not available.

How can I maniupulat the whole product collection before it is sent to fronend?

Regards / Aki

 

Subscriber.JPG

Replies

 
Aki Ruuskanen
Aki Ruuskanen
Reply

What I wanted to do is that some productgroups should by default be filtered on a condition unless a certain other filter is used. 

The solution was to use Ecommerce.Querying.BeforeQuery

The you can for example check and manipulate the parameters with notificationArgs.Settings.Parameters

So I could check for come conditions and the add a parameter if none the conditions were true. Nice. smiley

 

        public override void OnNotify(string notification, NotificationArgs args)
        {
            
            if (!(args is Ecommerce.Querying.BeforeQueryArgs))
                return;

            var notificationArgs = (Ecommerce.Querying.BeforeQueryArgs)args;

            var groupId = !string.IsNullOrEmpty(HttpContext.Current.Request["GroupID"]) ? HttpContext.Current.Request.QueryString.Get("GroupID") : "";
            var currentEcomGroup = Dynamicweb.Ecommerce.Services.ProductGroups.GetGroup(groupId);
            var mainProductListing = Convert.ToBoolean(currentEcomGroup.ProductGroupFieldValues.GetProductGroupFieldValue("MainProductListing").Value);

            if (currentEcomGroup.HasChildGroups && !mainProductListing) return;

            if (notificationArgs.Settings.Parameters.Keys.Contains("Color")) return;

            notificationArgs.Settings.Parameters.Add("MP", true);
                   
        }

Regards /Aki

 

You must be logged in to post in the forum