Skip to content

Commit db4da15

Browse files
Fixed dialog issue, added testes
1 parent 2f6c738 commit db4da15

File tree

4 files changed

+188
-4
lines changed

4 files changed

+188
-4
lines changed

Diff for: src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.form

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@
357357
<text value="Is visible in grid"/>
358358
</properties>
359359
</component>
360-
<component id="10bde" class="javax.swing.JCheckBox" binding="systemAttributecheckBox">
360+
<component id="10bde" class="javax.swing.JCheckBox" binding="systemAttributeCheckBox">
361361
<constraints>
362362
<grid row="15" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
363363
</constraints>

Diff for: src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCustomerEavAttributeDialog.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public class NewCustomerEavAttributeDialog extends EavAttributeDialog {
8282
private JCheckBox useInGridCheckBox;
8383
private JCheckBox filterableInGridCheckBox;
8484
private JCheckBox visibleInGridCheckBox;
85-
private JCheckBox systemAttributecheckBox;
85+
private JCheckBox systemAttributeCheckBox;
8686

8787
/**
8888
* Constructor.
@@ -243,9 +243,9 @@ private CustomerEntityData populateCategoryEntityData(
243243
useInCustomerAccountEditCheckBox.isSelected()
244244
);
245245
customerEntityData.setVisibleInGrid(visibleInGridCheckBox.isSelected());
246-
customerEntityData.setUsedInGrid(useInGridCheckBox.isVisible());
246+
customerEntityData.setUsedInGrid(useInGridCheckBox.isSelected());
247247
customerEntityData.setFilterableInGrid(filterableInGridCheckBox.isSelected());
248-
customerEntityData.setSystem(systemAttributecheckBox.isSelected());
248+
customerEntityData.setSystem(systemAttributeCheckBox.isSelected());
249249

250250
return customerEntityData;
251251
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
3+
namespace Foo\Bar\Setup\Patch\Data;
4+
5+
use Magento\Customer\Api\CustomerMetadataInterface;
6+
use Magento\Customer\Model\Customer;
7+
use Magento\Eav\Model\Config;
8+
use Magento\Eav\Setup\EavSetup;
9+
use Magento\Eav\Setup\EavSetupFactory;
10+
use Magento\Framework\Setup\ModuleDataSetupInterface;
11+
use Magento\Framework\Setup\Patch\DataPatchInterface;
12+
13+
class AddMultiselectTestCustomerAttribute implements DataPatchInterface
14+
{
15+
/**
16+
* @var ModuleDataSetupInterface
17+
*/
18+
private $moduleDataSetup;
19+
20+
/**
21+
* @var EavSetupFactory
22+
*/
23+
private $eavSetupFactory;
24+
25+
/**
26+
* @var Config
27+
*/
28+
private $eavConfig;
29+
30+
/**
31+
* @param ModuleDataSetupInterface $moduleDataSetup
32+
* @param EavSetupFactory $eavSetupFactory
33+
*/
34+
public function __construct(
35+
ModuleDataSetupInterface $moduleDataSetup,
36+
EavSetupFactory $eavSetupFactory,
37+
Config $eavConfig
38+
)
39+
{
40+
$this->moduleDataSetup = $moduleDataSetup;
41+
$this->eavSetupFactory = $eavSetupFactory;
42+
$this->eavConfig = $eavConfig;
43+
}
44+
45+
/**
46+
* Run code inside patch
47+
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
48+
* means run PatchInterface::revert()
49+
*
50+
* If we speak about data, under revert means: $transaction->rollback()
51+
*
52+
* @return $this
53+
*/
54+
public function apply()
55+
{
56+
/** @var EavSetup $eavSetup */
57+
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
58+
59+
$eavSetup->addAttribute(
60+
Customer::ENTITY,
61+
'multiselect_test',
62+
[
63+
'is_visible_in_grid' => false,
64+
'visible' => true,
65+
'label' => 'Multiselect Test',
66+
'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
67+
'type' => 'varchar',
68+
'is_used_in_grid' => false,
69+
'required' => false,
70+
'input' => 'multiselect',
71+
'user_defined' => true,
72+
'is_filterable_in_grid' => false,
73+
'system' => false,
74+
'backend' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class,
75+
'position' => 10,
76+
'option' => [
77+
'value' => [
78+
'option_0' => ['option1'],
79+
'option_1' => ['option2'],
80+
'option_2' => ['option3'],
81+
]
82+
],
83+
]
84+
);
85+
86+
$eavSetup->addAttributeToSet(
87+
CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER,
88+
CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
89+
null,
90+
'multiselect_test'
91+
);
92+
93+
$attribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'multiselect_test');
94+
$attribute->setData(
95+
'used_in_forms',
96+
['adminhtml_customer']
97+
);
98+
$attribute->save();
99+
100+
return $this;
101+
}
102+
103+
/**
104+
* Get array of patches that have to be executed prior to this.
105+
*
106+
* Example of implementation:
107+
*
108+
* [
109+
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
110+
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
111+
* ]
112+
*
113+
* @return string[]
114+
*/
115+
public static function getDependencies()
116+
{
117+
return [];
118+
}
119+
120+
/**
121+
* Get aliases (previous names) for the patch.
122+
*
123+
* @return string[]
124+
*/
125+
public function getAliases()
126+
{
127+
return [];
128+
}
129+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*
5+
*/
6+
7+
package com.magento.idea.magento2plugin.actions.generation.generator;
8+
9+
import com.intellij.openapi.project.Project;
10+
import com.intellij.psi.PsiFile;
11+
import com.magento.idea.magento2plugin.actions.generation.data.CustomerEntityData;
12+
import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput;
13+
import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel;
14+
import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType;
15+
import java.util.HashMap;
16+
import java.util.Map;
17+
18+
public class CustomerAttributeSetupPatchGeneratorTest extends BaseGeneratorTestCase {
19+
20+
private final static String MODULE_NAME = "Foo_Bar";
21+
22+
public void testGenerateMultiselectAttributeDataPatch() {
23+
final Project project = myFixture.getProject();
24+
25+
final CustomerEntityData customerEntityData = new CustomerEntityData();
26+
customerEntityData.setCode("multiselect_test");
27+
customerEntityData.setLabel("Multiselect Test");
28+
customerEntityData.setVisible(true);
29+
customerEntityData.setSource(AttributeSourceModel.TABLE.getSource());
30+
customerEntityData.setType(AttributeType.VARCHAR.getType());
31+
customerEntityData.setInput(AttributeInput.MULTISELECT.getInput());
32+
customerEntityData.setUserDefined(true);
33+
customerEntityData.setSortOrder(10);
34+
customerEntityData.setUseInAdminhtmlCustomerForm(true);
35+
36+
final Map<Integer, String> options = new HashMap<>();
37+
options.put(0, "option1");
38+
options.put(1, "option2");
39+
options.put(2, "option3");
40+
customerEntityData.setOptions(options);
41+
42+
customerEntityData.setDataPatchName("AddMultiselectTestCustomerAttribute");
43+
customerEntityData.setModuleName(MODULE_NAME);
44+
45+
46+
final CustomerEavAttributePatchGenerator setupPatchGenerator =
47+
new CustomerEavAttributePatchGenerator(customerEntityData, project);
48+
final PsiFile dataPatchFile = setupPatchGenerator.generate("testGenerateMultiselectAttributeDataPatch");
49+
50+
final String filePatch = this.getFixturePath("AddMultiselectTestCustomerAttribute.php");
51+
final PsiFile expectedFile = myFixture.configureByFile(filePatch);
52+
53+
assertGeneratedFileIsCorrect(expectedFile, "src/app/code/Foo/Bar/Setup/Patch/Data", dataPatchFile);
54+
}
55+
}

0 commit comments

Comments
 (0)