Skip to content

Commit 41105c8

Browse files
author
Andrey Konosov
committed
MAGETWO-32726: Varnish: Catalog page is not updated after product returns to stock again
- Added cache invalidation to stock indexer
1 parent 1ea9173 commit 41105c8

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace Magento\CatalogInventory\Model\Indexer\Stock;
1010

11+
use Magento\Catalog\Model\Category;
12+
1113
/**
1214
* Abstract action reindex class
1315
*
@@ -52,6 +54,17 @@ abstract class AbstractAction
5254
*/
5355
protected $_isNeedUseIdxTable = false;
5456

57+
/**
58+
* @var \Magento\Indexer\Model\CacheContext
59+
*/
60+
private $cacheContext;
61+
62+
/**
63+
* @var \Magento\Framework\Event\ManagerInterface
64+
*/
65+
private $eventManager;
66+
67+
5568
/**
5669
* @param \Magento\Framework\App\Resource $resource
5770
* @param \Magento\CatalogInventory\Model\Resource\Indexer\StockFactory $indexerFactory
@@ -60,11 +73,16 @@ abstract class AbstractAction
6073
public function __construct(
6174
\Magento\Framework\App\Resource $resource,
6275
\Magento\CatalogInventory\Model\Resource\Indexer\StockFactory $indexerFactory,
63-
\Magento\Catalog\Model\Product\Type $catalogProductType
76+
\Magento\Catalog\Model\Product\Type $catalogProductType,
77+
\Magento\Indexer\Model\CacheContext $cacheContext,
78+
\Magento\Framework\Event\ManagerInterface $eventManager
79+
6480
) {
6581
$this->_resource = $resource;
6682
$this->_indexerFactory = $indexerFactory;
6783
$this->_catalogProductType = $catalogProductType;
84+
$this->cacheContext = $cacheContext;
85+
$this->eventManager = $eventManager;
6886
}
6987

7088
/**
@@ -228,6 +246,16 @@ protected function _reindexRows($productIds = [])
228246
}
229247
}
230248

249+
$select = $adapter->select()
250+
->distinct(true)
251+
->from($this->_getTable('catalog_category_product'), [ 'category_id'])
252+
->where('product_id IN(?)', $processIds);
253+
254+
$affectedCategories = $adapter->fetchCol($select);
255+
$this->cacheContext->registerEntities(Category::CACHE_TAG, $affectedCategories);
256+
257+
$this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]);
258+
231259
return $this;
232260
}
233261

0 commit comments

Comments
 (0)