6
6
7
7
namespace Magento \Bundle \Api ;
8
8
9
+ use Magento \Bundle \Test \Fixture \Option as BundleOptionFixture ;
10
+ use Magento \Bundle \Test \Fixture \Product as BundleProductFixture ;
9
11
use Magento \Catalog \Api \Data \ProductInterface ;
12
+ use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
10
13
use Magento \Framework \Api \ExtensibleDataInterface ;
14
+ use Magento \Store \Test \Fixture \Store as StoreFixture ;
15
+ use Magento \TestFramework \Fixture \DataFixture ;
16
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
11
17
use Magento \TestFramework \Helper \Bootstrap ;
12
18
use Magento \TestFramework \TestCase \WebapiAbstract ;
13
19
use Magento \Bundle \Api \Data \LinkInterface ;
17
23
*/
18
24
class ProductServiceTest extends WebapiAbstract
19
25
{
20
- const SERVICE_NAME = 'catalogProductRepositoryV1 ' ;
21
- const SERVICE_VERSION = 'V1 ' ;
22
- const RESOURCE_PATH = '/V1/products ' ;
23
- const BUNDLE_PRODUCT_ID = 'sku-test-product-bundle ' ;
26
+ private const SERVICE_NAME = 'catalogProductRepositoryV1 ' ;
27
+ private const SERVICE_VERSION = 'V1 ' ;
28
+ private const RESOURCE_PATH = '/V1/products ' ;
29
+ private const BUNDLE_PRODUCT_ID = 'sku-test-product-bundle ' ;
24
30
25
31
/**
26
32
* @var \Magento\Catalog\Model\ResourceModel\Product\Collection
27
33
*/
28
34
protected $ productCollection ;
29
35
36
+ /**
37
+ * @var bool
38
+ */
39
+ private $ cleanUpOnTearDown = true ;
40
+
30
41
/**
31
42
* Execute per test initialization
32
43
*/
33
44
protected function setUp (): void
34
45
{
35
46
$ objectManager = Bootstrap::getObjectManager ();
36
47
$ this ->productCollection = $ objectManager ->get (\Magento \Catalog \Model \ResourceModel \Product \Collection::class);
48
+ $ this ->cleanUpOnTearDown = true ;
37
49
}
38
50
39
51
/**
40
52
* Execute per test cleanup
41
53
*/
42
54
protected function tearDown (): void
43
55
{
44
- $ this ->deleteProductBySku (self ::BUNDLE_PRODUCT_ID );
56
+ if ($ this ->cleanUpOnTearDown ) {
57
+ $ this ->deleteProductBySku (self ::BUNDLE_PRODUCT_ID );
58
+ }
45
59
parent ::tearDown ();
46
60
}
47
61
@@ -269,7 +283,6 @@ public function testUpdateFixedPriceBundleProductOptionSelectionPrice()
269
283
$ bundleProduct = $ this ->createFixedPriceBundleProduct ();
270
284
$ bundleProductOptions = $ this ->getBundleProductOptions ($ bundleProduct );
271
285
272
- $ oldOptionId = $ bundleProductOptions [0 ]['option_id ' ];
273
286
//replace current option with a new option
274
287
$ bundleProductOptions [0 ] = [
275
288
'title ' => 'new option ' ,
@@ -295,6 +308,52 @@ public function testUpdateFixedPriceBundleProductOptionSelectionPrice()
295
308
$ this ->assertEquals ($ optionPrice , $ bundleOptions [0 ]['product_links ' ][0 ]['price ' ]);
296
309
}
297
310
311
+ #[
312
+ DataFixture(StoreFixture::class, as: 'store2 ' ),
313
+ DataFixture(ProductFixture::class, ['price ' => 10 ], 'p1 ' ),
314
+ DataFixture(ProductFixture::class, ['price ' => 20 ], 'p2 ' ),
315
+ DataFixture(BundleOptionFixture::class, ['product_links ' => ['$p1$ ' ]], 'opt1 ' ),
316
+ DataFixture(BundleOptionFixture::class, ['product_links ' => ['$p2$ ' ]], 'opt2 ' ),
317
+ DataFixture(
318
+ BundleProductFixture::class,
319
+ ['_options ' => ['$opt1$ ' , '$opt2$ ' ]],
320
+ 'bundle1 '
321
+ ),
322
+ ]
323
+
324
+ public function testUpdateBundleProductOptionsTitleOnStoreView (): void
325
+ {
326
+ $ this ->cleanUpOnTearDown = false ;
327
+ $ fixtures = DataFixtureStorageManager::getStorage ();
328
+ $ product = $ fixtures ->get ('bundle1 ' );
329
+ $ store2 = $ fixtures ->get ('store2 ' );
330
+ $ data = $ this ->getProduct ($ product ->getSku ());
331
+ $ defaultOptions = $ this ->getBundleProductOptions ($ data );
332
+ $ store2Options = $ defaultOptions ;
333
+ $ store2Options [0 ]['title ' ] .= ' - custom ' ;
334
+ $ store2Options [1 ]['title ' ] .= ' - custom ' ;
335
+ $ this ->setBundleProductOptions ($ data , $ store2Options );
336
+ $ this ->saveProduct ($ data , $ store2 ->getCode ());
337
+
338
+ // check that option titles are updated on store 2
339
+ $ data = $ this ->getProduct ($ product ->getSku (), $ store2 ->getCode ());
340
+ $ options = $ this ->getBundleProductOptions ($ data );
341
+ $ this ->assertEquals ($ store2Options [0 ]['title ' ], $ options [0 ]['title ' ]);
342
+ $ this ->assertEquals ($ store2Options [1 ]['title ' ], $ options [1 ]['title ' ]);
343
+
344
+ // check that option titles have not changed on default store
345
+ $ data = $ this ->getProduct ($ product ->getSku (), 'default ' );
346
+ $ options = $ this ->getBundleProductOptions ($ data );
347
+ $ this ->assertEquals ($ defaultOptions [0 ]['title ' ], $ options [0 ]['title ' ]);
348
+ $ this ->assertEquals ($ defaultOptions [1 ]['title ' ], $ options [1 ]['title ' ]);
349
+
350
+ // check that option titles have not changed in global scope
351
+ $ data = $ this ->getProduct ($ product ->getSku (), 'all ' );
352
+ $ options = $ this ->getBundleProductOptions ($ data );
353
+ $ this ->assertEquals ($ defaultOptions [0 ]['title ' ], $ options [0 ]['title ' ]);
354
+ $ this ->assertEquals ($ defaultOptions [1 ]['title ' ], $ options [1 ]['title ' ]);
355
+ }
356
+
298
357
/**
299
358
* Get the bundle_product_options custom attribute from product, null if the attribute is not set
300
359
*
@@ -457,7 +516,7 @@ protected function convertCustomAttributes($customAttributes)
457
516
* @param string $productSku
458
517
* @return array the product data
459
518
*/
460
- protected function getProduct ($ productSku )
519
+ protected function getProduct ($ productSku, ? string $ storeCode = null )
461
520
{
462
521
$ serviceInfo = [
463
522
'rest ' => [
@@ -471,10 +530,9 @@ protected function getProduct($productSku)
471
530
],
472
531
];
473
532
474
- $ response = (TESTS_WEB_API_ADAPTER == self ::ADAPTER_SOAP ) ?
475
- $ this ->_webApiCall ($ serviceInfo , ['sku ' => $ productSku ]) : $ this ->_webApiCall ($ serviceInfo );
476
-
477
- return $ response ;
533
+ return TESTS_WEB_API_ADAPTER === self ::ADAPTER_SOAP
534
+ ? $ this ->_webApiCall ($ serviceInfo , ['sku ' => $ productSku ], storeCode: $ storeCode )
535
+ : $ this ->_webApiCall ($ serviceInfo , storeCode: $ storeCode );
478
536
}
479
537
480
538
/**
@@ -530,9 +588,10 @@ protected function deleteProductBySku($productSku)
530
588
* Save product
531
589
*
532
590
* @param array $product
591
+ * @param string|null $storeCode
533
592
* @return array the created product data
534
593
*/
535
- protected function saveProduct ($ product )
594
+ protected function saveProduct ($ product, ? string $ storeCode = null )
536
595
{
537
596
if (isset ($ product ['custom_attributes ' ])) {
538
597
$ count = count ($ product ['custom_attributes ' ]);
@@ -557,7 +616,7 @@ protected function saveProduct($product)
557
616
],
558
617
];
559
618
$ requestData = ['product ' => $ product ];
560
- $ response = $ this ->_webApiCall ($ serviceInfo , $ requestData );
619
+ $ response = $ this ->_webApiCall ($ serviceInfo , $ requestData, storeCode: $ storeCode );
561
620
return $ response ;
562
621
}
563
622
}
0 commit comments