Skip to content

Commit

Permalink
Merge pull request #3326 from Smile-SA/fix-virtualCategoQueryComputing
Browse files Browse the repository at this point in the history
[Virtual Category] Optimize virtual category rule computation
  • Loading branch information
romainruaud authored Jul 23, 2024
2 parents fad9b59 + 14c08fc commit f56d7cd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/module-elasticsuite-virtual-category/Model/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,16 @@ private function getVirtualCategoryQuery(
$excludedCategories = []
): ?QueryInterface {
$rootCategory = $this->getVirtualRootCategory($category);
if ($rootCategory && in_array($rootCategory->getId(), $excludedCategories)) {
// If the root category of the current virtual category has already been computed (exist in $excludedCategories)
// or if a parent of the root category of the current category has already been computed we don't need
// to compute the rule. All the product will already been present.
// For example, if you have the following category tree:
// - Category A (static)
// - - Category B (static)
// - - Category C (virtual with category B as root)
// When you compute the rule of the category A you do not need to compute the rule of the category C
// as all the product will be there.
if ($rootCategory && array_intersect(explode('/', $rootCategory->getPath()), $excludedCategories)) {
return null;
}

Expand Down

0 comments on commit f56d7cd

Please sign in to comment.