Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0"?>
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
- <module name="Vendor_Module" schema_version="0.0.1" setup_version="0.0.1" active="true"/>
- </config>
- <?php
- namespace VendorModuleSetup;
- use MagentoEavSetupEavSetup;
- use MagentoEavSetupEavSetupFactory;
- use MagentoFrameworkSetupInstallDataInterface;
- use MagentoFrameworkSetupModuleContextInterface;
- use MagentoFrameworkSetupModuleDataSetupInterface;
- class InstallData implements InstallDataInterface
- {
- public function __construct(EavSetupFactory $eavSetupFactory)
- {
- $this->eavSetupFactory = $eavSetupFactory;
- }
- public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
- if (version_compare($context->getVersion(), '1.0.0') < 0){
- $objectManager = MagentoFrameworkAppObjectManager::getInstance();
- $customerSetup = $objectManager->create('VendorModuleSetupCustomerSetup');
- $customerSetup->installAttributes($customerSetup);
- }
- }
- }
- <?php
- namespace VendorModuleSetup;
- use MagentoEavModelConfig;
- use MagentoEavModelEntitySetupContext;
- use MagentoEavSetupEavSetup;
- use MagentoFrameworkAppCacheInterface;
- use MagentoFrameworkSetupModuleDataSetupInterface;
- use MagentoEavModelResourceModelEntityAttributeGroupCollectionFactory;
- class CustomerSetup extends EavSetup {
- protected $eavConfig;
- public function __construct(
- ModuleDataSetupInterface $setup,
- Context $context,
- CacheInterface $cache,
- CollectionFactory $attrGroupCollectionFactory,
- Config $eavConfig
- ) {
- $this->eavConfig = $eavConfig;
- parent :: __construct($setup, $context, $cache, $attrGroupCollectionFactory);
- }
- public function installAttributes($customerSetup) {
- $this->installCustomerAttributes($customerSetup);
- $this->installCustomerAddressAttributes($customerSetup);
- }
- public function installCustomerAttributes($customerSetup) {
- $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY,
- 'branding',
- [
- 'label' => 'Branding',
- 'system' => 0,
- 'position' => 100,
- 'sort_order' =>100,
- 'visible' => false,
- 'note' => '',
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => true,
- 'type' => 'int',
- 'input' => 'boolean',
- 'source' => 'MagentoEavModelEntityAttributeSourceBoolean',
- ]
- );
- $customerSetup->getEavConfig()->getAttribute('customer', 'branding')->setData('is_user_defined',0)->setData('is_required',0)->setData('default_value','0')->setData('used_in_forms', ['adminhtml_customer'])->save();
- $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY,
- 'branding_type',
- [
- 'label' => 'Branding Type',
- 'system' => 0,
- 'position' => 101,
- 'sort_order' =>101,
- 'visible' => false,
- 'note' => '',
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => true,
- 'type' => 'varchar',
- 'input' => 'multiselect',
- 'source' => 'VendorModuleModelEntityAttributeSourceOptions',
- 'backend' => 'MagentoEavModelEntityAttributeBackendArrayBackend',
- ]
- );
- $customerSetup->getEavConfig()->getAttribute('customer', 'branding_type')->setData('is_user_defined',0)->setData('is_required',0)->setData('default_value','')->setData('used_in_forms', ['adminhtml_customer'])->save();
- }
- public function installCustomerAddressAttributes($customerSetup) {
- }
- public function getEavConfig() {
- return $this -> eavConfig;
- }
- }
- <?php
- namespace VendorModuleModelEntityAttributeSource;
- use MagentoEavModelEntityAttributeSourceAbstractSource;
- class Options extends AbstractSource
- {
- public function getAllOptions()
- {
- return [
- 'option1' => [
- 'label' => 'Custom Model Numbers',
- 'value' => 'custom_model_numbers'
- ],
- 'option2' => [
- 'label' => 'Camera Logo Stamp',
- 'value' => 'camera_stamp'
- ],
- 'option3' => [
- 'label' => 'Camera GUI',
- 'value' => 'camera_gui'
- ],
- 'option4' => [
- 'label' => 'Recorder Faceplate Decals',
- 'value' => 'recorder_decals'
- ],
- 'option5' => [
- 'label' => 'Recorder GUI',
- 'value' => 'recorder_gui'
- ],
- 'option6' => [
- 'label' => '2GIG Faceplate Stamp',
- 'value' => '2gig_faceplate'
- ]
- ];
- }
- }
- $customerSetup->getEavConfig()->getAttribute('customer', 'branding')->setData('is_user_defined',0)->setData('is_required',0)->setData('default_value','0')->setData('used_in_forms', ['adminhtml_customer', 'customer_account_edit'])->save();
- <?php
- namespace VendorModuleSetup;
- use MagentoEavModelConfig;
- use MagentoEavModelEntitySetupContext;
- use MagentoEavSetupEavSetup;
- use MagentoFrameworkAppCacheInterface;
- use MagentoFrameworkSetupModuleDataSetupInterface;
- use MagentoEavModelResourceModelEntityAttributeGroupCollectionFactory;
- class CustomerSetup extends EavSetup {
- protected $eavConfig;
- public function __construct(
- ModuleDataSetupInterface $setup,
- Context $context,
- CacheInterface $cache,
- CollectionFactory $attrGroupCollectionFactory,
- Config $eavConfig
- ) {
- $this->eavConfig = $eavConfig;
- parent :: __construct($setup, $context, $cache, $attrGroupCollectionFactory);
- }
- public function installAttributes($customerSetup) {
- $this->installCustomerAttributes($customerSetup);
- $this->installCustomerAddressAttributes($customerSetup);
- }
- public function installCustomerAttributes($customerSetup) {
- $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY,
- 'branding',
- [
- 'label' => 'Branding',
- 'system' => 0,
- 'position' => 100,
- 'sort_order' =>100,
- 'visible' => false,
- 'note' => '',
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => true,
- 'type' => 'int',
- 'input' => 'boolean',
- 'source' => 'MagentoEavModelEntityAttributeSourceBoolean',
- ]
- );
- $customerSetup->getEavConfig()->getAttribute('customer', 'branding')->setData('is_user_defined',0)->setData('is_required',0)->setData('default_value','0')->setData('used_in_forms', ['adminhtml_customer', 'customer_account_edit'])->save();
- $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY,
- 'branding_type',
- [
- 'label' => 'Branding Type',
- 'system' => 0,
- 'position' => 101,
- 'sort_order' =>101,
- 'visible' => false,
- 'note' => '',
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => true,
- 'type' => 'varchar',
- 'input' => 'multiselect',
- 'source' => 'VendorModuleModelEntityAttributeSourceOptions',
- 'backend' => 'MagentoEavModelEntityAttributeBackendArrayBackend',
- ]
- );
- $customerSetup->getEavConfig()->getAttribute('customer', 'branding_type')->setData('is_user_defined',0)->setData('is_required',0)->setData('default_value','')->setData('used_in_forms', ['adminhtml_customer'])->save();
- }
- public function installCustomerAddressAttributes($customerSetup) {
- }
- public function getEavConfig() {
- return $this -> eavConfig;
- }
- }
Add Comment
Please, Sign In to add comment