Skip to content

Commit 8fdf247

Browse files
committed
Refactoring
- replaced some of the deprecated calls - performed DRY optimizations Signed-off-by: Tomash Khamlai <tomash.khamlai@gmail.com>
1 parent caafd17 commit 8fdf247

File tree

1 file changed

+32
-52
lines changed

1 file changed

+32
-52
lines changed

dev/tests/integration/testsuite/Magento/Customer/_files/attribute_user_defined_address_custom_attribute.php

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,37 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/** @var \Magento\Customer\Model\Attribute $model1 */
8-
$model1 = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Attribute::class);
9-
$model1->setName(
10-
'custom_attribute1'
11-
)->setEntityTypeId(
12-
2
13-
)->setAttributeSetId(
14-
2
15-
)->setAttributeGroupId(
16-
1
17-
)->setFrontendInput(
18-
'text'
19-
)->setFrontendLabel(
20-
'custom_attribute_frontend_label'
21-
)->setIsUserDefined(
22-
1
23-
);
24-
$model1->save();
25-
26-
/** @var \Magento\Customer\Model\Attribute $model2 */
27-
$model2 = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Attribute::class);
28-
$model2->setName(
29-
'custom_attribute2'
30-
)->setEntityTypeId(
31-
2
32-
)->setAttributeSetId(
33-
2
34-
)->setAttributeGroupId(
35-
1
36-
)->setFrontendInput(
37-
'text'
38-
)->setFrontendLabel(
39-
'custom_attribute_frontend_label'
40-
)->setIsUserDefined(
41-
1
42-
);
43-
$model2->save();
7+
/** @var \Magento\Framework\ObjectManagerInterface $objectManager */
8+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
9+
10+
/** @var \Magento\Customer\Model\AttributeFactory $attributeFactory */
11+
$attributeFactory = $objectManager->create(\Magento\Customer\Model\AttributeFactory::class);
12+
13+
/** @var \Magento\Eav\Api\AttributeRepositoryInterface $attributeRepository */
14+
$attributeRepository = $objectManager->create(\Magento\Eav\Api\AttributeRepositoryInterface::class);
4415

4516
/** @var \Magento\Customer\Setup\CustomerSetup $setupResource */
46-
$setupResource = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
47-
\Magento\Customer\Setup\CustomerSetup::class
48-
);
49-
50-
$data1 = [['form_code' => 'customer_address_edit', 'attribute_id' => $model1->getAttributeId()]];
51-
$setupResource->getSetup()->getConnection()->insertMultiple(
52-
$setupResource->getSetup()->getTable('customer_form_attribute'),
53-
$data1
54-
);
55-
56-
$data2 = [['form_code' => 'customer_address_edit', 'attribute_id' => $model2->getAttributeId()]];
57-
$setupResource->getSetup()->getConnection()->insertMultiple(
58-
$setupResource->getSetup()->getTable('customer_form_attribute'),
59-
$data2
60-
);
17+
$setupResource = $objectManager->create(\Magento\Customer\Setup\CustomerSetup::class);
18+
19+
$attributeNames = ['custom_attribute1', 'custom_attribute2'];
20+
foreach ($attributeNames as $attributeName) {
21+
/** @var \Magento\Customer\Model\Attribute $attribute */
22+
$attribute = $attributeFactory->create();
23+
24+
$attribute->setName($attributeName)
25+
->setEntityTypeId(2)
26+
->setAttributeSetId(2)
27+
->setAttributeGroupId(1)
28+
->setFrontendInput('text')
29+
->setFrontendLabel('custom_attribute_frontend_label')
30+
->setIsUserDefined(true);
31+
32+
$attributeRepository->save($attribute);
33+
34+
$setupResource->getSetup()
35+
->getConnection()
36+
->insertMultiple(
37+
$setupResource->getSetup()->getTable('customer_form_attribute'),
38+
[['form_code' => 'customer_address_edit', 'attribute_id' => $attribute->getAttributeId()]]
39+
);
40+
}

0 commit comments

Comments
 (0)