Skip to content

Commit a92f418

Browse files
committed
MC-29188: Storefront: Create configurable product on (multiple websites/multiple storeviews)
1 parent 8291220 commit a92f418

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

dev/tests/integration/framework/Magento/TestFramework/Store/ExecuteInStoreContext.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,29 @@ public function __construct(StoreManagerInterface $storeManager)
2929
/**
3030
* Execute callback in store context
3131
*
32+
* @param null|string|bool|int|StoreInterface $store
3233
* @param callable $method
3334
* @param array $arguments
34-
* @param null|string|bool|int|StoreInterface $store
35-
* @return void
35+
* @return mixed
3636
*/
37-
public function execute(callable $method, array $arguments, $store = 'default'): void
37+
public function execute($store, callable $method, ...$arguments)
3838
{
39+
$storeCode = $store instanceof StoreInterface
40+
? $store->getCode()
41+
: $this->storeManager->getStore($store)->getCode();
3942
$currentStore = $this->storeManager->getStore();
43+
4044
try {
41-
$this->storeManager->setCurrentStore($store);
42-
$method(...$arguments);
45+
if ($currentStore->getCode() !== $storeCode) {
46+
$this->storeManager->setCurrentStore($storeCode);
47+
}
48+
$result = $method(...array_values($arguments));
4349
} finally {
44-
$this->storeManager->setCurrentStore($currentStore);
50+
if ($currentStore->getCode() !== $storeCode) {
51+
$this->storeManager->setCurrentStore($currentStore);
52+
}
4553
}
54+
55+
return $result;
4656
}
4757
}

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Product/View/Type/MultiStoreConfigurableViewOnProductPageTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,8 @@ protected function setUp()
7575
*/
7676
public function testMultiStoreLabelView(array $expectedStoreData, array $expectedSecondStoreData): void
7777
{
78-
$this->executeInStoreContext->execute([$this, 'assertProductLabel'], [$expectedStoreData]);
79-
$this->executeInStoreContext->execute(
80-
[$this, 'assertProductLabel'],
81-
[$expectedSecondStoreData],
82-
'fixturestore'
83-
);
78+
$this->executeInStoreContext->execute('default', [$this, 'assertProductLabel'], $expectedStoreData);
79+
$this->executeInStoreContext->execute('fixturestore', [$this, 'assertProductLabel'], $expectedSecondStoreData);
8480
}
8581

8682
/**
@@ -142,11 +138,11 @@ public function assertProductLabel($expectedStoreData): void
142138
public function testMultiStoreOptionsView(array $expectedProducts, array $expectedSecondStoreProducts): void
143139
{
144140
$this->prepareConfigurableProduct('configurable', 'fixture_second_store');
145-
$this->executeInStoreContext->execute([$this, 'assertProductConfig'], [$expectedProducts]);
141+
$this->executeInStoreContext->execute('default', [$this, 'assertProductConfig'], $expectedProducts);
146142
$this->executeInStoreContext->execute(
143+
'fixture_second_store',
147144
[$this, 'assertProductConfig'],
148-
[$expectedSecondStoreProducts],
149-
'fixture_second_store'
145+
$expectedSecondStoreProducts
150146
);
151147
}
152148

@@ -190,7 +186,7 @@ private function prepareConfigurableProduct(string $sku, string $storeCode): voi
190186
$productToUpdate = $product->getTypeInstance()->getUsedProductCollection($product)
191187
->setPageSize(1)->getFirstItem();
192188
$this->assertNotEmpty($productToUpdate->getData(), 'Configurable product does not have a child');
193-
$this->executeInStoreContext->execute([$this, 'setProductDisabled'], [$productToUpdate], $storeCode);
189+
$this->executeInStoreContext->execute($storeCode, [$this, 'setProductDisabled'], $productToUpdate);
194190
}
195191

196192
/**

0 commit comments

Comments
 (0)