Skip to content

Mainline EAV attribute generators #999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 79 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
639c881
Created Product attribute setup patch generator
ProkopovVitaliy Apr 6, 2021
485ae55
Added default value for source
ProkopovVitaliy Apr 6, 2021
6f8bdac
Refactored code
ProkopovVitaliy Apr 6, 2021
cafa5d4
Fixed java docs
ProkopovVitaliy Apr 6, 2021
feff1bf
Refactored code
ProkopovVitaliy Apr 6, 2021
fee3d22
Fixed static tests
ProkopovVitaliy Apr 6, 2021
d7d52d0
Removed Unnecessary modifier
ProkopovVitaliy Apr 6, 2021
05ee9b0
Removed singleton
ProkopovVitaliy Apr 6, 2021
e571e6c
Refactored models
ProkopovVitaliy Apr 7, 2021
800e1c9
Created test for generator
ProkopovVitaliy Apr 7, 2021
c1df489
Merge branch 'mainline-eav-attr-code-genearators' of https://github.c…
Apr 7, 2021
e60400f
Merge pull request #527 from ProkopovVitaliy/525-зroduct-attribute-se…
Apr 7, 2021
9515d13
Added source model generation for EAV attribute input
ProkopovVitaliy Apr 9, 2021
d0d0cb4
Merge remote-tracking branch 'origin/mainline-eav-attr-code-genearato…
Apr 9, 2021
8c2d949
Fixed label
ProkopovVitaliy Apr 9, 2021
f59095f
Added copyright
ProkopovVitaliy Apr 9, 2021
c75f0d4
Merge pull request #534 from ProkopovVitaliy/532-source-model-generat…
Apr 9, 2021
1714449
Refactored eav attribute generator
ProkopovVitaliy Apr 10, 2021
e2b9371
Refactored source model generation
ProkopovVitaliy Apr 11, 2021
1ad8406
Fixed directory for source model
ProkopovVitaliy Apr 11, 2021
b6cd7a9
Refactored generators
ProkopovVitaliy Apr 12, 2021
2f0b610
Changed source model template
ProkopovVitaliy Apr 12, 2021
305f66b
Merge pull request #538 from ProkopovVitaliy/eav-attribute-generation…
Apr 12, 2021
4fa88f8
Added apply_to property for attribute generation
ProkopovVitaliy Apr 12, 2021
250390c
Added test for apply_to property
ProkopovVitaliy Apr 12, 2021
631cae5
Added test for apply_to property
ProkopovVitaliy Apr 12, 2021
1ea811d
Fixed panel size
ProkopovVitaliy Apr 12, 2021
fb65c63
Merge branch '4.0.0-develop' of github.com:magento/magento2-phpstorm-…
Apr 12, 2021
731b667
Added indexer for product types
ProkopovVitaliy Apr 13, 2021
2dd86f4
Added possibility to set options
ProkopovVitaliy Apr 14, 2021
38d9892
Fixed field content
ProkopovVitaliy Apr 14, 2021
b30c699
Merge pull request #540 from ProkopovVitaliy/539-add-apply-to-property
eduard13 Apr 15, 2021
d5e2476
Merge branch 'mainline-eav-attr-code-genearators' into 545-attribute-…
ProkopovVitaliy Apr 15, 2021
200e7c9
Merge pull request #546 from ProkopovVitaliy/545-attribute-options
Apr 16, 2021
c995db4
Refactored base eav attribute dialog hierarchy
ProkopovVitaliy Apr 17, 2021
b8dcda7
Fixed classes after refactoring
ProkopovVitaliy Apr 18, 2021
896ea26
Implemented CR recommendation
ProkopovVitaliy Apr 19, 2021
424a66b
Renamed util class
ProkopovVitaliy Apr 19, 2021
6a5541c
Merge pull request #561 from ProkopovVitaliy/560-eav-attribute-genera…
Apr 19, 2021
6686d97
Added category dialog and generation, refactored structure
ProkopovVitaliy Apr 19, 2021
899b3f9
Added category dialog and generation, refactored code
ProkopovVitaliy Apr 21, 2021
2c06892
Renamed tests for product eav entity
ProkopovVitaliy Apr 21, 2021
6982520
Added test for category attribute generator
ProkopovVitaliy Apr 21, 2021
a939aa6
Merge pull request #569 from ProkopovVitaliy/563-category-attribute-g…
eduard13 Apr 22, 2021
66ef883
Refactored and improved eav attribute generations. Moved fields on th…
ProkopovVitaliy Apr 23, 2021
0e114f8
Multiple improvements to EAV generators
eduard13 Apr 23, 2021
4078a6b
Merge pull request #575 from eduard13/eav-generators-improvements-1
Apr 23, 2021
0e512d9
Fixed code style
ProkopovVitaliy Apr 23, 2021
5531aab
Fixed code style
ProkopovVitaliy Apr 23, 2021
8e98626
Moved properties in new block
ProkopovVitaliy Apr 26, 2021
be50c80
Merge branch 'mainline-eav-attr-code-genearators' into eav-generator-…
eduard13 Apr 26, 2021
54855a9
Adding copyrights
eduard13 Apr 26, 2021
b6569ba
Merge pull request #574 from ProkopovVitaliy/eav-generator-refactoring
eduard13 Apr 26, 2021
2f6c738
Added customer attribute generation
ProkopovVitaliy Apr 29, 2021
db4da15
Fixed dialog issue, added testes
ProkopovVitaliy Apr 29, 2021
83c9bd0
Merge branch '4.0.0-develop' of github.com:magento/magento2-phpstorm-…
May 3, 2021
077c19a
Fixing the scope selection
eduard13 May 5, 2021
df3b748
Merge pull request #587 from eduard13/eav-generators-improvements-2
May 14, 2021
fcecdd5
Merge branch '4.3.0-develop' of github.com:magento/magento2-phpstorm-…
Feb 15, 2022
b6c0342
Merge branch 'mainline-eav-attr-code-genearators' of github.com:magen…
Feb 15, 2022
94a915a
Code review adjustments
Feb 15, 2022
9fc3b44
Try running CI by regex attempt 1
Feb 15, 2022
d775553
Static fixes
Feb 15, 2022
2db8e9e
Experiment with branch names
Feb 15, 2022
2a18b00
Experiment with --stacktrace
Feb 15, 2022
db87c3a
Experiment with ACTIONS_STEP_DEBUG
Feb 15, 2022
a05a21f
Static fixes
Feb 15, 2022
870497f
Static fixes and test fixes
Feb 15, 2022
df550bd
Static fixes Checkstyle
Feb 15, 2022
9d6cebb
Fixed copyright
Feb 15, 2022
5af5127
Merge pull request #583 from ProkopovVitaliy/customer-aev-attribute-g…
Feb 16, 2022
5516798
Merge branch '4.3.0-develop' into mainline-eav-attr-code-genearators
Feb 17, 2022
9f79e0b
Merge branch '4.3.0-develop' into mainline-eav-attr-code-genearators
Feb 18, 2022
c27e398
Static fixes
Feb 18, 2022
16cc2fd
Merge remote-tracking branch 'origin/mainline-eav-attr-code-genearato…
Feb 18, 2022
645e5aa
Removed a general suppression, used a certain instead
Feb 18, 2022
3f3a956
Fixed test
Feb 18, 2022
b0172d3
Merge branch '4.3.0-develop' of github.com:magento/magento2-phpstorm-…
Mar 25, 2022
432e334
Merge branch '4.3.0-develop' of github.com:magento/magento2-phpstorm-…
Mar 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Run automated tests

