13
13
use Magento \ConfigurableProduct \Model \Product \Type \Configurable \Price ;
14
14
use Magento \Customer \Model \Group ;
15
15
use Magento \Framework \ObjectManagerInterface ;
16
- use Magento \TestFramework \Catalog \Model \Product \Price \GetDataFromIndexTable ;
16
+ use Magento \Store \Api \WebsiteRepositoryInterface ;
17
+ use Magento \TestFramework \Catalog \Model \Product \Price \GetPriceIndexDataByProductId ;
17
18
use Magento \TestFramework \Helper \Bootstrap ;
18
19
use PHPUnit \Framework \TestCase ;
19
20
@@ -30,6 +31,11 @@ class PriceTest extends TestCase
30
31
*/
31
32
private $ objectManager ;
32
33
34
+ /**
35
+ * @var WebsiteRepositoryInterface
36
+ */
37
+ private $ websiteRepository ;
38
+
33
39
/**
34
40
* @var ProductRepositoryInterface
35
41
*/
@@ -41,14 +47,9 @@ class PriceTest extends TestCase
41
47
private $ priceModel ;
42
48
43
49
/**
44
- * @var GetDataFromIndexTable
45
- */
46
- private $ getDataFromIndexTable ;
47
-
48
- /**
49
- * @var array
50
+ * @var GetPriceIndexDataByProductId
50
51
*/
51
- private $ priceIndexFields = [ ' price ' , ' final_price ' , ' min_price ' , ' max_price ' , ' tier_price ' ] ;
52
+ private $ getPriceIndexDataByProductId ;
52
53
53
54
/**
54
55
* @inheritdoc
@@ -57,9 +58,10 @@ protected function setUp()
57
58
{
58
59
$ this ->objectManager = Bootstrap::getObjectManager ();
59
60
$ this ->priceModel = $ this ->objectManager ->create (Price::class);
61
+ $ this ->websiteRepository = $ this ->objectManager ->get (WebsiteRepositoryInterface::class);
60
62
$ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
61
63
$ this ->productRepository ->cleanCache ();
62
- $ this ->getDataFromIndexTable = $ this ->objectManager ->get (GetDataFromIndexTable ::class);
64
+ $ this ->getPriceIndexDataByProductId = $ this ->objectManager ->get (GetPriceIndexDataByProductId ::class);
63
65
}
64
66
65
67
/**
@@ -69,9 +71,27 @@ protected function setUp()
69
71
public function testGetFinalPriceWithCustomOptionAndCatalogRule (): void
70
72
{
71
73
$ indexPrices = [
72
- 'simple_10 ' => [10 , 9 , 9 , 9 , null ],
73
- 'simple_20 ' => [20 , 15 , 15 , 15 , 15 ],
74
- 'configurable ' => [0 , 0 , 9 , 30 , 15 ],
74
+ 'simple_10 ' => [
75
+ 'price ' => 10 ,
76
+ 'final_price ' => 9 ,
77
+ 'min_price ' => 9 ,
78
+ 'max_price ' => 9 ,
79
+ 'tier_price ' => null
80
+ ],
81
+ 'simple_20 ' => [
82
+ 'price ' => 20 ,
83
+ 'final_price ' => 15 ,
84
+ 'min_price ' => 15 ,
85
+ 'max_price ' => 15 ,
86
+ 'tier_price ' => 15
87
+ ],
88
+ 'configurable ' => [
89
+ 'price ' => 0 ,
90
+ 'final_price ' => 0 ,
91
+ 'min_price ' => 9 ,
92
+ 'max_price ' => 30 ,
93
+ 'tier_price ' => 15
94
+ ],
75
95
];
76
96
$ this ->assertConfigurableProductPrice (20 , 25 , $ indexPrices );
77
97
}
@@ -83,9 +103,27 @@ public function testGetFinalPriceWithCustomOptionAndCatalogRule(): void
83
103
public function testGetFinalPriceWithCustomOptionAndCatalogRulesForChildren (): void
84
104
{
85
105
$ indexPrices = [
86
- 'simple_10 ' => [10 , 4.5 , 4.5 , 9 , null ],
87
- 'simple_20 ' => [20 , 8 , 8 , 15 , 15 ],
88
- 'configurable ' => [0 , 0 , 4.5 , 23 , 15 ],
106
+ 'simple_10 ' => [
107
+ 'price ' => 10 ,
108
+ 'final_price ' => 4.5 ,
109
+ 'min_price ' => 4.5 ,
110
+ 'max_price ' => 9 ,
111
+ 'tier_price ' => null
112
+ ],
113
+ 'simple_20 ' => [
114
+ 'price ' => 20 ,
115
+ 'final_price ' => 8 ,
116
+ 'min_price ' => 8 ,
117
+ 'max_price ' => 15 ,
118
+ 'tier_price ' => 15
119
+ ],
120
+ 'configurable ' => [
121
+ 'price ' => 0 ,
122
+ 'final_price ' => 0 ,
123
+ 'min_price ' => 4.5 ,
124
+ 'max_price ' => 23 ,
125
+ 'tier_price ' => 15
126
+ ],
89
127
];
90
128
$ this ->assertConfigurableProductPrice (19.5 , 23 , $ indexPrices );
91
129
}
@@ -104,28 +142,28 @@ private function assertConfigurableProductPrice(
104
142
array $ indexPrices
105
143
): void {
106
144
foreach ($ indexPrices as $ sku => $ prices ) {
107
- $ this ->assertIndexTableData ($ sku , array_combine ( $ this -> priceIndexFields , $ prices) );
145
+ $ this ->assertIndexTableData ($ sku , $ prices );
108
146
}
109
147
$ configurable = $ this ->productRepository ->get ('configurable ' );
110
148
//Add tier price option
111
149
$ optionId = $ configurable ->getOptions ()[0 ]->getId ();
112
150
$ configurable ->addCustomOption (AbstractType::OPTION_PREFIX . $ optionId , 'text ' );
113
151
$ configurable ->addCustomOption ('option_ids ' , $ optionId );
114
152
//First simple rule price + Option price
115
- $ this ->assertFinalPrice ($ priceWithFirstSimple , $ configurable );
153
+ $ this ->assertFinalPrice ($ configurable , $ priceWithFirstSimple );
116
154
$ configurable ->addCustomOption ('simple_product ' , 20 , $ this ->productRepository ->get ('simple_20 ' ));
117
155
//Second simple rule price + Option price
118
- $ this ->assertFinalPrice ($ priceWithSecondSimple , $ configurable );
156
+ $ this ->assertFinalPrice ($ configurable , $ priceWithSecondSimple );
119
157
}
120
158
121
159
/**
122
160
* Asserts product final price.
123
161
*
124
- * @param float $expectedPrice
125
162
* @param ProductInterface $product
163
+ * @param float $expectedPrice
126
164
* @return void
127
165
*/
128
- private function assertFinalPrice (float $ expectedPrice , ProductInterface $ product ): void
166
+ private function assertFinalPrice (ProductInterface $ product , float $ expectedPrice ): void
129
167
{
130
168
$ this ->assertEquals (
131
169
round ($ expectedPrice , 2 ),
@@ -142,9 +180,10 @@ private function assertFinalPrice(float $expectedPrice, ProductInterface $produc
142
180
*/
143
181
private function assertIndexTableData (string $ sku , array $ expectedPrices ): void
144
182
{
145
- $ data = $ this ->getDataFromIndexTable ->execute (
183
+ $ data = $ this ->getPriceIndexDataByProductId ->execute (
146
184
(int )$ this ->productRepository ->get ($ sku )->getId (),
147
- Group::NOT_LOGGED_IN_ID
185
+ Group::NOT_LOGGED_IN_ID ,
186
+ (int )$ this ->websiteRepository ->get ('base ' )->getId ()
148
187
);
149
188
$ data = reset ($ data );
150
189
foreach ($ expectedPrices as $ column => $ price ) {
0 commit comments