Skip to content

Commit 3e776ee

Browse files
committed
Fix for GitHub issue #14035. Explode a string of category filter. Change the default condition type to in.
1 parent 3f053dd commit 3e776ee

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

app/code/Magento/Catalog/Model/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ProductCategoryFilter.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ class ProductCategoryFilter implements CustomFilterInterface
2121
*/
2222
public function apply(Filter $filter, AbstractDb $collection)
2323
{
24-
$conditionType = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
25-
$categoryFilter = [$conditionType => [$filter->getValue()]];
24+
$value = $filter->getValue();
25+
$conditionType = $filter->getConditionType() ? $filter->getConditionType() : 'in';
26+
if (($conditionType == 'in' || $conditionType == 'nin') && is_string($value)) {
27+
$value = explode(',', $value);
28+
} else {
29+
$value = [$value];
30+
}
31+
$categoryFilter = [$conditionType => $value];
2632

2733
/** @var Collection $collection */
2834
$collection->addCategoriesFilter($categoryFilter);

app/code/Magento/Catalog/Test/Unit/Model/Api/SearchCriteria/CollectionProcessor/FilterProcessor/ProductCategoryFilterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testApplyWithoutCondition()
6666

6767
$collectionMock->expects($this->once())
6868
->method('addCategoriesFilter')
69-
->with(['eq' => ['value']]);
69+
->with(['in' => ['value']]);
7070

7171
$this->assertTrue($this->model->apply($filterMock, $collectionMock));
7272
}

0 commit comments

Comments
 (0)