Skip to content

Commit 7590648

Browse files
committed
BUG#AC-711::Duplicate product collection items in Default Store
1 parent dfe7b89 commit 7590648

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,27 +2091,33 @@ protected function _applyZeroStoreProductLimitations()
20912091
$filters = $this->_productLimitationFilters;
20922092
$categories = $this->getChildrenCategories((int)$filters['category_id']);
20932093

2094-
$conditions = [
2095-
'cat_pro.product_id=e.entity_id',
2096-
$this->getConnection()->quoteInto(
2097-
'cat_pro.category_id IN (?)',
2098-
$categories
2099-
),
2100-
];
2101-
$joinCond = join(' AND ', $conditions);
2094+
$categoryProductSelect = $this->getConnection()->select();
2095+
$categoryProductSelect->from("catalog_category_product");
2096+
$categoryProductSelect->reset(\Magento\Framework\DB\Select::ORDER);
2097+
$categoryProductSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
2098+
$categoryProductSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
2099+
$categoryProductSelect->reset(\Magento\Framework\DB\Select::COLUMNS);
2100+
$categoryProductSelect->columns([
2101+
"product_id" => "product_id",
2102+
"min_position" => new \Zend_Db_Expr("MIN(position)")
2103+
]);
2104+
$categoryProductSelect->where("category_id IN (?)", $categories);
2105+
$categoryProductSelect->group("product_id");
2106+
2107+
$joinCond = "cat_pro.product_id = e.entity_id";
21022108

21032109
$fromPart = $this->getSelect()->getPart(\Magento\Framework\DB\Select::FROM);
21042110
if (isset($fromPart['cat_pro'])) {
21052111
$fromPart['cat_pro']['joinCondition'] = $joinCond;
21062112
$this->getSelect()->setPart(\Magento\Framework\DB\Select::FROM, $fromPart);
21072113
} else {
21082114
$this->getSelect()->join(
2109-
['cat_pro' => $this->getTable('catalog_category_product')],
2115+
['cat_pro' => $categoryProductSelect],
21102116
$joinCond,
2111-
['cat_index_position' => 'position']
2117+
['cat_index_position' => 'min_position']
21122118
);
21132119
}
2114-
$this->_joinFields['position'] = ['table' => 'cat_pro', 'field' => 'position'];
2120+
$this->_joinFields['position'] = ['table' => 'cat_pro', 'field' => 'min_position'];
21152121

21162122
return $this;
21172123
}

0 commit comments

Comments
 (0)