Skip to content

Commit bf254e7

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-64459' into 2.1-develop-pr35
2 parents 7faa1e4 + 57dd684 commit bf254e7

File tree

5 files changed

+479
-150
lines changed

5 files changed

+479
-150
lines changed

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

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -651,24 +651,52 @@ protected function addFilterGroupToCollection(
651651
Collection $collection
652652
) {
653653
$fields = [];
654-
$categoryFilter = [];
654+
655655
foreach ($filterGroup->getFilters() as $filter) {
656656
$conditionType = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
657+
$isApplied = $this->applyCustomFilter($collection, $filter, $conditionType);
657658

658-
if ($filter->getField() == 'category_id') {
659-
$categoryFilter[$conditionType][] = $filter->getValue();
660-
continue;
659+
if (!$isApplied) {
660+
$fields[] = ['attribute' => $filter->getField(), $conditionType => $filter->getValue()];
661661
}
662-
$fields[] = ['attribute' => $filter->getField(), $conditionType => $filter->getValue()];
663662
}
664663

665-
if ($categoryFilter) {
664+
if ($fields) {
665+
$collection->addFieldToFilter($fields);
666+
}
667+
}
668+
669+
/**
670+
* Apply custom filters to product collection.
671+
*
672+
* @param Collection $collection
673+
* @param \Magento\Framework\Api\Filter $filter
674+
* @param string $conditionType
675+
* @return bool
676+
*/
677+
private function applyCustomFilter(Collection $collection, \Magento\Framework\Api\Filter $filter, $conditionType)
678+
{
679+
if ($filter->getField() == 'category_id') {
680+
$categoryFilter[$conditionType][] = $filter->getValue();
666681
$collection->addCategoriesFilter($categoryFilter);
682+
return true;
667683
}
668684

669-
if ($fields) {
670-
$collection->addFieldToFilter($fields);
685+
if ($filter->getField() == 'store') {
686+
$collection->addStoreFilter($filter->getValue());
687+
return true;
671688
}
689+
690+
if ($filter->getField() == 'website_id') {
691+
$value = $filter->getValue();
692+
if (strpos($value, ',') !== false) {
693+
$value = explode(',', $value);
694+
}
695+
$collection->addWebsiteFilter($value);
696+
return true;
697+
}
698+
699+
return false;
672700
}
673701

674702
/**

0 commit comments

Comments
 (0)