5
5
*/
6
6
namespace Magento \Catalog \Model \Indexer \Product \Price \Action ;
7
7
8
- use Magento \Directory \Model \CurrencyFactory ;
9
8
use Magento \Catalog \Model \Indexer \Product \Price \DimensionCollectionFactory ;
10
9
use Magento \Catalog \Model \Indexer \Product \Price \TableMaintainer ;
10
+ use Magento \Catalog \Model \Product ;
11
11
use Magento \Catalog \Model \Product \Type ;
12
12
use Magento \Catalog \Model \ResourceModel \Product \Indexer \Price \DefaultPrice ;
13
13
use Magento \Catalog \Model \ResourceModel \Product \Indexer \Price \Factory ;
14
14
use Magento \Catalog \Model \ResourceModel \Product \Indexer \Price \TierPrice ;
15
+ use Magento \Directory \Model \CurrencyFactory ;
15
16
use Magento \Framework \App \Config \ScopeConfigInterface ;
17
+ use Magento \Framework \App \ObjectManager ;
18
+ use Magento \Framework \Indexer \CacheContext ;
16
19
use Magento \Framework \Stdlib \DateTime ;
17
20
use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
18
21
use Magento \Store \Model \StoreManagerInterface ;
@@ -34,6 +37,11 @@ class Rows extends \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction
34
37
*/
35
38
private $ batchSize ;
36
39
40
+ /**
41
+ * @var CacheContext
42
+ */
43
+ private CacheContext $ cacheContext ;
44
+
37
45
/**
38
46
* @param ScopeConfigInterface $config
39
47
* @param StoreManagerInterface $storeManager
@@ -63,7 +71,8 @@ public function __construct(
63
71
TierPrice $ tierPriceIndexResource = null ,
64
72
DimensionCollectionFactory $ dimensionCollectionFactory = null ,
65
73
TableMaintainer $ tableMaintainer = null ,
66
- ?int $ batchSize = null
74
+ ?int $ batchSize = null ,
75
+ CacheContext $ cacheContext = null
67
76
) {
68
77
parent ::__construct (
69
78
$ config ,
@@ -79,6 +88,7 @@ public function __construct(
79
88
$ tableMaintainer
80
89
);
81
90
$ this ->batchSize = $ batchSize ?? self ::BATCH_SIZE ;
91
+ $ this ->cacheContext = $ cacheContext ?? ObjectManager::getInstance ()->get (CacheContext::class);
82
92
}
83
93
84
94
/**
@@ -101,7 +111,7 @@ public function execute($ids)
101
111
$ currentBatch [] = $ id ;
102
112
if (++$ i === $ this ->batchSize ) {
103
113
try {
104
- $ this ->_reindexRows ($ currentBatch );
114
+ $ this ->cacheContext -> registerEntities (Product:: CACHE_TAG , $ this -> _reindexRows ($ currentBatch) );
105
115
} catch (\Exception $ e ) {
106
116
throw new \Magento \Framework \Exception \LocalizedException (__ ($ e ->getMessage ()), $ e );
107
117
}
@@ -112,7 +122,7 @@ public function execute($ids)
112
122
113
123
if (!empty ($ currentBatch )) {
114
124
try {
115
- $ this ->_reindexRows ($ currentBatch );
125
+ $ this ->cacheContext -> registerEntities (Product:: CACHE_TAG , $ this -> _reindexRows ($ currentBatch) );
116
126
} catch (\Exception $ e ) {
117
127
throw new \Magento \Framework \Exception \LocalizedException (__ ($ e ->getMessage ()), $ e );
118
128
}
0 commit comments