Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check if product is part of Virtual Category? #3385

Closed
gkopec opened this issue Sep 16, 2024 · 2 comments
Closed

How to check if product is part of Virtual Category? #3385

gkopec opened this issue Sep 16, 2024 · 2 comments

Comments

@gkopec
Copy link

gkopec commented Sep 16, 2024

I would like to check if a product is in Virtual Category during add to cart action.

@rbayet
Copy link
Collaborator

rbayet commented Sep 16, 2024

Hello @gkopec,

Apart from the naive approach which would consist of

  • listing all active virtual categories
  • for each one of them executing the category query + a filter on the current product added to cart with a page size of 1
  • and then determine if the product belongs to the category (number of results = 1) or not (number of results = 0)

the best way to do that would be to create a special index to use for percolation requests :

  • in a special "virtual_categories" index, all virtual categories are indexed with their built/ready to be executed rule query as the percolate field
  • in the code executed in the add to cart, you perform a "percolate" request on that index by providing as document to test the queries the representation of the as it's available in the "catalog_product" index (think the "_source" structure)
  • the percolate request will answer which virtual categories documents have a percolate field (rule query) that the product matches

This feature is not yet available out of the box in Elasticsuite, but we do have something similar in Elasticsuite Premium where we percolate optimizers rules so we can determine which optimizers conditions a product would match.

Regards,

@rbayet
Copy link
Collaborator

rbayet commented Sep 16, 2024

You can have a look at https://github.com/Smile-SA/magento2-module-elasticsuite-targetrule which is an Open Source module that we don't really maintain anymore.
But it uses a percolation index/requests to determine which Target Rules conditions a product would match, so that could give you an idea of how to implement what I'm talking about.

PS: we might introduce in the future percolation of virtual categories rules inside Elasticsuite, but I don't think it's even on our roadmap yet, so don't hold your breath :)

@gkopec gkopec closed this as completed Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants