Guest User

Untitled

a guest
Dec 14th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. <?xml version="1.0"?>
  2. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
  3. <module name="Vendor_Module" schema_version="0.0.1" setup_version="0.0.1" active="true"/>
  4. </config>
  5.  
  6. <?php
  7.  
  8. namespace VendorModuleSetup;
  9.  
  10. use MagentoEavSetupEavSetup;
  11. use MagentoEavSetupEavSetupFactory;
  12. use MagentoFrameworkSetupInstallDataInterface;
  13. use MagentoFrameworkSetupModuleContextInterface;
  14. use MagentoFrameworkSetupModuleDataSetupInterface;
  15.  
  16. class InstallData implements InstallDataInterface
  17. {
  18. public function __construct(EavSetupFactory $eavSetupFactory)
  19. {
  20. $this->eavSetupFactory = $eavSetupFactory;
  21. }
  22.  
  23. public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
  24. {
  25.  
  26. $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
  27. if (version_compare($context->getVersion(), '1.0.0') < 0){
  28.  
  29. $objectManager = MagentoFrameworkAppObjectManager::getInstance();
  30. $customerSetup = $objectManager->create('VendorModuleSetupCustomerSetup');
  31. $customerSetup->installAttributes($customerSetup);
  32. }
  33. }
  34. }
  35.  
  36. <?php
  37.  
  38. namespace VendorModuleSetup;
  39.  
  40. use MagentoEavModelConfig;
  41. use MagentoEavModelEntitySetupContext;
  42. use MagentoEavSetupEavSetup;
  43. use MagentoFrameworkAppCacheInterface;
  44. use MagentoFrameworkSetupModuleDataSetupInterface;
  45. use MagentoEavModelResourceModelEntityAttributeGroupCollectionFactory;
  46.  
  47. class CustomerSetup extends EavSetup {
  48.  
  49. protected $eavConfig;
  50.  
  51. public function __construct(
  52. ModuleDataSetupInterface $setup,
  53. Context $context,
  54. CacheInterface $cache,
  55. CollectionFactory $attrGroupCollectionFactory,
  56. Config $eavConfig
  57. ) {
  58. $this->eavConfig = $eavConfig;
  59. parent :: __construct($setup, $context, $cache, $attrGroupCollectionFactory);
  60. }
  61.  
  62. public function installAttributes($customerSetup) {
  63. $this->installCustomerAttributes($customerSetup);
  64. $this->installCustomerAddressAttributes($customerSetup);
  65. }
  66.  
  67. public function installCustomerAttributes($customerSetup) {
  68.  
  69.  
  70. $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY,
  71. 'branding',
  72. [
  73. 'label' => 'Branding',
  74. 'system' => 0,
  75. 'position' => 100,
  76. 'sort_order' =>100,
  77. 'visible' => false,
  78. 'note' => '',
  79. 'is_used_in_grid' => true,
  80. 'is_visible_in_grid' => true,
  81. 'is_filterable_in_grid' => true,
  82. 'is_searchable_in_grid' => true,
  83.  
  84. 'type' => 'int',
  85. 'input' => 'boolean',
  86. 'source' => 'MagentoEavModelEntityAttributeSourceBoolean',
  87.  
  88. ]
  89. );
  90.  
  91. $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();
  92.  
  93.  
  94.  
  95. $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY,
  96. 'branding_type',
  97. [
  98. 'label' => 'Branding Type',
  99. 'system' => 0,
  100. 'position' => 101,
  101. 'sort_order' =>101,
  102. 'visible' => false,
  103. 'note' => '',
  104. 'is_used_in_grid' => true,
  105. 'is_visible_in_grid' => true,
  106. 'is_filterable_in_grid' => true,
  107. 'is_searchable_in_grid' => true,
  108.  
  109. 'type' => 'varchar',
  110. 'input' => 'multiselect',
  111. 'source' => 'VendorModuleModelEntityAttributeSourceOptions',
  112. 'backend' => 'MagentoEavModelEntityAttributeBackendArrayBackend',
  113. ]
  114. );
  115.  
  116. $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();
  117.  
  118.  
  119. }
  120.  
  121. public function installCustomerAddressAttributes($customerSetup) {
  122.  
  123. }
  124.  
  125. public function getEavConfig() {
  126. return $this -> eavConfig;
  127. }
  128. }
  129.  
  130. <?php
  131.  
  132. namespace VendorModuleModelEntityAttributeSource;
  133.  
  134. use MagentoEavModelEntityAttributeSourceAbstractSource;
  135.  
  136. class Options extends AbstractSource
  137. {
  138. public function getAllOptions()
  139. {
  140. return [
  141. 'option1' => [
  142. 'label' => 'Custom Model Numbers',
  143. 'value' => 'custom_model_numbers'
  144. ],
  145. 'option2' => [
  146. 'label' => 'Camera Logo Stamp',
  147. 'value' => 'camera_stamp'
  148. ],
  149. 'option3' => [
  150. 'label' => 'Camera GUI',
  151. 'value' => 'camera_gui'
  152. ],
  153. 'option4' => [
  154. 'label' => 'Recorder Faceplate Decals',
  155. 'value' => 'recorder_decals'
  156. ],
  157. 'option5' => [
  158. 'label' => 'Recorder GUI',
  159. 'value' => 'recorder_gui'
  160. ],
  161. 'option6' => [
  162. 'label' => '2GIG Faceplate Stamp',
  163. 'value' => '2gig_faceplate'
  164. ]
  165. ];
  166. }
  167. }
  168.  
  169. $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();
  170.  
  171. <?php
  172.  
  173. namespace VendorModuleSetup;
  174.  
  175. use MagentoEavModelConfig;
  176. use MagentoEavModelEntitySetupContext;
  177. use MagentoEavSetupEavSetup;
  178. use MagentoFrameworkAppCacheInterface;
  179. use MagentoFrameworkSetupModuleDataSetupInterface;
  180. use MagentoEavModelResourceModelEntityAttributeGroupCollectionFactory;
  181.  
  182. class CustomerSetup extends EavSetup {
  183.  
  184. protected $eavConfig;
  185.  
  186. public function __construct(
  187. ModuleDataSetupInterface $setup,
  188. Context $context,
  189. CacheInterface $cache,
  190. CollectionFactory $attrGroupCollectionFactory,
  191. Config $eavConfig
  192. ) {
  193. $this->eavConfig = $eavConfig;
  194. parent :: __construct($setup, $context, $cache, $attrGroupCollectionFactory);
  195. }
  196.  
  197. public function installAttributes($customerSetup) {
  198. $this->installCustomerAttributes($customerSetup);
  199. $this->installCustomerAddressAttributes($customerSetup);
  200. }
  201.  
  202. public function installCustomerAttributes($customerSetup) {
  203.  
  204.  
  205. $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY,
  206. 'branding',
  207. [
  208. 'label' => 'Branding',
  209. 'system' => 0,
  210. 'position' => 100,
  211. 'sort_order' =>100,
  212. 'visible' => false,
  213. 'note' => '',
  214. 'is_used_in_grid' => true,
  215. 'is_visible_in_grid' => true,
  216. 'is_filterable_in_grid' => true,
  217. 'is_searchable_in_grid' => true,
  218.  
  219. 'type' => 'int',
  220. 'input' => 'boolean',
  221. 'source' => 'MagentoEavModelEntityAttributeSourceBoolean',
  222.  
  223. ]
  224. );
  225.  
  226. $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();
  227.  
  228.  
  229.  
  230. $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY,
  231. 'branding_type',
  232. [
  233. 'label' => 'Branding Type',
  234. 'system' => 0,
  235. 'position' => 101,
  236. 'sort_order' =>101,
  237. 'visible' => false,
  238. 'note' => '',
  239. 'is_used_in_grid' => true,
  240. 'is_visible_in_grid' => true,
  241. 'is_filterable_in_grid' => true,
  242. 'is_searchable_in_grid' => true,
  243.  
  244. 'type' => 'varchar',
  245. 'input' => 'multiselect',
  246. 'source' => 'VendorModuleModelEntityAttributeSourceOptions',
  247. 'backend' => 'MagentoEavModelEntityAttributeBackendArrayBackend',
  248. ]
  249. );
  250.  
  251. $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();
  252.  
  253.  
  254. }
  255.  
  256. public function installCustomerAddressAttributes($customerSetup) {
  257.  
  258. }
  259.  
  260. public function getEavConfig() {
  261. return $this -> eavConfig;
  262. }
  263. }
Add Comment
Please, Sign In to add comment