Skip to content

Commit 2681670

Browse files
MAGETWO-94565: Catalog product collection filters produce errors and cause inconsistent behaviour
- Fix CR comments.
1 parent 62bfe24 commit 2681670

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,7 +2068,7 @@ protected function _applyProductLimitations()
20682068
protected function _applyZeroStoreProductLimitations()
20692069
{
20702070
$filters = $this->_productLimitationFilters;
2071-
$categories = $this->getChildrenCategories((int)$filters['category_id'], []);
2071+
$categories = $this->getChildrenCategories((int)$filters['category_id']);
20722072

20732073
$conditions = [
20742074
'cat_pro.product_id=e.entity_id',
@@ -2099,30 +2099,22 @@ protected function _applyZeroStoreProductLimitations()
20992099
* Get children categories.
21002100
*
21012101
* @param int $categoryId
2102-
* @param array $categories
21032102
* @return array
21042103
*/
2105-
private function getChildrenCategories(int $categoryId, array $categories): array
2104+
private function getChildrenCategories(int $categoryId): array
21062105
{
2107-
$categories[] = $categoryId;
2106+
$categoryIds[] = $categoryId;
21082107

21092108
/** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection */
21102109
$categoryCollection = $this->categoryCollectionFactory->create();
2111-
$category = $categoryCollection
2112-
->addAttributeToSelect('is_anchor')
2110+
$categories = $categoryCollection
21132111
->addAttributeToFilter('is_anchor', 1)
2114-
->addIdFilter([$categoryId])
2115-
->getFirstItem();
2116-
if ($category) {
2112+
->addAttributeToFilter('path', ['like' => $categoryId . '/%'])->getItems();
2113+
foreach ($categories as $category) {
21172114
$categoryChildren = $category->getChildren();
2118-
$categoryChildrenIds = explode(',', $categoryChildren);
2119-
foreach ($categoryChildrenIds as $categoryChildrenId) {
2120-
if ($categoryChildrenId) {
2121-
$categories = $this->getChildrenCategories((int)$categoryChildrenId, $categories);
2122-
}
2123-
}
2115+
$categoryIds = array_merge($categoryIds, explode(',', $categoryChildren));
21242116
}
2125-
return $categories;
2117+
return $categoryIds;
21262118
}
21272119

21282120
/**

0 commit comments

Comments
 (0)