on:
pull_request:
branches: [ master, 4.3.0-develop ]
branches: [ master, '*-develop', 'mainline*' ]

jobs:
build-linux:
Expand Down Expand Up @@ -107,6 +107,7 @@ jobs:
run: ./gradlew checkstyleCI -i --no-daemon
env:
MODIFIED_FILES: ${{ steps.file_changes.outputs.files}}
ACTIONS_STEP_DEBUG: true
- name: Run PMD Quality Check
run: ./gradlew pmdCI -i --no-daemon
env:
Expand Down
9 changes: 9 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@
<add-to-group group-id="NewGroup" anchor="last"/>
</group>

<!-- Eav Attribute generators -->
<group id="NewEavAttributeGroup" class="com.magento.idea.magento2plugin.actions.groups.NewEavAttributeGroup" text="Magento 2 EAV Attribute" popup="true">
<action id="NewProductEavAttribute" class="com.magento.idea.magento2plugin.actions.generation.eavattribute.NewProductEavAttributeAction" />
<action id="NewCatalogEavAttribute" class="com.magento.idea.magento2plugin.actions.generation.eavattribute.NewCategoryEavAttributeAction" />
<action id="NewCustomerAttribute" class="com.magento.idea.magento2plugin.actions.generation.NewCustomerEavAttributeAction" />
<add-to-group group-id="MagentoNewModuleFileGroup" anchor="last"/>
</group>

