Skip to content

Commit 82f7131

Browse files
committed
MAGETWO-64459: [Backport] - Can't get store-specific data via catalog API - for 2.1
1 parent 8ffe3cc commit 82f7131

File tree

5 files changed

+465
-151
lines changed

5 files changed

+465
-151
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -650,24 +650,38 @@ protected function addFilterGroupToCollection(
650650
\Magento\Framework\Api\Search\FilterGroup $filterGroup,
651651
Collection $collection
652652
) {
653-
$fields = [];
654-
$categoryFilter = [];
653+
$customFilterValues = [];
654+
$customFilterMethods = [];
655655
foreach ($filterGroup->getFilters() as $filter) {
656656
$conditionType = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
657657

658-
if ($filter->getField() == 'category_id') {
659-
$categoryFilter[$conditionType][] = $filter->getValue();
660-
continue;
658+
switch ($filter->getField()) {
659+
case 'category_id':
660+
$customFilterValues['category_id'][$conditionType][] = $filter->getValue();
661+
$customFilterMethods['category_id'] = 'addCategoriesFilter';
662+
break;
663+
case 'store':
664+
$customFilterValues['store'] = $filter->getValue();
665+
$customFilterMethods['store'] = 'addStoreFilter';
666+
break;
667+
case 'website_id':
668+
$value = $filter->getValue();
669+
if (strpos($value, ',') !== false) {
670+
$value = explode(',', $value);
671+
}
672+
$customFilterValues['website_id'] = is_array($value) ? $value : [$value];
673+
$customFilterMethods['website_id'] = 'addWebsiteFilter';
674+
break;
675+
default:
676+
$customFilterValues['fields'][] = ['attribute' => $filter->getField(), $conditionType => $filter->getValue()];
677+
$customFilterMethods['fields'] = 'addFieldToFilter';
678+
break;
661679
}
662-
$fields[] = ['attribute' => $filter->getField(), $conditionType => $filter->getValue()];
663-
}
664-
665-
if ($categoryFilter) {
666-
$collection->addCategoriesFilter($categoryFilter);
667680
}
668681

669-
if ($fields) {
670-
$collection->addFieldToFilter($fields);
682+
foreach ($customFilterValues as $filterName => $filterValue) {
683+
$filterMethod = $customFilterMethods[$filterName];
684+
$collection->$filterMethod($filterValue);
671685
}
672686
}
673687

0 commit comments

Comments
 (0)