Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <?php
  2. namespace XXXCustomerstatusSetup;
  3. use MagentoCustomerSetupCustomerSetupFactory;
  4. use MagentoCustomerModelCustomer;
  5. use MagentoEavModelEntityAttributeSet as AttributeSet;
  6. use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
  7. use MagentoFrameworkSetupInstallDataInterface;
  8. use MagentoFrameworkSetupModuleContextInterface;
  9. use MagentoFrameworkSetupModuleDataSetupInterface;
  10.  
  11. class InstallData implements InstallDataInterface
  12. {
  13.  
  14. /**
  15. * @var CustomerSetupFactory
  16. */
  17. protected $customerSetupFactory;
  18.  
  19. /**
  20. * @var AttributeSetFactory
  21. */
  22. private $attributeSetFactory;
  23.  
  24. /**
  25. * @param CustomerSetupFactory $customerSetupFactory
  26. * @param AttributeSetFactory $attributeSetFactory
  27. */
  28. public function __construct(
  29. CustomerSetupFactory $customerSetupFactory,
  30. AttributeSetFactory $attributeSetFactory
  31. ) {
  32. $this->customerSetupFactory = $customerSetupFactory;
  33. $this->attributeSetFactory = $attributeSetFactory;
  34. }
  35.  
  36. public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
  37. {
  38. /** @var CustomerSetup $customerSetup */
  39. $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
  40.  
  41. $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
  42. $attributeSetId = $customerEntity->getDefaultAttributeSetId();
  43.  
  44. /** @var $attributeSet AttributeSet */
  45. $attributeSet = $this->attributeSetFactory->create();
  46. $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
  47.  
  48. $customerSetup->addAttribute(Customer::ENTITY, 'custom_customer_status_custom', [
  49. 'type' => 'int',
  50. 'label' => 'Custom Customer Status',
  51. 'input' => 'select',
  52. 'source' => 'MagentoEavModelEntityAttributeSourceTable',
  53. 'required' => false,
  54. 'user_defined' => true,
  55. 'sort_order' => 11,
  56. 'position' => 11,
  57. 'system' => false,
  58. 'option' => ['values' => ['Awaiting Reply', 'Yes', 'No']],
  59. 'is_used_in_grid' => true,
  60. 'is_visible_in_grid' => true,
  61. ]);
  62.  
  63. $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'custom_customer_status_custom')
  64. ->addData([
  65. 'attribute_set_id' => $attributeSetId,
  66. 'attribute_group_id' => $attributeGroupId,
  67. 'used_in_forms' => ['adminhtml_customer'],
  68. ]);
  69.  
  70. $attribute->save();
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement