7
7
namespace Magento \CatalogRule \Model \Indexer ;
8
8
9
9
use Magento \Catalog \Model \Product ;
10
+ use Magento \Catalog \Model \ProductFactory ;
11
+ use Magento \Catalog \Model \ResourceModel \Indexer \ActiveTableSwitcher ;
10
12
use Magento \CatalogRule \Model \ResourceModel \Rule \Collection as RuleCollection ;
11
13
use Magento \CatalogRule \Model \ResourceModel \Rule \CollectionFactory as RuleCollectionFactory ;
12
14
use Magento \CatalogRule \Model \Rule ;
15
+ use Magento \Eav \Model \Config ;
13
16
use Magento \Framework \App \ObjectManager ;
17
+ use Magento \Framework \App \ResourceConnection ;
18
+ use Magento \Framework \Exception \LocalizedException ;
14
19
use Magento \Framework \Pricing \PriceCurrencyInterface ;
15
20
use Magento \CatalogRule \Model \Indexer \IndexBuilder \ProductLoader ;
16
21
use Magento \CatalogRule \Model \Indexer \IndexerTableSwapperInterface as TableSwapper ;
22
+ use Magento \Framework \Stdlib \DateTime ;
23
+ use Magento \Store \Model \StoreManagerInterface ;
24
+ use Psr \Log \LoggerInterface ;
17
25
18
26
/**
19
27
* Catalog rule index builder
@@ -46,12 +54,12 @@ class IndexBuilder
46
54
protected $ _catalogRuleGroupWebsiteColumnsList = ['rule_id ' , 'customer_group_id ' , 'website_id ' ];
47
55
48
56
/**
49
- * @var \Magento\Framework\App\ ResourceConnection
57
+ * @var ResourceConnection
50
58
*/
51
59
protected $ resource ;
52
60
53
61
/**
54
- * @var \Magento\Store\Model\ StoreManagerInterface
62
+ * @var StoreManagerInterface
55
63
*/
56
64
protected $ storeManager ;
57
65
@@ -61,7 +69,7 @@ class IndexBuilder
61
69
protected $ ruleCollectionFactory ;
62
70
63
71
/**
64
- * @var \Psr\Log\ LoggerInterface
72
+ * @var LoggerInterface
65
73
*/
66
74
protected $ logger ;
67
75
@@ -71,22 +79,22 @@ class IndexBuilder
71
79
protected $ priceCurrency ;
72
80
73
81
/**
74
- * @var \Magento\Eav\Model\ Config
82
+ * @var Config
75
83
*/
76
84
protected $ eavConfig ;
77
85
78
86
/**
79
- * @var \Magento\Framework\Stdlib\ DateTime
87
+ * @var DateTime
80
88
*/
81
89
protected $ dateFormat ;
82
90
83
91
/**
84
- * @var \Magento\Framework\Stdlib\ DateTime\DateTime
92
+ * @var DateTime\DateTime
85
93
*/
86
94
protected $ dateTime ;
87
95
88
96
/**
89
- * @var \Magento\Catalog\Model\ ProductFactory
97
+ * @var ProductFactory
90
98
*/
91
99
protected $ productFactory ;
92
100
@@ -135,61 +143,52 @@ class IndexBuilder
135
143
*/
136
144
private $ pricesPersistor ;
137
145
138
- /**
139
- * @var \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher
140
- */
141
- private $ activeTableSwitcher ;
142
-
143
146
/**
144
147
* @var TableSwapper
145
148
*/
146
149
private $ tableSwapper ;
147
150
148
- /**
149
- * @var ProductLoader
150
- */
151
- private $ productLoader ;
152
-
153
151
/**
154
152
* @param RuleCollectionFactory $ruleCollectionFactory
155
153
* @param PriceCurrencyInterface $priceCurrency
156
- * @param \Magento\Framework\App\ ResourceConnection $resource
157
- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
158
- * @param \Psr\Log\ LoggerInterface $logger
159
- * @param \Magento\Eav\Model\ Config $eavConfig
160
- * @param \Magento\Framework\Stdlib\ DateTime $dateFormat
161
- * @param \Magento\Framework\Stdlib\ DateTime\DateTime $dateTime
162
- * @param \Magento\Catalog\Model\ ProductFactory $productFactory
154
+ * @param ResourceConnection $resource
155
+ * @param StoreManagerInterface $storeManager
156
+ * @param LoggerInterface $logger
157
+ * @param Config $eavConfig
158
+ * @param DateTime $dateFormat
159
+ * @param DateTime\DateTime $dateTime
160
+ * @param ProductFactory $productFactory
163
161
* @param int $batchCount
164
162
* @param ProductPriceCalculator|null $productPriceCalculator
165
163
* @param ReindexRuleProduct|null $reindexRuleProduct
166
164
* @param ReindexRuleGroupWebsite|null $reindexRuleGroupWebsite
167
165
* @param RuleProductsSelectBuilder|null $ruleProductsSelectBuilder
168
166
* @param ReindexRuleProductPrice|null $reindexRuleProductPrice
169
167
* @param RuleProductPricesPersistor|null $pricesPersistor
170
- * @param \Magento\Catalog\Model\ResourceModel\Indexer\ ActiveTableSwitcher|null $activeTableSwitcher
168
+ * @param ActiveTableSwitcher|null $activeTableSwitcher
171
169
* @param ProductLoader|null $productLoader
172
170
* @param TableSwapper|null $tableSwapper
173
171
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
172
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
174
173
*/
175
174
public function __construct (
176
175
RuleCollectionFactory $ ruleCollectionFactory ,
177
176
PriceCurrencyInterface $ priceCurrency ,
178
- \ Magento \ Framework \ App \ ResourceConnection $ resource ,
179
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
180
- \ Psr \ Log \ LoggerInterface $ logger ,
181
- \ Magento \ Eav \ Model \ Config $ eavConfig ,
182
- \ Magento \ Framework \ Stdlib \ DateTime $ dateFormat ,
183
- \ Magento \ Framework \ Stdlib \ DateTime \DateTime $ dateTime ,
184
- \ Magento \ Catalog \ Model \ ProductFactory $ productFactory ,
177
+ ResourceConnection $ resource ,
178
+ StoreManagerInterface $ storeManager ,
179
+ LoggerInterface $ logger ,
180
+ Config $ eavConfig ,
181
+ DateTime $ dateFormat ,
182
+ DateTime \DateTime $ dateTime ,
183
+ ProductFactory $ productFactory ,
185
184
$ batchCount = 1000 ,
186
185
ProductPriceCalculator $ productPriceCalculator = null ,
187
186
ReindexRuleProduct $ reindexRuleProduct = null ,
188
187
ReindexRuleGroupWebsite $ reindexRuleGroupWebsite = null ,
189
188
RuleProductsSelectBuilder $ ruleProductsSelectBuilder = null ,
190
189
ReindexRuleProductPrice $ reindexRuleProductPrice = null ,
191
190
RuleProductPricesPersistor $ pricesPersistor = null ,
192
- \ Magento \ Catalog \ Model \ ResourceModel \ Indexer \ ActiveTableSwitcher $ activeTableSwitcher = null ,
191
+ ActiveTableSwitcher $ activeTableSwitcher = null ,
193
192
ProductLoader $ productLoader = null ,
194
193
TableSwapper $ tableSwapper = null
195
194
) {
@@ -223,12 +222,6 @@ public function __construct(
223
222
$ this ->pricesPersistor = $ pricesPersistor ?? ObjectManager::getInstance ()->get (
224
223
RuleProductPricesPersistor::class
225
224
);
226
- $ this ->activeTableSwitcher = $ activeTableSwitcher ?? ObjectManager::getInstance ()->get (
227
- \Magento \Catalog \Model \ResourceModel \Indexer \ActiveTableSwitcher::class
228
- );
229
- $ this ->productLoader = $ productLoader ?? ObjectManager::getInstance ()->get (
230
- ProductLoader::class
231
- );
232
225
$ this ->tableSwapper = $ tableSwapper ??
233
226
ObjectManager::getInstance ()->get (TableSwapper::class);
234
227
}
@@ -237,6 +230,7 @@ public function __construct(
237
230
* Reindex by id
238
231
*
239
232
* @param int $id
233
+ * @throws LocalizedException
240
234
* @return void
241
235
* @api
242
236
*/
@@ -246,7 +240,7 @@ public function reindexById($id)
246
240
$ this ->doReindexByIds ([$ id ]);
247
241
} catch (\Exception $ e ) {
248
242
$ this ->critical ($ e );
249
- throw new \ Magento \ Framework \ Exception \ LocalizedException (
243
+ throw new LocalizedException (
250
244
__ ("Catalog rule indexing failed. See details in exception log. " )
251
245
);
252
246
}
@@ -256,7 +250,7 @@ public function reindexById($id)
256
250
* Reindex by ids
257
251
*
258
252
* @param array $ids
259
- * @throws \Magento\Framework\Exception\ LocalizedException
253
+ * @throws LocalizedException
260
254
* @return void
261
255
* @api
262
256
*/
@@ -266,7 +260,7 @@ public function reindexByIds(array $ids)
266
260
$ this ->doReindexByIds ($ ids );
267
261
} catch (\Exception $ e ) {
268
262
$ this ->critical ($ e );
269
- throw new \ Magento \ Framework \ Exception \ LocalizedException (
263
+ throw new LocalizedException (
270
264
__ ("Catalog rule indexing failed. See details in exception log. " )
271
265
);
272
266
}
@@ -300,7 +294,7 @@ protected function doReindexByIds($ids)
300
294
/**
301
295
* Full reindex
302
296
*
303
- * @throws \Magento\Framework\Exception\ LocalizedException
297
+ * @throws LocalizedException
304
298
* @return void
305
299
* @api
306
300
*/
@@ -310,7 +304,7 @@ public function reindexFull()
310
304
$ this ->doReindexFull ();
311
305
} catch (\Exception $ e ) {
312
306
$ this ->critical ($ e );
313
- throw new \ Magento \ Framework \ Exception \ LocalizedException (
307
+ throw new LocalizedException (
314
308
__ ("Catalog rule indexing failed. See details in exception log. " )
315
309
);
316
310
}
@@ -375,65 +369,6 @@ protected function cleanByIds($productIds)
375
369
$ this ->cleanProductPriceIndex ($ productIds );
376
370
}
377
371
378
- /**
379
- * Assign product to rule
380
- *
381
- * @param Rule $rule
382
- * @param int $productEntityId
383
- * @param array $websiteIds
384
- * @return void
385
- * @throws \Exception
386
- * @deprecated
387
- * @see ReindexRuleProduct::execute
388
- */
389
- private function assignProductToRule (Rule $ rule , int $ productEntityId , array $ websiteIds ): void
390
- {
391
- $ ruleId = (int ) $ rule ->getId ();
392
- $ ruleProductTable = $ this ->getTable ('catalogrule_product ' );
393
- $ this ->connection ->delete (
394
- $ ruleProductTable ,
395
- [
396
- 'rule_id = ? ' => $ ruleId ,
397
- 'product_id = ? ' => $ productEntityId ,
398
- ]
399
- );
400
-
401
- $ customerGroupIds = $ rule ->getCustomerGroupIds ();
402
- $ fromTime = strtotime ($ rule ->getFromDate ());
403
- $ toTime = strtotime ($ rule ->getToDate ());
404
- $ toTime = $ toTime ? $ toTime + self ::SECONDS_IN_DAY - 1 : 0 ;
405
- $ sortOrder = (int )$ rule ->getSortOrder ();
406
- $ actionOperator = $ rule ->getSimpleAction ();
407
- $ actionAmount = $ rule ->getDiscountAmount ();
408
- $ actionStop = $ rule ->getStopRulesProcessing ();
409
-
410
- $ rows = [];
411
- foreach ($ websiteIds as $ websiteId ) {
412
- foreach ($ customerGroupIds as $ customerGroupId ) {
413
- $ rows [] = [
414
- 'rule_id ' => $ ruleId ,
415
- 'from_time ' => $ fromTime ,
416
- 'to_time ' => $ toTime ,
417
- 'website_id ' => $ websiteId ,
418
- 'customer_group_id ' => $ customerGroupId ,
419
- 'product_id ' => $ productEntityId ,
420
- 'action_operator ' => $ actionOperator ,
421
- 'action_amount ' => $ actionAmount ,
422
- 'action_stop ' => $ actionStop ,
423
- 'sort_order ' => $ sortOrder ,
424
- ];
425
-
426
- if (count ($ rows ) == $ this ->batchCount ) {
427
- $ this ->connection ->insertMultiple ($ ruleProductTable , $ rows );
428
- $ rows = [];
429
- }
430
- }
431
- }
432
- if ($ rows ) {
433
- $ this ->connection ->insertMultiple ($ ruleProductTable , $ rows );
434
- }
435
- }
436
-
437
372
/**
438
373
* Apply rule
439
374
*
@@ -457,30 +392,6 @@ protected function applyRule(Rule $rule, $product)
457
392
return $ this ;
458
393
}
459
394
460
- /**
461
- * Apply rules
462
- *
463
- * @param RuleCollection $ruleCollection
464
- * @param Product $product
465
- * @deprecated
466
- * @see ReindexRuleProduct::execute
467
- * @return void
468
- */
469
- private function applyRules (RuleCollection $ ruleCollection , Product $ product ): void
470
- {
471
- foreach ($ ruleCollection as $ rule ) {
472
- if (!$ rule ->validate ($ product )) {
473
- continue ;
474
- }
475
-
476
- $ websiteIds = array_intersect ($ product ->getWebsiteIds (), $ rule ->getWebsiteIds ());
477
- $ this ->assignProductToRule ($ rule , $ product ->getId (), $ websiteIds );
478
- }
479
-
480
- $ this ->cleanProductPriceIndex ([$ product ->getId ()]);
481
- $ this ->reindexRuleProductPrice ->execute ($ this ->batchCount , $ product ->getId ());
482
- }
483
-
484
395
/**
485
396
* Retrieve table name
486
397
*
@@ -580,7 +491,7 @@ protected function calcRuleProductPrice($ruleData, $productData = null)
580
491
* @param int $websiteId
581
492
* @param Product|null $product
582
493
* @return \Zend_Db_Statement_Interface
583
- * @throws \Magento\Framework\Exception\ LocalizedException
494
+ * @throws LocalizedException
584
495
* @deprecated 100.2.0
585
496
* @see RuleProductsSelectBuilder::build
586
497
*/
0 commit comments