66namespace Magento \ConfigurableProduct \Model \ResourceModel \Product \Indexer \Price ;
77
88use Magento \Catalog \Api \ProductRepositoryInterface ;
9+ use Magento \Catalog \Model \Indexer \Product \Price \Processor as PriceIndexerProcessor ;
910use Magento \Catalog \Model \Product \Attribute \Source \Status ;
1011use Magento \Catalog \Model \ResourceModel \Product \Collection ;
1112use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
1819use Magento \Catalog \Api \Data \ProductInterface ;
1920
2021/**
21- * Configurable test
22+ * Test reindex of configurable products
2223 *
2324 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2425 * @magentoAppArea adminhtml
@@ -64,7 +65,7 @@ protected function setUp(): void
6465 */
6566 public function testGetProductFinalPriceIfOneOfChildIsDisabled (): void
6667 {
67- $ configurableProduct = $ this ->getConfigurableProductFromCollection ();
68+ $ configurableProduct = $ this ->getConfigurableProductFromCollection (1 );
6869 $ this ->assertEquals (10 , $ configurableProduct ->getMinimalPrice ());
6970
7071 $ childProduct = $ this ->productRepository ->getById (10 , false , null , true );
@@ -75,7 +76,7 @@ public function testGetProductFinalPriceIfOneOfChildIsDisabled(): void
7576 $ this ->productRepository ->save ($ childProduct );
7677 $ this ->storeManager ->setCurrentStore ($ currentStoreId );
7778
78- $ configurableProduct = $ this ->getConfigurableProductFromCollection ();
79+ $ configurableProduct = $ this ->getConfigurableProductFromCollection (1 );
7980 $ this ->assertEquals (20 , $ configurableProduct ->getMinimalPrice ());
8081 }
8182
@@ -93,7 +94,7 @@ public function testGetProductFinalPriceIfOneOfChildIsDisabled(): void
9394 */
9495 public function testGetProductFinalPriceIfOneOfChildIsDisabledPerStore (): void
9596 {
96- $ configurableProduct = $ this ->getConfigurableProductFromCollection ();
97+ $ configurableProduct = $ this ->getConfigurableProductFromCollection (1 );
9798 $ this ->assertEquals (10 , $ configurableProduct ->getMinimalPrice ());
9899
99100 $ childProduct = $ this ->productRepository ->get ('simple_10 ' , false , null , true );
@@ -106,7 +107,7 @@ public function testGetProductFinalPriceIfOneOfChildIsDisabledPerStore(): void
106107 $ this ->productRepository ->save ($ childProduct );
107108 $ this ->storeManager ->setCurrentStore ($ currentStoreId );
108109
109- $ configurableProduct = $ this ->getConfigurableProductFromCollection ();
110+ $ configurableProduct = $ this ->getConfigurableProductFromCollection (1 );
110111 $ this ->assertEquals (20 , $ configurableProduct ->getMinimalPrice ());
111112 }
112113
@@ -122,33 +123,56 @@ public function testGetProductFinalPriceIfOneOfChildIsDisabledPerStore(): void
122123 */
123124 public function testGetProductMinimalPriceIfOneOfChildIsOutOfStock (): void
124125 {
125- $ configurableProduct = $ this ->getConfigurableProductFromCollection ();
126+ $ configurableProduct = $ this ->getConfigurableProductFromCollection (1 );
126127 $ this ->assertEquals (10 , $ configurableProduct ->getMinimalPrice ());
127128
128129 $ childProduct = $ this ->productRepository ->getById (10 , false , null , true );
129130 $ stockItem = $ childProduct ->getExtensionAttributes ()->getStockItem ();
130131 $ stockItem ->setIsInStock (Stock::STOCK_OUT_OF_STOCK );
131132 $ this ->stockRepository ->save ($ stockItem );
132133
133- $ configurableProduct = $ this ->getConfigurableProductFromCollection ();
134+ $ configurableProduct = $ this ->getConfigurableProductFromCollection (1 );
134135 $ this ->assertEquals (20 , $ configurableProduct ->getMinimalPrice ());
135136 }
136137
138+ /**
139+ * @magentoDataFixture Magento/Catalog/_files/enable_price_index_schedule.php
140+ * @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable_with_assigned_simples.php
141+ * @magentoDbIsolation disabled
142+ *
143+ * @return void
144+ */
145+ public function testReindexWithCorrectPriority ()
146+ {
147+ $ configurableProduct = $ this ->productRepository ->get ('configurable ' );
148+ $ childProduct1 = $ this ->productRepository ->get ('simple_1 ' );
149+ $ childProduct2 = $ this ->productRepository ->get ('simple_2 ' );
150+ $ priceIndexerProcessor = Bootstrap::getObjectManager ()->get (PriceIndexerProcessor::class);
151+ $ priceIndexerProcessor ->reindexList (
152+ [$ configurableProduct ->getId (), $ childProduct1 ->getId (), $ childProduct2 ->getId ()],
153+ true
154+ );
155+
156+ $ configurableProduct = $ this ->getConfigurableProductFromCollection ($ configurableProduct ->getId ());
157+ $ this ->assertEquals ($ childProduct1 ->getPrice (), $ configurableProduct ->getMinimalPrice ());
158+ }
159+
137160 /**
138161 * Retrieve configurable product.
139162 * Returns Configurable product that was created by Magento/ConfigurableProduct/_files/product_configurable.php
140163 * fixture
141164 *
165+ * @param int $productId
142166 * @return ProductInterface
143167 */
144- private function getConfigurableProductFromCollection (): ProductInterface
168+ private function getConfigurableProductFromCollection (int $ productId ): ProductInterface
145169 {
146170 /** @var Collection $collection */
147171 $ collection = Bootstrap::getObjectManager ()->get (CollectionFactory::class)
148172 ->create ();
149173 /** @var ProductInterface $configurableProduct */
150174 $ configurableProduct = $ collection
151- ->addIdFilter ([1 ])
175+ ->addIdFilter ([$ productId ])
152176 ->addMinimalPrice ()
153177 ->load ()
154178 ->getFirstItem ();
0 commit comments