Last active
October 1, 2019 07:47
-
-
Save med-amin/f71e1246a8adbe2ebabe61a7137ad547 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Copyright © 2018 . All rights reserved. | |
*/ | |
namespace Test\Test\Setup; | |
use Magento\Customer\Model\Customer; | |
use Magento\Customer\Setup\CustomerSetupFactory; | |
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory; | |
use Magento\Framework\Setup\InstallDataInterface; | |
use Magento\Framework\Setup\ModuleContextInterface; | |
use Magento\Framework\Setup\ModuleDataSetupInterface; | |
/** | |
* @codeCoverageIgnore | |
*/ | |
class InstallData implements InstallDataInterface | |
{ | |
/** | |
* @var CustomerSetupFactory | |
*/ | |
protected $customerSetupFactory; | |
/** | |
* @var AttributeSetFactory | |
*/ | |
private $attributeSetFactory; | |
/** | |
* @param CustomerSetupFactory $customerSetupFactory | |
* @param AttributeSetFactory $attributeSetFactory | |
*/ | |
public function __construct( | |
CustomerSetupFactory $customerSetupFactory, | |
AttributeSetFactory $attributeSetFactory | |
) { | |
$this->customerSetupFactory = $customerSetupFactory; | |
$this->attributeSetFactory = $attributeSetFactory; | |
} | |
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) | |
{ | |
/** @var CustomerSetup $customerSetup */ | |
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); | |
$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); | |
$attributeSetId = $customerEntity->getDefaultAttributeSetId(); | |
/** @var $attributeSet AttributeSet */ | |
$attributeSet = $this->attributeSetFactory->create(); | |
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); | |
// Add club start date | |
$customerSetup->addAttribute( | |
Customer::ENTITY, | |
'club_start_date', | |
[ | |
'type' => 'datetime', | |
'label' => 'Club start date', | |
'input' => 'date', | |
'required' => false, | |
'backend' => \Magento\Eav\Model\Entity\Attribute\Backend\Datetime::class, | |
'frontend' => \Magento\Eav\Model\Entity\Attribute\Frontend\Datetime::class, | |
'sort_order' => 900, | |
'visible' => true, | |
'system' => false, | |
'input_filter' => 'date', | |
'validate_rules' => '{"input_validation":"date"}', | |
'position' => 90, | |
'is_used_in_grid' => true, | |
'is_visible_in_grid' => true, | |
'is_filterable_in_grid' => true, | |
'is_searchable_in_grid' => true | |
] | |
); | |
/** @var $attribute */ | |
$attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'club_start_date'); | |
$attribute->addData([ | |
'used_in_forms', ['adminhtml_customer'], | |
'attribute_group_id' => $attributeGroupId, | |
'attribute_set_id' => $attributeSetId | |
]); | |
$attribute->save(); | |
// Add club end date | |
$customerSetup->addAttribute( | |
Customer::ENTITY, | |
'club_end_date', | |
[ | |
'type' => 'datetime', | |
'label' => 'Club end date', | |
'input' => 'date', | |
'required' => false, | |
'backend' => \Magento\Eav\Model\Entity\Attribute\Backend\Datetime::class, | |
'frontend' => \Magento\Eav\Model\Entity\Attribute\Frontend\Datetime::class, | |
'sort_order' => 900, | |
'visible' => true, | |
'system' => false, | |
'input_filter' => 'date', | |
'validate_rules' => '{"input_validation":"date"}', | |
'position' => 90, | |
'is_used_in_grid' => true, | |
'is_visible_in_grid' => true, | |
'is_filterable_in_grid' => true, | |
'is_searchable_in_grid' => true | |
] | |
); | |
/** @var $attribute */ | |
$attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'club_end_date'); | |
$attribute->addData([ | |
'used_in_forms', ['adminhtml_customer'], | |
'attribute_group_id' => $attributeGroupId, | |
'attribute_set_id' => $attributeSetId | |
]); | |
$setup->getConnection()->addColumn( | |
$setup->getTable('customer_entity'), | |
'club_end_date', | |
[ | |
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATE, | |
'nullable' => true, | |
'comment' => 'Club end Date', | |
] | |
); | |
$setup->getConnection()->addColumn( | |
$setup->getTable('customer_entity'), | |
'club_start_date', | |
[ | |
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATE, | |
'nullable' => true, | |
'comment' => 'Club Start Date', | |
] | |
); | |
$attribute->save(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment