77
88use Magento \Catalog \Api \ProductRepositoryInterface ;
99use Magento \Catalog \Model \Indexer \Product \Price \Processor ;
10+ use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
11+ use Magento \CatalogRule \Model \Indexer \Rule \RuleProductProcessor ;
1012use Magento \Framework \App \ResourceConnection ;
13+ use Magento \Framework \App \Area ;
1114use Magento \Store \Model \StoreManagerInterface ;
1215use Magento \TestFramework \Fixture \AppIsolation ;
1316use Magento \TestFramework \Fixture \DataFixture ;
1417use Magento \TestFramework \Fixture \DbIsolation ;
18+ use Magento \TestFramework \Fixture \AppArea ;
1519use Magento \TestFramework \Helper \Bootstrap ;
1620
1721#[
@@ -65,6 +69,16 @@ class IndexerBuilderTest extends \PHPUnit\Framework\TestCase
6569 */
6670 private $ indexProductProcessor ;
6771
72+ /**
73+ * @var RuleProductProcessor
74+ */
75+ private $ ruleProductProcessor ;
76+
77+ /**
78+ * @var CollectionFactory
79+ */
80+ private $ productCollectionFactory ;
81+
6882 protected function setUp (): void
6983 {
7084 $ this ->indexerBuilder = Bootstrap::getObjectManager ()->get (
@@ -76,6 +90,8 @@ protected function setUp(): void
7690 $ this ->productRepository = Bootstrap::getObjectManager ()->get (ProductRepositoryInterface::class);
7791 $ this ->connection = Bootstrap::getObjectManager ()->get (ResourceConnection::class);
7892 $ this ->indexProductProcessor = Bootstrap::getObjectManager ()->get (Processor::class);
93+ $ this ->ruleProductProcessor = Bootstrap::getObjectManager ()->get (RuleProductProcessor::class);
94+ $ this ->productCollectionFactory = Bootstrap::getObjectManager ()->get (CollectionFactory::class);
7995 }
8096
8197 protected function tearDown (): void
@@ -251,7 +267,7 @@ private function getTriggersCount(string $tableName): int
251267 {
252268 return count (
253269 $ this ->connection ->getConnection ()
254- ->query ('SHOW TRIGGERS LIKE \'' . $ tableName . '\'' )
270+ ->query ('SHOW TRIGGERS LIKE \'' . $ tableName . '\'' )
255271 ->fetchAll ()
256272 );
257273 }
@@ -271,4 +287,38 @@ protected function prepareProducts()
271287 ->setData ('test_attribute ' , 'NO_test_attribute_value ' )
272288 ->save ();
273289 }
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+ }
274324}
0 commit comments