/
Stock.php
114 lines (103 loc) · 2.94 KB
/
Stock.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogInventory\Model\Indexer;
use Magento\Framework\Indexer\CacheContext;
class Stock implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface
{
/**
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Action\Row
*/
protected $_productStockIndexerRow;
/**
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Action\Rows
*/
protected $_productStockIndexerRows;
/**
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Action\Full
*/
protected $_productStockIndexerFull;
/**
* @var \Magento\Framework\Indexer\CacheContext
*/
private $cacheContext;
/**
* @param Stock\Action\Row $productStockIndexerRow
* @param Stock\Action\Rows $productStockIndexerRows
* @param Stock\Action\Full $productStockIndexerFull
*/
public function __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
) {
$this->_productStockIndexerRow = $productStockIndexerRow;
$this->_productStockIndexerRows = $productStockIndexerRows;
$this->_productStockIndexerFull = $productStockIndexerFull;
}
/**
* Execute materialization on ids entities
*
* @param int[] $ids
*
* @return void
*/
public function execute($ids)
{
$this->_productStockIndexerRows->execute($ids);
}
/**
* Execute full indexation
*
* @return void
*/
public function executeFull()
{
$this->_productStockIndexerFull->execute();
$this->getCacheContext()->registerTags(
[
\Magento\Catalog\Model\Category::CACHE_TAG,
\Magento\Catalog\Model\Product::CACHE_TAG
]
);
}
/**
* Execute partial indexation by ID list
*
* @param int[] $ids
*
* @return void
*/
public function executeList(array $ids)
{
$this->_productStockIndexerRows->execute($ids);
}
/**
* Execute partial indexation by ID
*
* @param int $id
*
* @return void
*/
public function executeRow($id)
{
$this->_productStockIndexerRow->execute($id);
}
/**
* Get cache context
*
* @return \Magento\Framework\Indexer\CacheContext
* @deprecated 100.0.7
* @see we don't add dependecies this way anymore
*/
protected function getCacheContext()
{
if (!($this->cacheContext instanceof CacheContext)) {
return \Magento\Framework\App\ObjectManager::getInstance()->get(CacheContext::class);
} else {
return $this->cacheContext;
}
}
}