7
7
8
8
namespace Magento \Bundle \Block \Catalog \Product \View \Type ;
9
9
10
+ use Magento \Bundle \Pricing \Price \BundleOptions ;
10
11
use Magento \Catalog \Api \ProductRepositoryInterface ;
11
12
use Magento \Framework \ObjectManagerInterface ;
12
13
use Magento \Framework \Registry ;
13
14
use Magento \Framework \Serialize \SerializerInterface ;
14
- use Magento \Framework \View \LayoutInterface ;
15
+ use Magento \Framework \View \Result \Page ;
16
+ use Magento \Framework \View \Result \PageFactory ;
17
+ use Magento \Store \Model \StoreManagerInterface ;
15
18
use Magento \TestFramework \Helper \Bootstrap ;
19
+ use Magento \TestFramework \Store \ExecuteInStoreContext ;
16
20
use PHPUnit \Framework \TestCase ;
17
21
18
22
/**
@@ -36,8 +40,14 @@ class BundleProductPriceTest extends TestCase
36
40
/** @var SerializerInterface */
37
41
private $ json ;
38
42
39
- /** @var Bundle */
40
- private $ block ;
43
+ /** @var ExecuteInStoreContext */
44
+ private $ executeInStoreContext ;
45
+
46
+ /** @var StoreManagerInterface */
47
+ private $ storeManager ;
48
+
49
+ /** @var PageFactory */
50
+ private $ pageFactory ;
41
51
42
52
/**
43
53
* @inheritdoc
@@ -49,9 +59,11 @@ protected function setUp()
49
59
$ this ->objectManager = Bootstrap::getObjectManager ();
50
60
$ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
51
61
$ this ->productRepository ->cleanCache ();
52
- $ this ->block = $ this ->objectManager ->get (LayoutInterface::class)->createBlock (Bundle::class);
53
62
$ this ->registry = $ this ->objectManager ->get (Registry::class);
54
63
$ this ->json = $ this ->objectManager ->get (SerializerInterface::class);
64
+ $ this ->executeInStoreContext = $ this ->objectManager ->get (ExecuteInStoreContext::class);
65
+ $ this ->storeManager = $ this ->objectManager ->get (StoreManagerInterface::class);
66
+ $ this ->pageFactory = $ this ->objectManager ->get (PageFactory::class);
55
67
}
56
68
57
69
/**
@@ -98,6 +110,63 @@ public function testDynamicBundleOptionPrices(): void
98
110
$ this ->processBundlePriceView ('bundle_product ' , $ expectedData );
99
111
}
100
112
113
+ /**
114
+ * @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_on_second_website.php
115
+ * @magentoDbIsolation disabled
116
+ * @magentoAppIsolation enabled
117
+ *
118
+ * @return void
119
+ */
120
+ public function testDynamicBundleOptionPricesOnSecondWebsite (): void
121
+ {
122
+ $ this ->executeInStoreContext ->execute (
123
+ 'fixture_second_store ' ,
124
+ [$ this , 'processBundlePriceView ' ],
125
+ 'dynamic_bundle_product_with_special_price ' ,
126
+ [
127
+ 'options_prices ' => [
128
+ [
129
+ 'oldPrice ' => ['amount ' => 20 ],
130
+ 'basePrice ' => ['amount ' => 7.5 ],
131
+ 'finalPrice ' => ['amount ' => 7.5 ],
132
+ ],
133
+ [
134
+ 'oldPrice ' => ['amount ' => 40 ],
135
+ 'basePrice ' => ['amount ' => 22.5 ],
136
+ 'finalPrice ' => ['amount ' => 22.5 ],
137
+ ],
138
+ ],
139
+ 'bundle_prices ' => [
140
+ 'oldPrice ' => ['amount ' => 0 ],
141
+ 'basePrice ' => ['amount ' => 0 ],
142
+ 'finalPrice ' => ['amount ' => 0 ],
143
+ ]
144
+ ]
145
+ );
146
+ $ this ->processBundlePriceView (
147
+ 'dynamic_bundle_product_with_special_price ' ,
148
+ [
149
+ 'options_prices ' => [
150
+ [
151
+ 'oldPrice ' => ['amount ' => 10 ],
152
+ 'basePrice ' => ['amount ' => 7.5 ],
153
+ 'finalPrice ' => ['amount ' => 7.5 ],
154
+ ],
155
+ [
156
+ 'oldPrice ' => ['amount ' => 20 ],
157
+ 'basePrice ' => ['amount ' => 15 ],
158
+ 'finalPrice ' => ['amount ' => 15 ],
159
+ ],
160
+ ],
161
+ 'bundle_prices ' => [
162
+ 'oldPrice ' => ['amount ' => 0 ],
163
+ 'basePrice ' => ['amount ' => 0 ],
164
+ 'finalPrice ' => ['amount ' => 0 ],
165
+ ]
166
+ ]
167
+ );
168
+ }
169
+
101
170
/**
102
171
* @magentoDataFixture Magento/Bundle/_files/product_with_multiple_options_1.php
103
172
*
@@ -128,14 +197,93 @@ public function testFixedBundleOptionPrices(): void
128
197
}
129
198
130
199
/**
200
+ * @magentoDataFixture Magento/Bundle/_files/fixed_bundle_product_on_second_website.php
201
+ * @magentoDbIsolation disabled
202
+ * @magentoAppIsolation enabled
203
+ *
204
+ * @return void
205
+ */
206
+ public function testFixedBundleOptionPricesOnSecondWebsite (): void
207
+ {
208
+ $ this ->executeInStoreContext ->execute (
209
+ 'fixture_second_store ' ,
210
+ [$ this , 'processBundlePriceView ' ],
211
+ 'fixed_bundle_product_with_special_price ' ,
212
+ [
213
+ 'options_prices ' => [
214
+ [
215
+ 'oldPrice ' => ['amount ' => 10 ],
216
+ 'basePrice ' => ['amount ' => 3 ],
217
+ 'finalPrice ' => ['amount ' => 3 ],
218
+ ],
219
+ [
220
+ 'oldPrice ' => ['amount ' => 10 ],
221
+ 'basePrice ' => ['amount ' => 3 ],
222
+ 'finalPrice ' => ['amount ' => 3 ],
223
+ ],
224
+ [
225
+ 'oldPrice ' => ['amount ' => 25 ],
226
+ 'basePrice ' => ['amount ' => 7.5 ],
227
+ 'finalPrice ' => ['amount ' => 7.5 ],
228
+ ],
229
+ ],
230
+ 'bundle_prices ' => [
231
+ 'oldPrice ' => ['amount ' => 50 ],
232
+ 'basePrice ' => ['amount ' => 30 ],
233
+ 'finalPrice ' => ['amount ' => 30 ],
234
+ ]
235
+ ]
236
+ );
237
+ $ this ->processBundlePriceView (
238
+ 'fixed_bundle_product_with_special_price ' ,
239
+ [
240
+ 'options_prices ' => [
241
+ [
242
+ 'oldPrice ' => ['amount ' => 10 ],
243
+ 'basePrice ' => ['amount ' => 8 ],
244
+ 'finalPrice ' => ['amount ' => 8 ],
245
+ ],
246
+ [
247
+ 'oldPrice ' => ['amount ' => 12.5 ],
248
+ 'basePrice ' => ['amount ' => 10 ],
249
+ 'finalPrice ' => ['amount ' => 10 ],
250
+ ],
251
+ [
252
+ 'oldPrice ' => ['amount ' => 25 ],
253
+ 'basePrice ' => ['amount ' => 20 ],
254
+ 'finalPrice ' => ['amount ' => 20 ],
255
+ ],
256
+ ],
257
+ 'bundle_prices ' => [
258
+ 'oldPrice ' => ['amount ' => 60 ],
259
+ 'basePrice ' => ['amount ' => 50 ],
260
+ 'finalPrice ' => ['amount ' => 50 ],
261
+ ]
262
+ ]
263
+ );
264
+ }
265
+
266
+ /**
267
+ * Asserts bundle product prices from price block.
268
+ *
131
269
* @param string $productSku
132
270
* @param array $expectedData
133
271
* @return void
134
272
*/
135
- private function processBundlePriceView (string $ productSku , array $ expectedData ): void
273
+ public function processBundlePriceView (string $ productSku , array $ expectedData ): void
136
274
{
275
+ $ this ->objectManager ->removeSharedInstance (BundleOptions::class);
137
276
$ this ->registerProduct ($ productSku );
138
- $ jsonConfig = $ this ->json ->unserialize ($ this ->block ->getJsonConfig ());
277
+ /** @var Page $page */
278
+ $ page = $ this ->pageFactory ->create ();
279
+ $ page ->addHandle ([
280
+ 'default ' ,
281
+ 'catalog_product_view ' ,
282
+ 'catalog_product_view_type_bundle ' ,
283
+ ]);
284
+ $ page ->getLayout ()->generateXml ();
285
+ $ block = $ page ->getLayout ()->getBlock ('product.info.bundle.options ' );
286
+ $ jsonConfig = $ this ->json ->unserialize ($ block ->getJsonConfig ());
139
287
$ this ->assertEquals ($ expectedData ['bundle_prices ' ], $ jsonConfig ['prices ' ]);
140
288
$ this ->assertOptionsConfig ($ expectedData ['options_prices ' ], $ jsonConfig );
141
289
}
@@ -165,7 +313,7 @@ private function assertOptionsConfig(array $expectedData, array $actualData): vo
165
313
*/
166
314
private function registerProduct (string $ productSku ): void
167
315
{
168
- $ product = $ this ->productRepository ->get ($ productSku );
316
+ $ product = $ this ->productRepository ->get ($ productSku, false , $ this -> storeManager -> getStore ()-> getId (), true );
169
317
$ this ->registry ->unregister ('product ' );
170
318
$ this ->registry ->register ('product ' , $ product );
171
319
}
0 commit comments