7
7
8
8
use Magento \Catalog \Api \ProductRepositoryInterface ;
9
9
use Magento \Catalog \Model \Indexer \Product \Price \Processor ;
10
+ use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
11
+ use Magento \CatalogRule \Model \Indexer \Rule \RuleProductProcessor ;
10
12
use Magento \Framework \App \ResourceConnection ;
13
+ use Magento \Framework \App \Area ;
11
14
use Magento \Store \Model \StoreManagerInterface ;
12
15
use Magento \TestFramework \Fixture \AppIsolation ;
13
16
use Magento \TestFramework \Fixture \DataFixture ;
14
17
use Magento \TestFramework \Fixture \DbIsolation ;
18
+ use Magento \TestFramework \Fixture \AppArea ;
15
19
use Magento \TestFramework \Helper \Bootstrap ;
16
20
17
21
#[
@@ -65,6 +69,16 @@ class IndexerBuilderTest extends \PHPUnit\Framework\TestCase
65
69
*/
66
70
private $ indexProductProcessor ;
67
71
72
+ /**
73
+ * @var RuleProductProcessor
74
+ */
75
+ private $ ruleProductProcessor ;
76
+
77
+ /**
78
+ * @var CollectionFactory
79
+ */
80
+ private $ productCollectionFactory ;
81
+
68
82
protected function setUp (): void
69
83
{
70
84
$ this ->indexerBuilder = Bootstrap::getObjectManager ()->get (
@@ -76,6 +90,8 @@ protected function setUp(): void
76
90
$ this ->productRepository = Bootstrap::getObjectManager ()->get (ProductRepositoryInterface::class);
77
91
$ this ->connection = Bootstrap::getObjectManager ()->get (ResourceConnection::class);
78
92
$ this ->indexProductProcessor = Bootstrap::getObjectManager ()->get (Processor::class);
93
+ $ this ->ruleProductProcessor = Bootstrap::getObjectManager ()->get (RuleProductProcessor::class);
94
+ $ this ->productCollectionFactory = Bootstrap::getObjectManager ()->get (CollectionFactory::class);
79
95
}
80
96
81
97
protected function tearDown (): void
@@ -251,7 +267,7 @@ private function getTriggersCount(string $tableName): int
251
267
{
252
268
return count (
253
269
$ this ->connection ->getConnection ()
254
- ->query ('SHOW TRIGGERS LIKE \'' . $ tableName . '\'' )
270
+ ->query ('SHOW TRIGGERS LIKE \'' . $ tableName . '\'' )
255
271
->fetchAll ()
256
272
);
257
273
}
@@ -271,4 +287,38 @@ protected function prepareProducts()
271
287
->setData ('test_attribute ' , 'NO_test_attribute_value ' )
272
288
->save ();
273
289
}
290
+
291
+ #[
292
+ AppArea(Area::AREA_FRONTEND ),
293
+ DataFixture('Magento/CatalogRule/_files/simple_product_with_catalog_rule_50_percent_off.php ' ),
294
+ DataFixture('Magento/CatalogRule/_files/set_indexer_to_scheduled_mode.php ' ),
295
+ ]
296
+ public function testReindexOfDependentIndexer (): void
297
+ {
298
+ $ productId = $ this ->productRepository ->get ('simple ' )->getId ();
299
+
300
+ $ productCollection = $ this ->productCollectionFactory ->create ();
301
+ $ productCollection ->addIdFilter ($ productId );
302
+ //$productCollection->addPriceData();
303
+ $ productCollection ->load ();
304
+ echo (string )$ productCollection ->getSelect ();
305
+ $ product = $ productCollection ->getFirstItem ();
306
+ echo "\n\n" . $ product ->getId () . '= ' ;
307
+ //$product = $productCollection->getItemByColumnValue('sku', 'simple');
308
+ //$product = $this->productRepository->get('simple');
309
+ //print_r($product->getPriceInfo());
310
+ echo $ product ->getFinalPrice ();
311
+ echo ' * ' ;
312
+ $ product ->setPrice (500 );
313
+ $ this ->productRepository ->save ($ product );
314
+ $ product = $ this ->productRepository ->get ('simple ' );
315
+ echo $ product ->getPriceInfo ()->getPrice ('final_price ' )->getAmount ()->getValue ();
316
+ $ product ->setPrice (50 );
317
+ $ this ->productRepository ->save ($ product );
318
+
319
+ $ this ->indexProductProcessor ->getIndexer ()->setScheduled (false );
320
+ $ this ->ruleProductProcessor ->getIndexer ()->setScheduled (false );
321
+
322
+ $ this ->indexerBuilder ->reindexFull ();
323
+ }
274
324
}
0 commit comments