Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Stock.php
Go to the documentation of this file.
1 <?php
7 
9 
11 {
16 
21 
26 
30  private $cacheContext;
31 
37  public function __construct(
38  \Magento\CatalogInventory\Model\Indexer\Stock\Action\Row $productStockIndexerRow,
39  \Magento\CatalogInventory\Model\Indexer\Stock\Action\Rows $productStockIndexerRows,
40  \Magento\CatalogInventory\Model\Indexer\Stock\Action\Full $productStockIndexerFull
41  ) {
42  $this->_productStockIndexerRow = $productStockIndexerRow;
43  $this->_productStockIndexerRows = $productStockIndexerRows;
44  $this->_productStockIndexerFull = $productStockIndexerFull;
45  }
46 
54  public function execute($ids)
55  {
56  $this->_productStockIndexerRows->execute($ids);
57  $this->getCacheContext()->registerEntities(\Magento\Catalog\Model\Product::CACHE_TAG, $ids);
58  }
59 
65  public function executeFull()
66  {
67  $this->_productStockIndexerFull->execute();
68  $this->getCacheContext()->registerTags(
69  [
70  \Magento\Catalog\Model\Category::CACHE_TAG,
71  \Magento\Catalog\Model\Product::CACHE_TAG
72  ]
73  );
74  }
75 
83  public function executeList(array $ids)
84  {
85  $this->_productStockIndexerRows->execute($ids);
86  }
87 
95  public function executeRow($id)
96  {
97  $this->_productStockIndexerRow->execute($id);
98  }
99 
106  protected function getCacheContext()
107  {
108  if (!($this->cacheContext instanceof CacheContext)) {
109  return \Magento\Framework\App\ObjectManager::getInstance()->get(CacheContext::class);
110  } else {
111  return $this->cacheContext;
112  }
113  }
114 }
$id
Definition: fieldset.phtml:14
__construct(\Magento\CatalogInventory\Model\Indexer\Stock\Action\Row $productStockIndexerRow, \Magento\CatalogInventory\Model\Indexer\Stock\Action\Rows $productStockIndexerRows, \Magento\CatalogInventory\Model\Indexer\Stock\Action\Full $productStockIndexerFull)
Definition: Stock.php:37