|
12 | 12 | use Magento\Eav\Setup\EavSetup;
|
13 | 13 | use Magento\Framework\Exception\NoSuchEntityException;
|
14 | 14 | use Magento\TestFramework\Helper\Bootstrap;
|
| 15 | +use Magento\TestFramework\Workaround\Override\Fixture\Resolver; |
15 | 16 |
|
16 | 17 | $objectManager = Bootstrap::getObjectManager();
|
17 | 18 |
|
18 | 19 | /** @var ProductAttributeRepositoryInterface $attributeRepository */
|
19 | 20 | $attributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class);
|
20 |
| -$attributeCode = 'test_configurable'; |
| 21 | +/** @var ProductAttributeInterfaceFactory $attributeFactory */ |
| 22 | +$attributeFactory = $objectManager->get(ProductAttributeInterfaceFactory::class); |
| 23 | + |
21 | 24 | try {
|
22 |
| - $attributeRepository->get($attributeCode); |
| 25 | + $attributeRepository->get('test_configurable'); |
| 26 | + Resolver::getInstance() |
| 27 | + ->requireDataFixture('Magento/ConfigurableProduct/_files/configurable_attribute_rollback.php'); |
23 | 28 | } catch (NoSuchEntityException $e) {
|
24 |
| - /** @var $installer EavSetup */ |
25 |
| - $installer = $objectManager->get(EavSetup::class); |
26 |
| - $attributeSetId = $installer->getAttributeSetId(Product::ENTITY, 'Default'); |
27 |
| - $groupId = $installer->getDefaultAttributeGroupId(Product::ENTITY, $attributeSetId); |
| 29 | +} |
28 | 30 |
|
29 |
| - /** @var ProductAttributeInterfaceFactory $attributeFactory */ |
30 |
| - $attributeFactory = $objectManager->get(ProductAttributeInterfaceFactory::class); |
31 |
| - /** @var ProductAttributeInterface $attributeModel */ |
32 |
| - $attributeModel = $attributeFactory->create(); |
33 |
| - $attributeModel->setData( |
34 |
| - [ |
35 |
| - 'attribute_code' => $attributeCode, |
36 |
| - 'entity_type_id' => $installer->getEntityTypeId(Product::ENTITY), |
37 |
| - 'is_global' => 1, |
38 |
| - 'is_user_defined' => 1, |
39 |
| - 'frontend_input' => 'select', |
40 |
| - 'is_unique' => 0, |
41 |
| - 'is_required' => 0, |
42 |
| - 'is_searchable' => 0, |
43 |
| - 'is_visible_in_advanced_search' => 0, |
44 |
| - 'is_comparable' => 0, |
45 |
| - 'is_filterable' => 0, |
46 |
| - 'is_filterable_in_search' => 0, |
47 |
| - 'is_used_for_promo_rules' => 0, |
48 |
| - 'is_html_allowed_on_front' => 1, |
49 |
| - 'is_visible_on_front' => 0, |
50 |
| - 'used_in_product_listing' => 0, |
51 |
| - 'used_for_sort_by' => 0, |
52 |
| - 'frontend_label' => ['Test Configurable'], |
53 |
| - 'backend_type' => 'int', |
54 |
| - 'option' => [ |
55 |
| - 'value' => ['option_0' => ['Option 1'], 'option_1' => ['Option 2']], |
56 |
| - 'order' => ['option_0' => 1, 'option_1' => 2], |
57 |
| - ], |
58 |
| - ] |
59 |
| - ); |
60 |
| - $attribute = $attributeRepository->save($attributeModel); |
| 31 | +$eavConfig = $objectManager->get(Config::class); |
61 | 32 |
|
62 |
| - $installer->addAttributeToGroup(Product::ENTITY, $attributeSetId, $groupId, $attribute->getId()); |
63 |
| - $eavConfig = $objectManager->get(Config::class); |
64 |
| - $eavConfig->clear(); |
65 |
| -} |
| 33 | +/** @var $installer EavSetup */ |
| 34 | +$installer = $objectManager->get(EavSetup::class); |
| 35 | +$attributeSetId = $installer->getAttributeSetId(Product::ENTITY, 'Default'); |
| 36 | +$groupId = $installer->getDefaultAttributeGroupId(Product::ENTITY, $attributeSetId); |
| 37 | +/** @var ProductAttributeInterface $attributeModel */ |
| 38 | +$attributeModel = $attributeFactory->create(); |
| 39 | +$attributeModel->setData( |
| 40 | + [ |
| 41 | + 'attribute_code' => 'test_configurable', |
| 42 | + 'entity_type_id' => $installer->getEntityTypeId(Product::ENTITY), |
| 43 | + 'is_global' => 1, |
| 44 | + 'is_user_defined' => 1, |
| 45 | + 'frontend_input' => 'select', |
| 46 | + 'is_unique' => 0, |
| 47 | + 'is_required' => 0, |
| 48 | + 'is_searchable' => 0, |
| 49 | + 'is_visible_in_advanced_search' => 0, |
| 50 | + 'is_comparable' => 0, |
| 51 | + 'is_filterable' => 0, |
| 52 | + 'is_filterable_in_search' => 0, |
| 53 | + 'is_used_for_promo_rules' => 0, |
| 54 | + 'is_html_allowed_on_front' => 1, |
| 55 | + 'is_visible_on_front' => 0, |
| 56 | + 'used_in_product_listing' => 0, |
| 57 | + 'used_for_sort_by' => 0, |
| 58 | + 'frontend_label' => ['Test Configurable'], |
| 59 | + 'backend_type' => 'int', |
| 60 | + 'option' => [ |
| 61 | + 'value' => ['option_0' => ['Option 1'], 'option_1' => ['Option 2']], |
| 62 | + 'order' => ['option_0' => 1, 'option_1' => 2], |
| 63 | + ], |
| 64 | + ] |
| 65 | +); |
| 66 | + |
| 67 | +$attribute = $attributeRepository->save($attributeModel); |
| 68 | + |
| 69 | +$installer->addAttributeToGroup(Product::ENTITY, $attributeSetId, $groupId, $attribute->getId()); |
| 70 | +$eavConfig->clear(); |
0 commit comments