Skip to content

Commit 5af5127

Browse files
author
Vitaliy
authored
Merge pull request #583 from ProkopovVitaliy/customer-aev-attribute-generation
Customer EAV attribute generation
2 parents fcecdd5 + 9d6cebb commit 5af5127

23 files changed

+1734
-32
lines changed

.github/workflows/gradle.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: Run automated tests
55

66
on:
77
pull_request:
8-
branches: [ master, 4.3.0-develop ]
8+
branches: [ master, '*-develop', 'mainline*' ]
99

1010
jobs:
1111
build-linux:
@@ -107,6 +107,7 @@ jobs:
107107
run: ./gradlew checkstyleCI -i --no-daemon
108108
env:
109109
MODIFIED_FILES: ${{ steps.file_changes.outputs.files}}
110+
ACTIONS_STEP_DEBUG: true
110111
- name: Run PMD Quality Check
111112
run: ./gradlew pmdCI -i --no-daemon
112113
env:

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<group id="NewEavAttributeGroup" class="com.magento.idea.magento2plugin.actions.groups.NewEavAttributeGroup" text="Magento 2 EAV Attribute" popup="true">
9898
<action id="NewProductEavAttribute" class="com.magento.idea.magento2plugin.actions.generation.eavattribute.NewProductEavAttributeAction" />
9999
<action id="NewCatalogEavAttribute" class="com.magento.idea.magento2plugin.actions.generation.eavattribute.NewCategoryEavAttributeAction" />
100+
<action id="NewCustomerAttribute" class="com.magento.idea.magento2plugin.actions.generation.NewCustomerEavAttributeAction" />
100101
<add-to-group group-id="MagentoNewModuleFileGroup" anchor="last"/>
101102
</group>
102103

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
#if (${NAMESPACE})
4+
namespace ${NAMESPACE};
5+
#end
6+
7+
#set ($uses = ${USES})
8+
#foreach ($use in $uses.split(","))
9+
use $use;
10+
#end
11+
12+
class ${CLASS_NAME} implements ${IMPLEMENTS}
13+
{
14+
/**
15+
* @var ${MODULE_DATA_SETUP_INTERFACE}
16+
*/
17+
private $moduleDataSetup;
18+
19+
/**
20+
* @var ${EAV_SETUP_FACTORY}
21+
*/
22+
private $eavSetupFactory;
23+
24+
/**
25+
* @var ${EAV_CONFIG_CLASS}
26+
*/
27+
private $eavConfig;
28+
29+
/**
30+
* @var ${ATTRIBUTE_RESOURCE}
31+
*/
32+
private $attributeResource;
33+
34+
/**
35+
* @param ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup
36+
* @param ${EAV_SETUP_FACTORY} $eavSetupFactory
37+
* @param ${EAV_CONFIG_CLASS} $eavConfig
38+
* @param ${ATTRIBUTE_RESOURCE} $attributeResource
39+
*/
40+
public function __construct(
41+
${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup,
42+
${EAV_SETUP_FACTORY} $eavSetupFactory,
43+
${EAV_CONFIG_CLASS} $eavConfig,
44+
${ATTRIBUTE_RESOURCE} $attributeResource
45+
) {
46+
$this->moduleDataSetup = $moduleDataSetup;
47+
$this->eavSetupFactory = $eavSetupFactory;
48+
$this->eavConfig = $eavConfig;
49+
$this->attributeResource = $attributeResource;
50+
}
51+
52+
/**
53+
* Run code inside patch
54+
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
55+
* means run PatchInterface::revert()
56+
*
57+
* If we speak about data, under revert means: $transaction->rollback()
58+
*
59+
* @return $this
60+
*/
61+
public function apply()
62+
{
63+
/** @var ${EAV_SETUP} $eavSetup */
64+
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
65+
66+
$eavSetup->addAttribute(
67+
${ENTITY_CLASS}::ENTITY,
68+
'${ATTRIBUTE_CODE}',
69+
[
70+
#set ($attributeSet = ${ATTRIBUTE_SET})
71+
#foreach ($attribute in $attributeSet.split("->"))
72+
$attribute
73+
#end
74+
]
75+
);
76+
77+
$eavSetup->addAttributeToSet(
78+
${CUSTOMER_METADATA_INTERFACE}::ENTITY_TYPE_CUSTOMER,
79+
${CUSTOMER_METADATA_INTERFACE}::ATTRIBUTE_SET_ID_CUSTOMER,
80+
null,
81+
'${ATTRIBUTE_CODE}'
82+
);
83+
84+
#if (${CUSTOMER_FORMS})
85+
$attribute = $this->eavConfig->getAttribute(${ENTITY_CLASS}::ENTITY, '${ATTRIBUTE_CODE}');
86+
$attribute->setData(
87+
'used_in_forms',
88+
[${CUSTOMER_FORMS}]
89+
);
90+
$this->attributeResource->save($attribute);
91+
#end
92+
93+
return $this;
94+
}
95+
96+
/**
97+
* Get array of patches that have to be executed prior to this.
98+
*
99+
* Example of implementation:
100+
*
101+
* [
102+
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
103+
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
104+
* ]
105+
*
106+
* @return string[]
107+
*/
108+
public static function getDependencies()
109+
{
110+
return [];
111+
}
112+
113+
/**
114+
* Get aliases (previous names) for the patch.
115+
*
116+
* @return string[]
117+
*/
118+
public function getAliases()
119+
{
120+
return [];
121+
}
122+
}
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>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation;
7+
8+
import com.intellij.openapi.project.Project;
9+
import com.intellij.psi.PsiDirectory;
10+
import com.magento.idea.magento2plugin.MagentoIcons;
11+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewCustomerEavAttributeDialog;
12+
import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog;
13+
import com.magento.idea.magento2plugin.actions.generation.eavattribute.NewEavAttributeAction;
14+
15+
public class NewCustomerEavAttributeAction extends NewEavAttributeAction {
16+
17+
public static final String ACTION_NAME = "Customer Attribute";
18+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Customer Attribute";
19+
20+
public NewCustomerEavAttributeAction() {
21+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
22+
}
23+
24+
@Override
25+
protected EavAttributeDialog getDialogWindow(
26+
final Project project,
27+
final PsiDirectory directory
28+
) {
29+
return new NewCustomerEavAttributeDialog(project, directory, ACTION_NAME);
30+
}
31+
}

0 commit comments

Comments
 (0)