Guest User

Untitled

a guest
Jun 25th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. $setup->startSetup();
  2.  
  3. $insertArray = array(
  4. 'profile_picture' => array("type" => "varchar", "label" => "Profile Picture"),
  5. 'security_question_1' => array("type" => "int", "label" => "Security Question 1"),
  6. 'security_question_2' => array("type" => "int", "label" => "Security Question 2"),
  7. 'security_answer_1' => array("type" => "varchar", "label" => "Security Answer 1"),
  8. 'security_answer_2' => array("type" => "varchar", "label" => "Security Answer 2")
  9. );
  10.  
  11. foreach ($insertArray as $key => $data) {
  12. $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
  13.  
  14. $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
  15. $attributeSetId = $customerEntity->getDefaultAttributeSetId();
  16.  
  17. /** @var $attributeSet AttributeSet */
  18. $attributeSet = $this->attributeSetFactory->create();
  19. $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
  20.  
  21. $customerSetup->addAttribute(Customer::ENTITY, $key, [
  22. 'type' => $data['type'],
  23. 'label' => $data['label'],
  24. 'input' => 'text',
  25. 'required' => false,
  26. 'visible' => true,
  27. 'user_defined' => true,
  28. 'sort_order' => 1000,
  29. 'position' => 1000,
  30. 'system' => 0,
  31. ]);
  32.  
  33. $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, $key)
  34. ->addData([
  35. 'attribute_set_id' => $attributeSetId,
  36. 'attribute_group_id' => $attributeGroupId,
  37. 'used_in_forms' => ['adminhtml_customer'],
  38. ]);
  39.  
  40. $attribute->save();
  41. }
  42. $setup->endSetup();
Add Comment
Please, Sign In to add comment