|
6 | 6 |
|
7 | 7 | namespace Magento\CatalogInventory\Model\Indexer\Stock; |
8 | 8 |
|
| 9 | +use Magento\Catalog\Model\Category; |
9 | 10 | use Magento\CatalogInventory\Api\StockConfigurationInterface; |
10 | 11 | use Magento\Framework\App\ResourceConnection; |
11 | 12 | use Magento\Framework\App\ObjectManager; |
@@ -88,6 +89,11 @@ public function clean(array $productIds, callable $reindex) |
88 | 89 | if ($productIds) { |
89 | 90 | $this->cacheContext->registerEntities(Product::CACHE_TAG, array_unique($productIds)); |
90 | 91 | $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]); |
| 92 | + $categoryIds = $this->getCategoryIdsByProductIds($productIds); |
| 93 | + if ($categoryIds){ |
| 94 | + $this->cacheContext->registerEntities(Category::CACHE_TAG, array_unique($categoryIds)); |
| 95 | + $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]); |
| 96 | + } |
91 | 97 | } |
92 | 98 | } |
93 | 99 |
|
@@ -159,6 +165,22 @@ private function getProductIdsForCacheClean(array $productStatusesBefore, array |
159 | 165 | return $productIds; |
160 | 166 | } |
161 | 167 |
|
| 168 | + /** |
| 169 | + * Get category ids for products |
| 170 | + * |
| 171 | + * @param array $productIds |
| 172 | + * @return array |
| 173 | + */ |
| 174 | + private function getCategoryIdsByProductIds(array $productIds): array |
| 175 | + { |
| 176 | + $categoryProductTable = $this->getConnection()->getTableName('catalog_category_product'); |
| 177 | + $select = $this->getConnection()->select() |
| 178 | + ->from(['catalog_category_product' => $categoryProductTable], ['category_id']) |
| 179 | + ->where('product_id IN (?)', $productIds); |
| 180 | + |
| 181 | + return $this->getConnection()->fetchCol($select); |
| 182 | + } |
| 183 | + |
162 | 184 | /** |
163 | 185 | * Get database connection. |
164 | 186 | * |
|
0 commit comments