|
23 | 23 | use Magento\Framework\Indexer\DimensionFactory;
|
24 | 24 | use Magento\Store\Model\Indexer\WebsiteDimensionProvider;
|
25 | 25 | use Magento\Store\Model\Store;
|
26 |
| -use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory; |
| 26 | +use Magento\Catalog\Model\ResourceModel\Category; |
27 | 27 |
|
28 | 28 | /**
|
29 | 29 | * Product collection
|
@@ -305,9 +305,9 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
|
305 | 305 | private $urlFinder;
|
306 | 306 |
|
307 | 307 | /**
|
308 |
| - * @var CollectionFactory |
| 308 | + * @var Category |
309 | 309 | */
|
310 |
| - private $categoryCollectionFactory; |
| 310 | + private $categoryResourceModel; |
311 | 311 |
|
312 | 312 | /**
|
313 | 313 | * Collection constructor
|
@@ -337,7 +337,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
|
337 | 337 | * @param TableMaintainer|null $tableMaintainer
|
338 | 338 | * @param PriceTableResolver|null $priceTableResolver
|
339 | 339 | * @param DimensionFactory|null $dimensionFactory
|
340 |
| - * @param CollectionFactory|null $categoryCollectionFactory |
| 340 | + * @param Category|null $categoryResourceModel |
341 | 341 | *
|
342 | 342 | * @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
343 | 343 | */
|
@@ -367,7 +367,7 @@ public function __construct(
|
367 | 367 | TableMaintainer $tableMaintainer = null,
|
368 | 368 | PriceTableResolver $priceTableResolver = null,
|
369 | 369 | DimensionFactory $dimensionFactory = null,
|
370 |
| - CollectionFactory $categoryCollectionFactory = null |
| 370 | + Category $categoryResourceModel = null |
371 | 371 | ) {
|
372 | 372 | $this->moduleManager = $moduleManager;
|
373 | 373 | $this->_catalogProductFlatState = $catalogProductFlatState;
|
@@ -401,8 +401,8 @@ public function __construct(
|
401 | 401 | $this->priceTableResolver = $priceTableResolver ?: ObjectManager::getInstance()->get(PriceTableResolver::class);
|
402 | 402 | $this->dimensionFactory = $dimensionFactory
|
403 | 403 | ?: ObjectManager::getInstance()->get(DimensionFactory::class);
|
404 |
| - $this->categoryCollectionFactory = $categoryCollectionFactory ?: ObjectManager::getInstance() |
405 |
| - ->get(CollectionFactory::class); |
| 404 | + $this->categoryResourceModel = $categoryResourceModel ?: ObjectManager::getInstance() |
| 405 | + ->get(Category::class); |
406 | 406 | }
|
407 | 407 |
|
408 | 408 | /**
|
@@ -2104,18 +2104,23 @@ protected function _applyZeroStoreProductLimitations()
|
2104 | 2104 | private function getChildrenCategories(int $categoryId): array
|
2105 | 2105 | {
|
2106 | 2106 | $categoryIds[] = $categoryId;
|
2107 |
| - |
2108 |
| - /** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection */ |
2109 |
| - $categoryCollection = $this->categoryCollectionFactory->create(); |
2110 |
| - $categories = $categoryCollection |
2111 |
| - ->addAttributeToFilter( |
2112 |
| - ['is_anchor', 'path'], |
2113 |
| - [1, ['like' => $categoryId . '/%']] |
2114 |
| - )->getItems(); |
2115 |
| - foreach ($categories as $category) { |
2116 |
| - $categoryChildren = $category->getChildren(); |
2117 |
| - $categoryIds = array_merge($categoryIds, explode(',', $categoryChildren)); |
| 2107 | + $anchorCategory = []; |
| 2108 | + |
| 2109 | + $categories = $this->categoryResourceModel->getCategoryWithChildren($categoryId); |
| 2110 | + $firstCategory = array_shift($categories); |
| 2111 | + if ($firstCategory['is_anchor'] == 1) { |
| 2112 | + $anchorCategory[] = (int)$firstCategory['entity_id']; |
| 2113 | + foreach ($categories as $category) { |
| 2114 | + if (in_array($category['parent_id'], $categoryIds) |
| 2115 | + && in_array($category['parent_id'], $anchorCategory)) { |
| 2116 | + $categoryIds[] = (int)$category['entity_id']; |
| 2117 | + if ($category['is_anchor'] == 1) { |
| 2118 | + $anchorCategory[] = (int)$category['entity_id']; |
| 2119 | + } |
| 2120 | + } |
| 2121 | + } |
2118 | 2122 | }
|
| 2123 | + |
2119 | 2124 | return $categoryIds;
|
2120 | 2125 | }
|
2121 | 2126 |
|
|
0 commit comments