Skip to content

Commit 1b9f8ee

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

7 files changed

+53
-111
lines changed

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

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ protected function setUp()
5555

5656
$this->objectManager = Bootstrap::getObjectManager();
5757
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
58+
$this->productRepository->cleanCache();
5859
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
5960
$this->layout = $this->objectManager->get(LayoutInterface::class);
6061
$this->block = $this->layout->createBlock(Configurable::class);
@@ -68,13 +69,13 @@ protected function setUp()
6869
* @dataProvider expectedLabelsDataProvider
6970
*
7071
* @param array $expectedStoreData
71-
* @param array $expectedSecondSoreData
72+
* @param array $expectedSecondStoreData
7273
* @return void
7374
*/
74-
public function testMultiStoreLabelView(array $expectedStoreData, array $expectedSecondSoreData): void
75+
public function testMultiStoreLabelView(array $expectedStoreData, array $expectedSecondStoreData): void
7576
{
7677
$this->assertProductLabelConfigDataPerStore($expectedStoreData);
77-
$this->assertProductLabelConfigDataPerStore($expectedSecondSoreData, 'fixturestore', true);
78+
$this->assertProductLabelConfigDataPerStore($expectedSecondStoreData, 'fixturestore', true);
7879
}
7980

8081
/**
@@ -85,31 +86,25 @@ public function expectedLabelsDataProvider(): array
8586
return [
8687
[
8788
'options_first_store' => [
88-
[
89+
'simple_option_1_default_store' => [
8990
'label' => 'Option 1 Default Store',
90-
'sku' => 'simple_option_1_default_store',
9191
],
92-
[
92+
'simple_option_2_default_store' => [
9393
'label' => 'Option 2 Default Store',
94-
'sku' => 'simple_option_2_default_store',
9594
],
96-
[
95+
'simple_option_3_default_store' => [
9796
'label' => 'Option 3 Default Store',
98-
'sku' => 'simple_option_3_default_store',
9997
],
10098
],
10199
'options_second_store' => [
102-
[
100+
'simple_option_1_default_store' => [
103101
'label' => 'Option 1 Second Store',
104-
'sku' => 'simple_option_1_default_store',
105102
],
106-
[
103+
'simple_option_2_default_store' => [
107104
'label' => 'Option 2 Second Store',
108-
'sku' => 'simple_option_2_default_store',
109105
],
110-
[
106+
'simple_option_3_default_store' => [
111107
'label' => 'Option 3 Second Store',
112-
'sku' => 'simple_option_3_default_store',
113108
],
114109
],
115110
],
@@ -184,7 +179,7 @@ private function assertProductConfig(array $expectedProducts, array $config): vo
184179
* @param string $storeCode
185180
* @return void
186181
*/
187-
private function setProductDisabledPerStore(ProductInterface $product, string $storeCode)
182+
private function setProductDisabledPerStore(ProductInterface $product, string $storeCode): void
188183
{
189184
$currentStore = $this->storeManager->getStore();
190185
try {
@@ -291,22 +286,14 @@ private function getBlockConfig(ProductInterface $product, bool $refreshBlock):
291286
*/
292287
private function assertAttributeConfig(array $expectedData, array $actualOptions): void
293288
{
294-
$skus = array_column($expectedData, 'sku');
289+
$skus = array_keys($expectedData);
295290
$idBySkuMap = $this->productResource->getProductsIdsBySkus($skus);
296-
foreach ($expectedData as &$option) {
297-
$sku = $option['sku'];
298-
unset($option['sku']);
291+
array_walk($actualOptions['options'], function (&$option) {
292+
unset($option['id']);
293+
});
294+
foreach ($expectedData as $sku => &$option) {
299295
$option['products'] = [$idBySkuMap[$sku]];
300-
$found = false;
301-
foreach ($actualOptions['options'] as $actualOption) {
302-
if ($option['label'] === $actualOption['label']) {
303-
unset($actualOption['id']);
304-
$this->assertEquals($option, $actualOption);
305-
$found = true;
306-
break;
307-
}
308-
}
309-
$this->assertTrue($found, sprintf('The option with %s label is not loaded', $option['label']));
310296
}
297+
$this->assertEquals(array_values($expectedData), $actualOptions['options']);
311298
}
312299
}

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_attribute_different_labels_per_stores.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,36 @@
77

88
use Magento\Catalog\Api\Data\ProductAttributeInterface;
99
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
10+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1011
use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
1112
use Magento\Catalog\Setup\CategorySetup;
1213
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
14+
use Magento\Framework\ObjectManagerInterface;
1315
use Magento\Store\Model\Store;
14-
use Magento\Store\Model\StoreManagerInterface;
1516
use Magento\TestFramework\Helper\Bootstrap;
1617

1718
require __DIR__ . '/../../Store/_files/core_fixturestore.php';
1819

20+
/** @var ObjectManagerInterface $objectManager */
1921
$objectManager = Bootstrap::getObjectManager();
20-
$storeManager = $objectManager->get(StoreManagerInterface::class);
2122
$defaultInstalledStoreId = $storeManager->getStore('default')->getId();
2223
$secondStoreId = $storeManager->getStore('fixturestore')->getId();
23-
$installer = $objectManager->create(CategorySetup::class);
24-
$attribute = $objectManager->create(AttributeFactory::class)->create();
25-
$attributeRepository = $objectManager->create(ProductAttributeRepositoryInterface::class);
24+
/** @var CategorySetup $installer */
25+
$installer = $objectManager->get(CategorySetup::class);
26+
/** @var Attribute $attribute */
27+
$attribute = $objectManager->get(AttributeFactory::class)->create();
28+
/** @var ProductAttributeRepositoryInterface $attributeRepository */
29+
$attributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class);
2630
$entityType = $installer->getEntityTypeId(ProductAttributeInterface::ENTITY_TYPE_CODE);
27-
if (!$attribute->loadByCode($entityType, 'different_labels_dropdown_attribute')->getAttributeId()) {
31+
if (!$attribute->loadByCode($entityType, 'different_labels_attribute')->getAttributeId()) {
2832
$attribute->setData(
2933
[
3034
'frontend_label' => ['Different option labels dropdown attribute'],
3135
'entity_type_id' => $entityType,
3236
'frontend_input' => 'select',
3337
'backend_type' => 'int',
3438
'is_required' => '0',
35-
'attribute_code' => 'different_labels_dropdown_attribute',
39+
'attribute_code' => 'different_labels_attribute',
3640
'is_global' => ScopedAttributeInterface::SCOPE_GLOBAL,
3741
'is_user_defined' => 1,
3842
'is_unique' => '0',
@@ -44,7 +48,7 @@
4448
'is_html_allowed_on_front' => '1',
4549
'used_in_product_listing' => '1',
4650
'used_for_sort_by' => '0',
47-
'option' => [
51+
'option' => [
4852
'value' => [
4953
'option_1' => [
5054
Store::DEFAULT_STORE_ID => 'Option 1',
@@ -70,7 +74,7 @@
7074
],
7175
]
7276
);
73-
$attribute->save();
77+
$attributeRepository->save($attribute);
7478
$installer->addAttributeToGroup(
7579
ProductAttributeInterface::ENTITY_TYPE_CODE,
7680
'Default',

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_attribute_different_labels_per_stores_rollback.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,26 @@
66
declare(strict_types=1);
77

88
use Magento\Framework\Exception\NoSuchEntityException;
9+
use Magento\Framework\ObjectManagerInterface;
910
use Magento\TestFramework\Helper\Bootstrap;
1011
use Magento\Framework\Registry;
1112
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
1213

14+
/** @var ObjectManagerInterface $objectManager */
1315
$objectManager = Bootstrap::getObjectManager();
16+
/** @var Registry $registry */
1417
$registry = $objectManager->get(Registry::class);
1518
$registry->unregister('isSecureArea');
1619
$registry->register('isSecureArea', true);
1720
/** @var ProductAttributeRepositoryInterface $attributeRepository */
18-
$attributeRepository = $objectManager->create(ProductAttributeRepositoryInterface::class);
21+
$attributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class);
1922

2023
try {
21-
$attributeRepository->deleteById('different_labels_dropdown_attribute');
24+
$attributeRepository->deleteById('different_labels_attribute');
2225
} catch (NoSuchEntityException $e) {
26+
//already deleted
2327
}
28+
2429
$registry->unregister('isSecureArea');
2530
$registry->register('isSecureArea', false);
2631

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_product_different_option_labeles_per_stores.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
/** @var ObjectManagerInterface $objectManager */
2424
$objectManager = Bootstrap::getObjectManager();
2525
/** @var ProductAttributeRepositoryInterface $productAttributeRepository */
26-
$productAttributeRepository = $objectManager->create(ProductAttributeRepositoryInterface::class);
27-
$attribute = $productAttributeRepository->get('different_labels_dropdown_attribute');
26+
$productAttributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class);
27+
$attribute = $productAttributeRepository->get('different_labels_attribute');
2828
$options = $attribute->getOptions();
2929
/** @var WebsiteRepositoryInterface $websiteRepository */
3030
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
3131
$baseWebsite = $websiteRepository->get('base');
3232
/** @var ProductRepositoryInterface $productRepository */
33-
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
33+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
34+
$productRepository->cleanCache();
3435
/** @var ProductFactory $productFactory */
3536
$productFactory = $objectManager->get(ProductFactory::class);
3637
$attributeValues = [];
@@ -46,7 +47,7 @@
4647
->setName('Configurable Option ' . $option->getLabel())
4748
->setSku(strtolower(str_replace(' ', '_', 'simple ' . $option->getLabel())))
4849
->setPrice(150)
49-
->setDifferentLabelsDropdownAttribute($option->getValue())
50+
->setDifferentLabelsAttribute($option->getValue())
5051
->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE)
5152
->setStatus(Status::STATUS_ENABLED)
5253
->setCategoryIds([$rootCategoryId])

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_product_different_option_labeles_per_stores_rollback.php

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,14 @@
55
*/
66
declare(strict_types=1);
77

8-
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
9-
use Magento\Catalog\Api\ProductRepositoryInterface;
10-
use Magento\Framework\Exception\NoSuchEntityException;
118
use Magento\Framework\ObjectManagerInterface;
12-
use Magento\Framework\Registry;
9+
use Magento\TestFramework\ConfigurableProduct\Model\DeleteConfigurableProduct;
1310
use Magento\TestFramework\Helper\Bootstrap;
1411

1512
/** @var ObjectManagerInterface $objectManager */
1613
$objectManager = Bootstrap::getObjectManager();
17-
/** @var Registry $registry */
18-
$registry = $objectManager->get(Registry::class);
19-
$registry->unregister('isSecureArea');
20-
$registry->register('isSecureArea', true);
21-
/** @var ProductRepositoryInterface $productRepository */
22-
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
23-
/** @var ProductAttributeRepositoryInterface $productAttributeRepository */
24-
$productAttributeRepository = $objectManager->create(ProductAttributeRepositoryInterface::class);
25-
$attribute = $productAttributeRepository->get('different_labels_dropdown_attribute');
26-
$options = $attribute->getOptions();
27-
array_shift($options);
28-
$productsArray = [];
29-
30-
foreach ($options as $option) {
31-
$productsArray [] = strtolower(str_replace(' ', '_', 'simple ' . $option->getLabel()));
32-
}
33-
34-
$productsArray[] = 'configurable';
35-
foreach ($productsArray as $sku) {
36-
try {
37-
$productRepository->deleteById($sku);
38-
} catch (NoSuchEntityException $e) {
39-
//Product already removed
40-
}
41-
}
42-
43-
$registry->unregister('isSecureArea');
44-
$registry->register('isSecureArea', false);
14+
/** @var DeleteConfigurableProduct $deleteConfigurableProduct */
15+
$deleteConfigurableProduct = $objectManager->get(DeleteConfigurableProduct::class);
16+
$deleteConfigurableProduct->execute('configurable');
4517

4618
require __DIR__ . '/configurable_attribute_different_labels_per_stores_rollback.php';

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_product_two_websites.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@
2424
/** @var ObjectManagerInterface $objectManager */
2525
$objectManager = Bootstrap::getObjectManager();
2626
/** @var ProductAttributeRepositoryInterface $productAttributeRepository */
27-
$productAttributeRepository = $objectManager->create(ProductAttributeRepositoryInterface::class);
27+
$productAttributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class);
2828
$attribute = $productAttributeRepository->get('test_configurable');
2929
$options = $attribute->getOptions();
3030
/** @var WebsiteRepositoryInterface $websiteRepository */
3131
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
3232
$baseWebsite = $websiteRepository->get('base');
3333
$secondWebsite = $websiteRepository->get('test');
3434
/** @var ProductRepositoryInterface $productRepository */
35-
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
35+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
36+
$productRepository->cleanCache();
3637
/** @var ProductFactory $productFactory */
3738
$productFactory = $objectManager->get(ProductFactory::class);
3839
$attributeValues = [];

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_product_two_websites_rollback.php

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,15 @@
55
*/
66
declare(strict_types=1);
77

8-
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
9-
use Magento\Catalog\Api\ProductRepositoryInterface;
10-
use Magento\Framework\Exception\NoSuchEntityException;
118
use Magento\Framework\ObjectManagerInterface;
12-
use Magento\Framework\Registry;
9+
use Magento\TestFramework\ConfigurableProduct\Model\DeleteConfigurableProduct;
1310
use Magento\TestFramework\Helper\Bootstrap;
1411

1512
/** @var ObjectManagerInterface $objectManager */
1613
$objectManager = Bootstrap::getObjectManager();
17-
/** @var Registry $registry */
18-
$registry = $objectManager->get(Registry::class);
19-
$registry->unregister('isSecureArea');
20-
$registry->register('isSecureArea', true);
21-
/** @var ProductRepositoryInterface $productRepository */
22-
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
23-
/** @var ProductAttributeRepositoryInterface $productAttributeRepository */
24-
$productAttributeRepository = $objectManager->create(ProductAttributeRepositoryInterface::class);
25-
$attribute = $productAttributeRepository->get('test_configurable');
26-
$options = $attribute->getOptions();
27-
array_shift($options);
28-
$productsArray = [];
29-
30-
foreach ($options as $option) {
31-
$productsArray [] = strtolower(str_replace(' ', '_', 'simple ' . $option->getLabel()));
32-
}
33-
34-
$productsArray[] = 'configurable';
35-
foreach ($productsArray as $sku) {
36-
try {
37-
$productRepository->deleteById($sku);
38-
} catch (NoSuchEntityException $e) {
39-
//Product already removed
40-
}
41-
}
42-
43-
$registry->unregister('isSecureArea');
44-
$registry->register('isSecureArea', false);
14+
/** @var DeleteConfigurableProduct $deleteConfigurableProduct */
15+
$deleteConfigurableProduct = $objectManager->get(DeleteConfigurableProduct::class);
16+
$deleteConfigurableProduct->execute('configurable');
4517

4618
require __DIR__ . '/configurable_attribute_rollback.php';
4719
require __DIR__ . '/../../Store/_files/second_website_with_two_stores_rollback.php';

0 commit comments

Comments
 (0)