<!-- Complex generators -->
<group id="MagentoNewGroup">
<action id="Magento2NewModule" class="com.magento.idea.magento2plugin.actions.generation.NewModuleAction"/>
Expand Down Expand Up @@ -200,6 +208,7 @@
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex" />
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.DeclarativeSchemaElementsIndex" />
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.UIComponentIndex" />
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.ProductTypeIndex" />

<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginTargetLineMarkerProvider"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#if(${INCLUDE_FIELDSET})
<fieldset name="${FIELDSET_NAME}">
#end
<field name="${FIELD_NAME}" sortOrder="${SORT_ORDER}" formElement="${FORM_ELEMENT}"/>
#if(${INCLUDE_FIELDSET})
</fieldset>
#end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php
#parse("PHP File Header.php")
#if (${NAMESPACE})
namespace ${NAMESPACE};
#end

#set ($uses = ${USES})
#foreach ($use in $uses.split(","))
use $use;
#end

class ${CLASS_NAME} implements ${IMPLEMENTS}
{
/**
* @var ${MODULE_DATA_SETUP_INTERFACE}
*/
private $moduleDataSetup;

/**
* @var ${EAV_SETUP_FACTORY}
*/
private $eavSetupFactory;

/**
* @var ${EAV_CONFIG_CLASS}
*/
private $eavConfig;

/**
* @var ${ATTRIBUTE_RESOURCE}
*/
private $attributeResource;

/**
* @param ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup
* @param ${EAV_SETUP_FACTORY} $eavSetupFactory
* @param ${EAV_CONFIG_CLASS} $eavConfig
* @param ${ATTRIBUTE_RESOURCE} $attributeResource
*/
public function __construct(
${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup,
${EAV_SETUP_FACTORY} $eavSetupFactory,
${EAV_CONFIG_CLASS} $eavConfig,
${ATTRIBUTE_RESOURCE} $attributeResource
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->eavSetupFactory = $eavSetupFactory;
$this->eavConfig = $eavConfig;
$this->attributeResource = $attributeResource;
}

/**
* Run code inside patch
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
* means run PatchInterface::revert()
*
* If we speak about data, under revert means: $transaction->rollback()
*
* @return $this
*/
public function apply()
{
/** @var ${EAV_SETUP} $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);

$eavSetup->addAttribute(
${ENTITY_CLASS}::ENTITY,
'${ATTRIBUTE_CODE}',
[
#set ($attributeSet = ${ATTRIBUTE_SET})
#foreach ($attribute in $attributeSet.split("->"))
$attribute
#end
]
);

$eavSetup->addAttributeToSet(
${CUSTOMER_METADATA_INTERFACE}::ENTITY_TYPE_CUSTOMER,
${CUSTOMER_METADATA_INTERFACE}::ATTRIBUTE_SET_ID_CUSTOMER,
null,
'${ATTRIBUTE_CODE}'
);

#if (${CUSTOMER_FORMS})
$attribute = $this->eavConfig->getAttribute(${ENTITY_CLASS}::ENTITY, '${ATTRIBUTE_CODE}');
$attribute->setData(
'used_in_forms',
[${CUSTOMER_FORMS}]
);
$this->attributeResource->save($attribute);
#end

return $this;
}

/**
* Get array of patches that have to be executed prior to this.
*
* Example of implementation:
*
* [
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
* ]
*
* @return string[]
*/
public static function getDependencies()
{
return [];
}

/**
* Get aliases (previous names) for the patch.
*
* @return string[]
*/
public function getAliases()
{
return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<html lang="en">
<body>
<font face="verdana" size="-1">
<p>
Data patch for the customer EAV attribute
</p>
</font>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
#parse("PHP File Header.php")
#if (${NAMESPACE})

namespace ${NAMESPACE};
#end

#set ($uses = ${USES})
#foreach ($use in $uses.split(","))
use $use;
#end

class ${CLASS_NAME} implements ${IMPLEMENTS} {

/**
* @var ${MODULE_DATA_SETUP_INTERFACE}
*/
private $moduleDataSetup;

/**
* @var ${EAV_SETUP_FACTORY}
*/
private $eavSetupFactory;

/**
* @param ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup
* @param ${EAV_SETUP_FACTORY} $eavSetupFactory
*/
public function __construct(
${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup,
${EAV_SETUP_FACTORY} $eavSetupFactory
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->eavSetupFactory = $eavSetupFactory;
}

/**
* Run code inside patch
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
* means run PatchInterface::revert()
*
* If we speak about data, under revert means: $transaction->rollback()
*/
public function apply()
{
/** @var ${EAV_SETUP} $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);

$eavSetup->addAttribute(
${ENTITY_CLASS}::ENTITY,
'${ATTRIBUTE_CODE}',
[
#set ($attributeSet = ${ATTRIBUTE_SET})
#foreach ($attribute in $attributeSet.split("->"))
$attribute
#end
]
);
}

/**
* Get array of patches that have to be executed prior to this.
*
* Example of implementation:
*
* [
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
* ]
*
* @return string[]
*/
public static function getDependencies()
{
return [];
}

/**
* Get aliases (previous names) for the patch.
*
* @return string[]
*/
public function getAliases()
{
return [];
}
}
22 changes: 22 additions & 0 deletions resources/fileTemplates/internal/Magento Source Model Class.php.ft
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
#parse("PHP File Header.php")

namespace ${NAMESPACE};

#set ($uses = ${USES})
#foreach ($use in $uses.split(","))
use $use;
#end

class ${NAME} extends ${EXTENDS}
{
/**
* Retrieve All options
*
* @return array
*/
public function getAllOptions(): array
{
return [];
}
}
1 change: 1 addition & 0 deletions resources/magento2/validation.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ validator.arrayValuesDialog.namesMustBeUnique=Duplicated items names
validator.arrayValuesDialog.nameMustNotBeEmpty=The array name cannot be empty
validator.layoutNameRuleInvalid=The layout name is invalid
validator.layoutNameUnderscoreQtyInvalid=Wrong layout name, please check
validator.commaSeparatedString.isNotValid=The {0} field must contain comma separated string without whitespaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation;

import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;
import com.magento.idea.magento2plugin.MagentoIcons;
import com.magento.idea.magento2plugin.actions.generation.dialog.NewCustomerEavAttributeDialog;
import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog;
import com.magento.idea.magento2plugin.actions.generation.eavattribute.NewEavAttributeAction;

public class NewCustomerEavAttributeAction extends NewEavAttributeAction {

public static final String ACTION_NAME = "Customer Attribute";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Customer Attribute";

public NewCustomerEavAttributeAction() {
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
}

@Override
protected EavAttributeDialog getDialogWindow(
final Project project,
final PsiDirectory directory
) {
return new NewCustomerEavAttributeDialog(project, directory, ACTION_NAME);
}
}
Loading