Skip to content

Commit 94a915a

Browse files
author
Vitaliy Boyko
committed
Code review adjustments
1 parent b6c0342 commit 94a915a

File tree

9 files changed

+75
-9
lines changed

9 files changed

+75
-9
lines changed

resources/fileTemplates/internal/Magento Customer Eav Attribute Data Patch Class.php.ft

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,27 @@ class ${CLASS_NAME} implements ${IMPLEMENTS}
2626
*/
2727
private $eavConfig;
2828

29+
/**
30+
* @var ${ATTRIBUTE_RESOURCE}
31+
*/
32+
private $attributeResource;
33+
2934
/**
3035
* @param ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup
3136
* @param ${EAV_SETUP_FACTORY} $eavSetupFactory
37+
* @param ${EAV_CONFIG_CLASS} $eavConfig
38+
* @param ${ATTRIBUTE_RESOURCE} $attributeResource
3239
*/
3340
public function __construct(
3441
${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup,
3542
${EAV_SETUP_FACTORY} $eavSetupFactory,
36-
${EAV_CONFIG_CLASS} $eavConfig
43+
${EAV_CONFIG_CLASS} $eavConfig,
44+
${ATTRIBUTE_RESOURCE} $attributeResource
3745
) {
3846
$this->moduleDataSetup = $moduleDataSetup;
3947
$this->eavSetupFactory = $eavSetupFactory;
4048
$this->eavConfig = $eavConfig;
49+
$this->attributeResource = $attributeResource;
4150
}
4251

4352
/**
@@ -78,7 +87,7 @@ class ${CLASS_NAME} implements ${IMPLEMENTS}
7887
'used_in_forms',
7988
[${CUSTOMER_FORMS}]
8089
);
81-
$attribute->save();
90+
$this->attributeResource->save($attribute);
8291
#end
8392

8493
return $this;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html lang="en">
8+
<body>
9+
<font face="verdana" size="-1">
10+
<p>
11+
Data patch for the customer EAV attribute
12+
</p>
13+
</font>
14+
</body>
15+
</html>

src/com/magento/idea/magento2plugin/actions/generation/data/CustomerEntityData.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
4-
*
54
*/
65

76
package com.magento.idea.magento2plugin.actions.generation.data;
@@ -29,6 +28,7 @@ public class CustomerEntityData implements EavEntityDataInterface {
2928
private boolean visible;
3029
private boolean userDefined;
3130
private boolean useInAdminhtmlCustomerForm;
31+
private boolean useInAdminhtmlCheckoutForm;
3232
private boolean useInCustomerAccountCreateForm;
3333
private boolean useInCustomerAccountEditForm;
3434
private boolean usedInGrid;
@@ -119,6 +119,10 @@ public void setUseInAdminhtmlCustomerForm(final boolean useInAdminhtmlCustomerFo
119119
this.useInAdminhtmlCustomerForm = useInAdminhtmlCustomerForm;
120120
}
121121

122+
public void setUseInAdminhtmlCheckoutForm(final boolean useInAdminhtmlCheckoutForm) {
123+
this.useInAdminhtmlCheckoutForm = useInAdminhtmlCheckoutForm;
124+
}
125+
122126
public void setUseInCustomerAccountCreateForm(final boolean useInCustomerAccountCreateForm) {
123127
this.useInCustomerAccountCreateForm = useInCustomerAccountCreateForm;
124128
}
@@ -235,6 +239,10 @@ public boolean isUseInAdminhtmlCustomerForm() {
235239
return useInAdminhtmlCustomerForm;
236240
}
237241

242+
public boolean isUseInAdminhtmlCheckoutForm() {
243+
return useInAdminhtmlCheckoutForm;
244+
}
245+
238246
public boolean isUseInCustomerAccountCreateForm() {
239247
return useInCustomerAccountCreateForm;
240248
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
<grid id="28350" binding="contentPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="10" left="10" bottom="10" right="10"/>
55
<constraints>
6-
<xy x="-1" y="5" width="764" height="810"/>
6+
<xy x="-1" y="5" width="764" height="843"/>
77
</constraints>
88
<properties>
99
<enabled value="true"/>
10-
<preferredSize width="800" height="800"/>
1110
</properties>
1211
<border type="none"/>
1312
<children>
@@ -365,6 +364,14 @@
365364
<text value="System"/>
366365
</properties>
367366
</component>
367+
<component id="ba7a3" class="javax.swing.JCheckBox" binding="useInAdminhtmlCheckoutCheckBox">
368+
<constraints>
369+
<grid row="17" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
370+
</constraints>
371+
<properties>
372+
<text value="Admin Checkout"/>
373+
</properties>
374+
</component>
368375
</children>
369376
</grid>
370377
<hspacer id="75d92">

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
4-
*
54
*/
65

76
package com.magento.idea.magento2plugin.actions.generation.dialog;
@@ -83,6 +82,7 @@ public class NewCustomerEavAttributeDialog extends EavAttributeDialog {
8382
private JCheckBox filterableInGridCheckBox;
8483
private JCheckBox visibleInGridCheckBox;
8584
private JCheckBox systemAttributeCheckBox;
85+
private JCheckBox useInAdminhtmlCheckoutCheckBox;
8686

8787
/**
8888
* Constructor.
@@ -236,6 +236,9 @@ private CustomerEntityData populateCategoryEntityData(
236236
customerEntityData.setUseInAdminhtmlCustomerForm(
237237
useInAdminhtmlCustomerCheckBox.isSelected()
238238
);
239+
customerEntityData.setUseInAdminhtmlCheckoutForm(
240+
useInAdminhtmlCheckoutCheckBox.isSelected()
241+
);
239242
customerEntityData.setUseInCustomerAccountCreateForm(
240243
useInCustomerAccountCreateCheckBox.isSelected()
241244
);
@@ -320,4 +323,8 @@ public void itemStateChanged(final ItemEvent itemEvent) {
320323
}
321324
});
322325
}
326+
327+
private void createUIComponents() {
328+
// TODO: place custom component creation code here
329+
}
323330
}

src/com/magento/idea/magento2plugin/actions/generation/generator/CustomerEavAttributePatchGenerator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ private String getFormsForAttribute(final CustomerEntityData customerEntityData)
8686
);
8787
}
8888

89+
if (customerEntityData.isUseInAdminhtmlCheckoutForm()) {
90+
usedInForms.add(
91+
"'" + CustomerForm.ADMINHTML_CHECKOUT.getFormCode() + "'"
92+
);
93+
}
94+
8995
if (customerEntityData.isUseInCustomerAccountCreateForm()) {
9096
usedInForms.add(
9197
"'" + CustomerForm.CUSTOMER_ACCOUNT_CREATE.getFormCode() + "'"

src/com/magento/idea/magento2plugin/actions/generation/generator/EavAttributeSetupPatchGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ protected void fillAttributes(final Properties attributes) {
7676
.append(
7777
"MODULE_DATA_SETUP_INTERFACE",
7878
DataPatchDependency.MODULE_DATA_SETUP_INTERFACE.getClassPatch()
79+
).append(
80+
"ATTRIBUTE_RESOURCE",
81+
DataPatchDependency.ATTRIBUTE_RESOURCE.getClassPatch()
7982
)
8083
.append(
8184
"EAV_SETUP_FACTORY",

src/com/magento/idea/magento2plugin/magento/packages/eav/DataPatchDependency.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public enum DataPatchDependency {
1111
EAV_CONFIG("Magento\\Eav\\Model\\Config"),
1212
EAV_SETUP_FACTORY("Magento\\Eav\\Setup\\EavSetupFactory"),
1313
ENV_SETUP("Magento\\Eav\\Setup\\EavSetup"),
14-
MODULE_DATA_SETUP_INTERFACE("Magento\\Framework\\Setup\\ModuleDataSetupInterface");
14+
MODULE_DATA_SETUP_INTERFACE("Magento\\Framework\\Setup\\ModuleDataSetupInterface"),
15+
ATTRIBUTE_RESOURCE("Magento\\Customer\\Model\\ResourceModel\\Attribute");
1516

1617
private String classPatch;
1718

testData/actions/generation/generator/CustomerAttributeSetupPatchGenerator/generateMultiselectAttributeDataPatch/AddMultiselectTestCustomerAttribute.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Magento\Customer\Api\CustomerMetadataInterface;
66
use Magento\Customer\Model\Customer;
7+
use Magento\Customer\Model\ResourceModel\Attribute;
78
use Magento\Eav\Model\Config;
89
use Magento\Eav\Setup\EavSetup;
910
use Magento\Eav\Setup\EavSetupFactory;
@@ -27,19 +28,28 @@ class AddMultiselectTestCustomerAttribute implements DataPatchInterface
2728
*/
2829
private $eavConfig;
2930

31+
/**
32+
* @var Attribute
33+
*/
34+
private $attributeResource;
35+
3036
/**
3137
* @param ModuleDataSetupInterface $moduleDataSetup
3238
* @param EavSetupFactory $eavSetupFactory
39+
* @param Config $eavConfig
40+
* @param Attribute $attributeResource
3341
*/
3442
public function __construct(
3543
ModuleDataSetupInterface $moduleDataSetup,
3644
EavSetupFactory $eavSetupFactory,
37-
Config $eavConfig
45+
Config $eavConfig,
46+
Attribute $attributeResource
3847
)
3948
{
4049
$this->moduleDataSetup = $moduleDataSetup;
4150
$this->eavSetupFactory = $eavSetupFactory;
4251
$this->eavConfig = $eavConfig;
52+
$this->attributeResource = $attributeResource;
4353
}
4454

4555
/**
@@ -95,7 +105,7 @@ public function apply()
95105
'used_in_forms',
96106
['adminhtml_customer']
97107
);
98-
$attribute->save();
108+
$this->attributeResource->save($attribute);
99109

100110
return $this;
101111
}

0 commit comments

Comments
 (0)