Skip to content

Commit

Permalink
Merge pull request #2392 from romainruaud/fix_virtual-category-filter…
Browse files Browse the repository at this point in the history
…ing-29x

Prevent side effect when building widgets conditions based on virtual…
  • Loading branch information
romainruaud authored Dec 16, 2021
2 parents d2997ed + ef91511 commit 16182db
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ public function __construct(Provider $filterProvider)
*/
public function beforeAddCategoryFilter(Collection $subject, Category $category)
{
$category = clone $category; // Do not apply side-effect on the category itself.

if ($category && $category->getData('is_virtual_category')) {
$query = $this->filterProvider->getQueryFilter($category);
if ($query !== null) {
$subject->addQueryFilter($query);
}
// This is where cloning is useful. Otherwise, we could have a category without id later in the call stack.
$category->setId(null);
}

Expand Down

0 comments on commit 16182db

Please sign in to comment.