SHARE
TWEET

Untitled

a guest Jan 12th, 2017 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Add customer attribute
  2.  
  3. ```php
  4.  
  5. $installer = $this;
  6.  
  7. $installer->startSetup();
  8.  
  9. $setup = new Mage_Eav_Model_Entity_Setup("core_setup");
  10.  
  11. $entityTypeId     = $setup->getEntityTypeId("customer");
  12. $attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
  13. $attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
  14.  
  15. $attributeCode  = "telephone"; // attribute code wgat will be created
  16.  
  17. $installer->addAttribute(
  18.         "customer",
  19.         $attributeCode,  
  20.         array(
  21.             "type"     => "varchar",
  22.             "backend"  => "",
  23.             "label"    => "Telephone",
  24.             "input"    => "text",
  25.             "source"   => "",
  26.             "visible"  => true,
  27.             "required" => false,
  28.             "default"  => "",
  29.             "frontend" => "",
  30.             "unique"   => false,
  31.             "note"     => "Customer telephone"
  32.         )
  33.     );
  34.  
  35. $attribute = Mage::getSingleton("eav/config")->getAttribute("customer", $attributeCode);
  36.  
  37. $setup->addAttributeToGroup(
  38.             $entityTypeId,
  39.             $attributeSetId,
  40.             $attributeGroupId,
  41.             $attributeCode,
  42.             "100"  // sort_order
  43.         );
  44.  
  45. $usedInForms = array(
  46.                     "adminhtml_customer",
  47.                     "checkout_register",
  48.                     "customer_account_create",
  49.                     "customer_account_edit",
  50.                     "adminhtml_checkout"
  51.                 );
  52.  
  53. $attribute->setData("used_in_forms", $usedInForms)
  54.           ->setData("is_used_for_customer_segment", true)
  55.           ->setData("is_system", 0)
  56.           ->setData("is_user_defined", 1)
  57.           ->setData("is_visible", 1)
  58.           ->setData("sort_order", 100)
  59.           ;
  60.  
  61. $attribute->save();
  62.  
  63. $installer->endSetup();
  64.  
  65. ```
RAW Paste Data
Top