Skip to content
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

Customer EAV attribute generation #583

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<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>

Expand Down
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,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