@@ -2091,27 +2091,33 @@ protected function _applyZeroStoreProductLimitations()
2091
2091
$ filters = $ this ->_productLimitationFilters ;
2092
2092
$ categories = $ this ->getChildrenCategories ((int )$ filters ['category_id ' ]);
2093
2093
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 " ;
2102
2108
2103
2109
$ fromPart = $ this ->getSelect ()->getPart (\Magento \Framework \DB \Select::FROM );
2104
2110
if (isset ($ fromPart ['cat_pro ' ])) {
2105
2111
$ fromPart ['cat_pro ' ]['joinCondition ' ] = $ joinCond ;
2106
2112
$ this ->getSelect ()->setPart (\Magento \Framework \DB \Select::FROM , $ fromPart );
2107
2113
} else {
2108
2114
$ this ->getSelect ()->join (
2109
- ['cat_pro ' => $ this -> getTable ( ' catalog_category_product ' ) ],
2115
+ ['cat_pro ' => $ categoryProductSelect ],
2110
2116
$ joinCond ,
2111
- ['cat_index_position ' => 'position ' ]
2117
+ ['cat_index_position ' => 'min_position ' ]
2112
2118
);
2113
2119
}
2114
- $ this ->_joinFields ['position ' ] = ['table ' => 'cat_pro ' , 'field ' => 'position ' ];
2120
+ $ this ->_joinFields ['position ' ] = ['table ' => 'cat_pro ' , 'field ' => 'min_position ' ];
2115
2121
2116
2122
return $ this ;
2117
2123
}
0 commit comments