Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefaultCustomerGroupsAndAttributes.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Customer\Setup\CustomerSetupFactory;
16 
22 {
26  private $customerSetupFactory;
27 
31  private $moduleDataSetup;
32 
38  public function __construct(
39  CustomerSetupFactory $customerSetupFactory,
40  \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
41  ) {
42  $this->customerSetupFactory = $customerSetupFactory;
43  $this->moduleDataSetup = $moduleDataSetup;
44  }
45 
50  public function apply()
51  {
53  $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
54 
55  // insert default customer groups
56  $this->moduleDataSetup->getConnection()->insertForce(
57  $this->moduleDataSetup->getTable('customer_group'),
58  ['customer_group_id' => 0, 'customer_group_code' => 'NOT LOGGED IN', 'tax_class_id' => 3]
59  );
60  $this->moduleDataSetup->getConnection()->insertForce(
61  $this->moduleDataSetup->getTable('customer_group'),
62  ['customer_group_id' => 1, 'customer_group_code' => 'General', 'tax_class_id' => 3]
63  );
64  $this->moduleDataSetup->getConnection()->insertForce(
65  $this->moduleDataSetup->getTable('customer_group'),
66  ['customer_group_id' => 2, 'customer_group_code' => 'Wholesale', 'tax_class_id' => 3]
67  );
68  $this->moduleDataSetup->getConnection()->insertForce(
69  $this->moduleDataSetup->getTable('customer_group'),
70  ['customer_group_id' => 3, 'customer_group_code' => 'Retailer', 'tax_class_id' => 3]
71  );
72 
73  $customerSetup->installEntities();
74 
75  $customerSetup->installCustomerForms();
76 
77  $disableAGCAttribute = $customerSetup->getEavConfig()->getAttribute('customer', 'disable_auto_group_change');
78  $disableAGCAttribute->setData('used_in_forms', ['adminhtml_customer']);
79  $disableAGCAttribute->save();
80 
81  $attributesInfo = [
82  'vat_id' => [
83  'label' => 'VAT number',
84  'type' => 'static',
85  'input' => 'text',
86  'position' => 140,
87  'visible' => true,
88  'required' => false,
89  ],
90  'vat_is_valid' => [
91  'label' => 'VAT number validity',
92  'visible' => false,
93  'required' => false,
94  'type' => 'static',
95  ],
96  'vat_request_id' => [
97  'label' => 'VAT number validation request ID',
98  'type' => 'static',
99  'visible' => false,
100  'required' => false,
101  ],
102  'vat_request_date' => [
103  'label' => 'VAT number validation request date',
104  'type' => 'static',
105  'visible' => false,
106  'required' => false,
107  ],
108  'vat_request_success' => [
109  'label' => 'VAT number validation request success',
110  'visible' => false,
111  'required' => false,
112  'type' => 'static',
113  ],
114  ];
115 
116  foreach ($attributesInfo as $attributeCode => $attributeParams) {
117  $customerSetup->addAttribute('customer_address', $attributeCode, $attributeParams);
118  }
119 
120  $vatIdAttribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'vat_id');
121  $vatIdAttribute->setData(
122  'used_in_forms',
123  ['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address']
124  );
125  $vatIdAttribute->save();
126 
127  $entities = $customerSetup->getDefaultEntities();
128  foreach ($entities as $entityName => $entity) {
129  $customerSetup->addEntityType($entityName, $entity);
130  }
131 
132  $customerSetup->updateAttribute(
133  'customer_address',
134  'street',
135  'backend_model',
136  \Magento\Eav\Model\Entity\Attribute\Backend\DefaultBackend::class
137  );
138 
139  $migrationSetup = $this->moduleDataSetup->createMigrationSetup();
140 
141  $migrationSetup->appendClassAliasReplace(
142  'customer_eav_attribute',
143  'data_model',
146  ['attribute_id']
147  );
148  $migrationSetup->doUpdateClassAliases();
149  }
150 
154  public static function getDependencies()
155  {
156  return [];
157  }
158 
162  public static function getVersion()
163  {
164  return '2.0.0';
165  }
166 
170  public function getAliases()
171  {
172  return [];
173  }
174 }
__construct(CustomerSetupFactory $customerSetupFactory, \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup)
$attributeCode
Definition: extend.phtml:12
$entity
Definition: element.phtml:22