6
6
namespace Magento \ConfigurableProduct \Model \ResourceModel \Product \Indexer \Price ;
7
7
8
8
use Magento \Catalog \Api \ProductRepositoryInterface ;
9
+ use Magento \Catalog \Model \Indexer \Product \Price \Processor as PriceIndexerProcessor ;
9
10
use Magento \Catalog \Model \Product \Attribute \Source \Status ;
10
11
use Magento \Catalog \Model \ResourceModel \Product \Collection ;
11
12
use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
18
19
use Magento \Catalog \Api \Data \ProductInterface ;
19
20
20
21
/**
21
- * Configurable test
22
+ * Test reindex of configurable products
22
23
*
23
24
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24
25
* @magentoAppArea adminhtml
@@ -64,7 +65,7 @@ protected function setUp(): void
64
65
*/
65
66
public function testGetProductFinalPriceIfOneOfChildIsDisabled (): void
66
67
{
67
- $ configurableProduct = $ this ->getConfigurableProductFromCollection ();
68
+ $ configurableProduct = $ this ->getConfigurableProductFromCollection (1 );
68
69
$ this ->assertEquals (10 , $ configurableProduct ->getMinimalPrice ());
69
70
70
71
$ childProduct = $ this ->productRepository ->getById (10 , false , null , true );
@@ -75,7 +76,7 @@ public function testGetProductFinalPriceIfOneOfChildIsDisabled(): void
75
76
$ this ->productRepository ->save ($ childProduct );
76
77
$ this ->storeManager ->setCurrentStore ($ currentStoreId );
77
78
78
- $ configurableProduct = $ this ->getConfigurableProductFromCollection ();
79
+ $ configurableProduct = $ this ->getConfigurableProductFromCollection (1 );
79
80
$ this ->assertEquals (20 , $ configurableProduct ->getMinimalPrice ());
80
81
}
81
82
@@ -93,7 +94,7 @@ public function testGetProductFinalPriceIfOneOfChildIsDisabled(): void
93
94
*/
94
95
public function testGetProductFinalPriceIfOneOfChildIsDisabledPerStore (): void
95
96
{
96
- $ configurableProduct = $ this ->getConfigurableProductFromCollection ();
97
+ $ configurableProduct = $ this ->getConfigurableProductFromCollection (1 );
97
98
$ this ->assertEquals (10 , $ configurableProduct ->getMinimalPrice ());
98
99
99
100
$ childProduct = $ this ->productRepository ->get ('simple_10 ' , false , null , true );
@@ -106,7 +107,7 @@ public function testGetProductFinalPriceIfOneOfChildIsDisabledPerStore(): void
106
107
$ this ->productRepository ->save ($ childProduct );
107
108
$ this ->storeManager ->setCurrentStore ($ currentStoreId );
108
109
109
- $ configurableProduct = $ this ->getConfigurableProductFromCollection ();
110
+ $ configurableProduct = $ this ->getConfigurableProductFromCollection (1 );
110
111
$ this ->assertEquals (20 , $ configurableProduct ->getMinimalPrice ());
111
112
}
112
113
@@ -122,33 +123,56 @@ public function testGetProductFinalPriceIfOneOfChildIsDisabledPerStore(): void
122
123
*/
123
124
public function testGetProductMinimalPriceIfOneOfChildIsOutOfStock (): void
124
125
{
125
- $ configurableProduct = $ this ->getConfigurableProductFromCollection ();
126
+ $ configurableProduct = $ this ->getConfigurableProductFromCollection (1 );
126
127
$ this ->assertEquals (10 , $ configurableProduct ->getMinimalPrice ());
127
128
128
129
$ childProduct = $ this ->productRepository ->getById (10 , false , null , true );
129
130
$ stockItem = $ childProduct ->getExtensionAttributes ()->getStockItem ();
130
131
$ stockItem ->setIsInStock (Stock::STOCK_OUT_OF_STOCK );
131
132
$ this ->stockRepository ->save ($ stockItem );
132
133
133
- $ configurableProduct = $ this ->getConfigurableProductFromCollection ();
134
+ $ configurableProduct = $ this ->getConfigurableProductFromCollection (1 );
134
135
$ this ->assertEquals (20 , $ configurableProduct ->getMinimalPrice ());
135
136
}
136
137
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
+
137
160
/**
138
161
* Retrieve configurable product.
139
162
* Returns Configurable product that was created by Magento/ConfigurableProduct/_files/product_configurable.php
140
163
* fixture
141
164
*
165
+ * @param int $productId
142
166
* @return ProductInterface
143
167
*/
144
- private function getConfigurableProductFromCollection (): ProductInterface
168
+ private function getConfigurableProductFromCollection (int $ productId ): ProductInterface
145
169
{
146
170
/** @var Collection $collection */
147
171
$ collection = Bootstrap::getObjectManager ()->get (CollectionFactory::class)
148
172
->create ();
149
173
/** @var ProductInterface $configurableProduct */
150
174
$ configurableProduct = $ collection
151
- ->addIdFilter ([1 ])
175
+ ->addIdFilter ([$ productId ])
152
176
->addMinimalPrice ()
153
177
->load ()
154
178
->getFirstItem ();
0 commit comments