Skip to content

Commit 639c881

Browse files
Created Product attribute setup patch generator
1 parent f612120 commit 639c881

19 files changed

+1363
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<action id="MagentoCreateADataModel" class="com.magento.idea.magento2plugin.actions.generation.NewDataModelAction" />
7373
<action id="MagentoMessageQueue" class="com.magento.idea.magento2plugin.actions.generation.NewMessageQueueAction" />
7474
<action id="NewDbSchema" class="com.magento.idea.magento2plugin.actions.generation.NewDbSchemaAction" />
75+
<action id="NewEavAttribute" class="com.magento.idea.magento2plugin.actions.generation.NewEavAttributeAction" />
7576
<add-to-group group-id="NewGroup" anchor="last"/>
7677
</group>
7778

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
#if (${NAMESPACE})
4+
5+
namespace ${NAMESPACE};
6+
#end
7+
8+
#set ($uses = ${USES})
9+
#foreach ($use in $uses.split(","))
10+
use $use;
11+
#end
12+
13+
class ${NAME} implements ${IMPLEMENTS} {
14+
15+
/**
16+
* @var ${MODULE_DATA_SETUP_INTERFACE}
17+
*/
18+
private $moduleDataSetup;
19+
20+
/**
21+
* @var ${EAV_SETUP_FACTORY}
22+
*/
23+
private $eavSetupFactory;
24+
25+
/**
26+
* AddRecommendedAttribute constructor.
27+
*
28+
* @param ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup
29+
* @param ${EAV_SETUP_FACTORY} $eavSetupFactory
30+
*/
31+
public function __construct(
32+
${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup,
33+
${EAV_SETUP_FACTORY} $eavSetupFactory
34+
) {
35+
$this->moduleDataSetup = $moduleDataSetup;
36+
$this->eavSetupFactory = $eavSetupFactory;
37+
}
38+
39+
/**
40+
* Get array of patches that have to be executed prior to this.
41+
*
42+
* Example of implementation:
43+
*
44+
* [
45+
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
46+
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
47+
* ]
48+
*
49+
* @return string[]
50+
*/
51+
public static function getDependencies()
52+
{
53+
return [];
54+
}
55+
56+
/**
57+
* Get aliases (previous names) for the patch.
58+
*
59+
* @return string[]
60+
*/
61+
public function getAliases()
62+
{
63+
return [];
64+
}
65+
66+
/**
67+
* Run code inside patch
68+
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
69+
* means run PatchInterface::revert()
70+
*
71+
* If we speak about data, under revert means: $transaction->rollback()
72+
*
73+
* @return $this
74+
*/
75+
public function apply()
76+
{
77+
/** @var ${EAV_SETUP} $eavSetup */
78+
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
79+
80+
$eavSetup->addAttribute(
81+
${ENTITY_CLASS}::ENTITY,
82+
'${ATTRIBUTE_CODE}',
83+
[
84+
#set ($attributeSet = ${ATTRIBUTE_SET})
85+
#foreach ($attribute in $attributeSet.split(","))
86+
$attribute,
87+
#end
88+
]
89+
);
90+
}
91+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.magento.idea.magento2plugin.actions.generation;
2+
3+
import com.intellij.ide.IdeView;
4+
import com.intellij.openapi.actionSystem.*;
5+
import com.intellij.openapi.project.Project;
6+
import com.intellij.psi.PsiDirectory;
7+
import com.magento.idea.magento2plugin.MagentoIcons;
8+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewEavAttributeDialog;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
public class NewEavAttributeAction extends AnAction {
12+
public static final String ACTION_NAME = "Magento 2 EAV Attribute";
13+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Attribute";
14+
15+
public NewEavAttributeAction() {
16+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
17+
}
18+
19+
@Override
20+
public void actionPerformed(@NotNull AnActionEvent e) {
21+
final DataContext dataContext = e.getDataContext();
22+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
23+
if (view == null) {
24+
return;
25+
}
26+
27+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
28+
if (project == null) {
29+
return;
30+
}
31+
32+
final PsiDirectory directory = view.getOrChooseDirectory();
33+
if (directory == null) {
34+
return;
35+
}
36+
37+
NewEavAttributeDialog.open(project, directory);
38+
}
39+
40+
@Override
41+
public boolean isDumbAware() {
42+
return false;
43+
}
44+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.magento.idea.magento2plugin.actions.generation.data;
2+
3+
public interface EavEntityDataInterface {
4+
public String getCode();
5+
public String getType();
6+
public String getLabel();
7+
public String getInput();
8+
public String getNamespace();
9+
public String getModuleName();
10+
public String getDirectory();
11+
public String getDataPatchName();
12+
public String getEntityClass();
13+
}
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
package com.magento.idea.magento2plugin.actions.generation.data;
2+
3+
import com.magento.idea.magento2plugin.magento.packages.eav.EavEntities;
4+
5+
public class ProductEntityData implements EavEntityDataInterface {
6+
private String group;
7+
private String code;
8+
private String type;
9+
private String label;
10+
private String input;
11+
private String source;
12+
private String scope;
13+
private boolean isRequired = false;
14+
private boolean isUsedInGrid = false;
15+
private boolean isVisibleInGrid = false;
16+
private boolean isFilterableInGrid = false;
17+
private boolean isVisible = true;
18+
private boolean isHtmlAllowedOnFront = false;
19+
private boolean isVisibleOnFront = false;
20+
private int sortOrder = 0;
21+
22+
private String dataPatchName;
23+
private String namespace;
24+
private String directory;
25+
private String moduleName;
26+
27+
public void setGroup(String group) {
28+
this.group = group;
29+
}
30+
31+
public void setCode(String code) {
32+
this.code = code;
33+
}
34+
35+
public void setType(String type) {
36+
this.type = type;
37+
}
38+
39+
public void setLabel(String label) {
40+
this.label = label;
41+
}
42+
43+
public void setInput(String input) {
44+
this.input = input;
45+
}
46+
47+
public void setSource(String source) {
48+
this.source = source;
49+
}
50+
51+
public void setScope(String scope) {
52+
this.scope = scope;
53+
}
54+
55+
public void setRequired(boolean required) {
56+
isRequired = required;
57+
}
58+
59+
public void setUsedInGrid(boolean usedInGrid) {
60+
isUsedInGrid = usedInGrid;
61+
}
62+
63+
public void setVisibleInGrid(boolean visibleInGrid) {
64+
isVisibleInGrid = visibleInGrid;
65+
}
66+
67+
public void setFilterableInGrid(boolean filterableInGrid) {
68+
isFilterableInGrid = filterableInGrid;
69+
}
70+
71+
public void setVisible(boolean visible) {
72+
isVisible = visible;
73+
}
74+
75+
public void setHtmlAllowedOnFront(boolean htmlAllowedOnFront) {
76+
isHtmlAllowedOnFront = htmlAllowedOnFront;
77+
}
78+
79+
public void setVisibleOnFront(boolean visibleOnFront) {
80+
isVisibleOnFront = visibleOnFront;
81+
}
82+
83+
public void setSortOrder(int sortOrder) {
84+
this.sortOrder = sortOrder;
85+
}
86+
87+
public void setDataPatchName(String dataPatchName) {
88+
this.dataPatchName = dataPatchName;
89+
}
90+
91+
public void setNamespace(String namespace) {
92+
this.namespace = namespace;
93+
}
94+
95+
public void setDirectory(String directory) {
96+
this.directory = directory;
97+
}
98+
99+
public void setModuleName(String moduleName) {
100+
this.moduleName = moduleName;
101+
}
102+
103+
public String getCode() {
104+
return code;
105+
}
106+
107+
public String getType() {
108+
return type;
109+
}
110+
111+
public String getLabel() {
112+
return label;
113+
}
114+
115+
public String getInput() {
116+
return input;
117+
}
118+
119+
public String getGroup() {
120+
return group;
121+
}
122+
123+
public String getNamespace() {
124+
return namespace;
125+
}
126+
127+
public String getModuleName() {
128+
return moduleName;
129+
}
130+
131+
public String getDirectory() {
132+
return directory;
133+
}
134+
135+
public String getDataPatchName() {
136+
return dataPatchName;
137+
}
138+
139+
public String getSource() {
140+
return source;
141+
}
142+
143+
public String getScope() {
144+
return scope;
145+
}
146+
147+
public boolean isRequired() {
148+
return isRequired;
149+
}
150+
151+
public boolean isUsedInGrid() {
152+
return isUsedInGrid;
153+
}
154+
155+
public boolean isVisibleInGrid() {
156+
return isVisibleInGrid;
157+
}
158+
159+
public boolean isFilterableInGrid() {
160+
return isFilterableInGrid;
161+
}
162+
163+
public boolean isVisible() {
164+
return isVisible;
165+
}
166+
167+
public boolean isHtmlAllowedOnFront() {
168+
return isHtmlAllowedOnFront;
169+
}
170+
171+
public boolean isVisibleOnFront() {
172+
return isVisibleOnFront;
173+
}
174+
175+
public int getSortOrder() {
176+
return sortOrder;
177+
}
178+
179+
@Override
180+
public String getEntityClass() {
181+
return EavEntities.PRODUCT.getEntityClass();
182+
}
183+
}

0 commit comments

Comments
 (0)