Developer forum

Forum » CMS - Standard features » Showing main products based on variants with new repositories

Showing main products based on variants with new repositories

Kasper Vesth
Reply

I have a question regarding the new repositories used for filtering eCommerce products.

I am aware that the filtering has no sense of eCommerce context as such, so this will be more of a discussion of best practice.

I have a test site here: http://feenogfroen3.staging.nozebrahosting.dk/maerker/g-i/hummel with some filters made by using the facets specified in my repository. The use case is as follows:

When I choose a size from the dropdown I want to see the main products that have variants with the given size(s). Because of the way the customers sizes vary Size is based on a custom field that holds the sizes of the variant (A variant can cover more than one size). A size field could look like this: "140, 146, 152", which would give the 3 different values in the dropdown for the facet.

The facets work like a charm, but because we only want to show main products we have set isvariant = false as standard. This means however, that if we filter by a size that is not present on the main product we won't see it in the list (the reason there are any products at all was because we made the main product have the same value as the first variant).

As I see it there are 3 possibilities:

1: We set the size field on the main product so it has all the covered sizes of the variants. This has the drawback that if a size is being sold out (there are typically only 1 or 2 of each size), the product won't disappear from the product list unless we update the main product again, and update the indexes.

2: We specify in the query that if we have searched for a size we also search for isvariant=true, and get a product in the list for each variant, which will essentially make the same product appear many times.

3: We do a manual sorting and only show main products after the index has returned its results. That would however mess with the paging and numbering of products.

This is a specific case of a pretty generic feature many customers would expect. How would you go about doing a filtering of main products based on values on the variants of the product with the new repositories? I hope some of you have some good ideas :)

Regards

Kasper


Replies

 
Nicolai Høeg Pedersen
Reply

Your solution 1 is the only option as I see it. No matter what we did, the index needs an update to avoid the facets to count the variant no longer in stock...

Facets are calculated based on the index, and if a product or a variant is in stock at the indexing time and gets sold out later, it needs a reindex to not be in stock for the next search of the facets. The list of products will not include a product that is sold out no matter what.

What you are trying to create is that your facets are based on the main product document entries only - except for your color facet. You want that to be based on, and count on, the variant documents instead. The only one to achieve that is to add isvariant to the query, set the default to false, and load that one facet group for colors using ajax with the isvariant=true instead. That would make that facet group load based on variant documents instead of the main documents. But, it would still be wrong because of the stock issue.

BR Nicolai.

 

You must be logged in to post in the forum