Developer forum

Forum » Development » ProductCatalog Event before paging, remove products but keep products per page.

ProductCatalog Event before paging, remove products but keep products per page.

Dimitrij Jazel
Reply

Hi Guys,

I have a product catalog, that uses new index. DW APP: 8.8.1.18

In product catalog, I have 100 products total.

Showing 20 products per page.

 

What notification subscriber do I need to use

So that I could remove products from before they are aded to the page.

And making sure it would not leave enpty product gaps, and show completed page with 20 products. Instead of leaving empty gaps by showing 18-19 products, and 20 on another one.

 

For example, 5 products, have ProductField called "Model"

If they have the same model - than I must show only first product that has the same model.

PROD1 has Model A.

PROD2 has Model B

PROD3 has Model A

PROD4 has Model A

PROD5 has Model C

I would need to show catalog like this;

PROD1

PROD2

PROD5

 

Here is what I tried so far:

Dynamicweb.Notifications.eCommerce.ProductList.BeforePaging looked very prommising at first.

But when I was removing product from beforePagingArgs.Products - It leaves branks.

 

This is how my implementation looks like:

[Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.eCommerce.ProductList.BeforePaging)]
public class BeforePaging : Dynamicweb.Extensibility.NotificationSubscriber
{
    public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
    {
        Dynamicweb.Notifications.eCommerce.ProductList.BeforePagingArgs beforePagingArgs = args as Dynamicweb.Notifications.eCommerce.ProductList.BeforePagingArgs;

        List<string> removeProducts = fetchProductsToRemove(); // populate list with ProductIDs
        
        if (removeProducts.Any())
        {
            foreach (string pID in removeProducts)
            {
                var targetInt = beforePagingArgs.Products.IndexOf(pID);
                beforePagingArgs.Products.Remove(beforePagingArgs.Products[targetInt]);
            }
        }
    }
}

Logic works, it removes from ProductList, but removes AFTER paging. Result is blank product spaces.

Am I using it wrong, or what?

 

I also tried subscribing to other events, but than product catalog dissapears completely.

 

/Dmitrij


Replies

 
Nicolai Pedersen
Reply

From this thread: http://doc.dynamicweb.com/forum/development/development/sortering-af-en-allerede-sorteret-liste-fra-repository

The short answer - you cannot do it like this.

The index only returns the product ids you need to make one page at a time. So no matter what notification you use, you will only see a collection of that one page.

So if you cannot make some kind of indicator on your index that will make it possible for you to filter out the results during the search, I cannot think of a way to achieve this using the index search.

My only idea is to set the page size to 1000 and use the notifications you do now, and then in your Razor template handle the paging there. It will of course load way too much product data on the server, but if this way of working is important, that is the only option I see.

 
Dimitrij Jazel
Reply

Hi Nicolai,

But what if "preloading" products takes about 2 minutes to load (because there are about 2500 products).

 

But than, how did you guys build "Assortments"?

Could we maybe (if not now maybe in future versions of DW) hook up, and add some additional that would basically show or Hide product from whole product range, in the same way how Assortments are doing it?

So far assortments work really fine overall.

/Dmitrij

 
Nicolai Pedersen
Reply

Hi Dmitrij.

I don't know your exact logic. But you probably need to build an IndexBuilderExtension that will add additional data on the product that you can use in your query or you can maybe make a macro which can be used as a value in a criteria - that is how we do assortments.

But you need to think of some logic so you can filter your results during search.

 
Dimitrij Jazel
Reply

As you said here Nicolai,

"or you can maybe make a macro which can be used as a value in a criteria - that is how we do assortments."

Bingo! :) That is exactly what I need than. Is that a custom Macro, or something else?

Cause I did not see any info about creating those.

 

Would REALLY appreciate if you could provide some info about this :-)))

/Dmitrij

 

 
Nicolai Pedersen
Reply

I can.

In the upper right corner of this website you find a search box. If you type in "Indexing macro" you get some nice results. One of them being : http://doc.dynamicweb.com/forum?M=BasicForum&PID=1605&ThreadID=49689

You can also go into the Dynamicweb 8/Dynamicweb 9 documentation under platform, searching and indexing, and read about macros there.

BR Nicolai

 
Dimitrij Jazel
Reply

Yes, I am full aware of that feature, thanks for reminding about it.

And thanks for this info Nicolai, atleast now I know what to look for. :-)

 

 

Regarding current search.

Global search is nice, but when you get a ton of stuff that you have to go through in hope for some usefull info, I am still hoping this forum post was not forgotten:

http://doc.dynamicweb.com/forum/feature-requests/forum-search-feature-request?M=BasicForum&PID=1605

http://doc.dynamicweb.com/forum/feature-requests/developer-forum-search-features

 

 

You must be logged in to post in the forum