@@ -2068,7 +2068,7 @@ protected function _applyProductLimitations()
2068
2068
protected function _applyZeroStoreProductLimitations ()
2069
2069
{
2070
2070
$ filters = $ this ->_productLimitationFilters ;
2071
- $ categories = $ this ->getChildrenCategories ((int )$ filters ['category_id ' ], [] );
2071
+ $ categories = $ this ->getChildrenCategories ((int )$ filters ['category_id ' ]);
2072
2072
2073
2073
$ conditions = [
2074
2074
'cat_pro.product_id=e.entity_id ' ,
@@ -2099,30 +2099,22 @@ protected function _applyZeroStoreProductLimitations()
2099
2099
* Get children categories.
2100
2100
*
2101
2101
* @param int $categoryId
2102
- * @param array $categories
2103
2102
* @return array
2104
2103
*/
2105
- private function getChildrenCategories (int $ categoryId, array $ categories ): array
2104
+ private function getChildrenCategories (int $ categoryId ): array
2106
2105
{
2107
- $ categories [] = $ categoryId ;
2106
+ $ categoryIds [] = $ categoryId ;
2108
2107
2109
2108
/** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection */
2110
2109
$ categoryCollection = $ this ->categoryCollectionFactory ->create ();
2111
- $ category = $ categoryCollection
2112
- ->addAttributeToSelect ('is_anchor ' )
2110
+ $ categories = $ categoryCollection
2113
2111
->addAttributeToFilter ('is_anchor ' , 1 )
2114
- ->addIdFilter ([$ categoryId ])
2115
- ->getFirstItem ();
2116
- if ($ category ) {
2112
+ ->addAttributeToFilter ('path ' , ['like ' => $ categoryId . '/% ' ])->getItems ();
2113
+ foreach ($ categories as $ category ) {
2117
2114
$ 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 ));
2124
2116
}
2125
- return $ categories ;
2117
+ return $ categoryIds ;
2126
2118
}
2127
2119
2128
2120
/**
0 commit comments