php - Adding attributes to customer entity -


my current goal add new customer attribute (with int type) should appear select predefined options (loaded model entries editable in backend, done). i'm struggling proper use of $installer->addattribute() method, specifying correct source option. other problem new attribute isn't saved eav_entity_attribute table

i'm on magento ce 1.5.1.0

this code basic int attribute text renderer:

$installer = $this; $installer->startsetup();  $setup = new mage_eav_model_entity_setup('core_setup');  $entitytypeid     = $setup->getentitytypeid('customer'); $attributesetid   = $setup->getdefaultattributesetid($entitytypeid); $attributegroupid = $setup->getdefaultattributegroupid($entitytypeid, $attributesetid);  $setup->addattribute('customer', 'your_attribute_code_here', array(     'input'         => 'text',     'type'          => 'int',     'label'         => 'some textual description',     'visible'       => 1,     'required'      => 0,     'user_defined' => 1, ));  $setup->addattributetogroup(  $entitytypeid,  $attributesetid,  $attributegroupid,  'your_attribute_code_here',  '999'  //sort_order );  $oattribute = mage::getsingleton('eav/config')->getattribute('customer', 'your_attribute_code_here'); $oattribute->setdata('used_in_forms', array('adminhtml_customer')); $oattribute->save();  $setup->endsetup(); 

the unusual step adding attributes setdata('used_in_forms') seems unique customer attributes. without it, field won't rendered, not in adminhtml anyway. can see valid options array in customer_form_attribute database table.

in terms of using select predefined options, need:

$iattributeid = $installer->getattributeid($entitytypeid, 'your_attribute_code_here'); $aclasses = array('tv','dvd','home theatre','air conditioner','stereo/hifi','game console','camcorder','vcr','set top box','pvr'); $aoption = array(); $aoption['attribute_id'] = $iattributeid;  for($icount=0;$icount<sizeof($aclasses);$icount++){     $aoption['value']['option'.$icount][0] = $aclasses[$icount]; } $setup->addattributeoption($aoption); 

and here walk-through on using custom source drop-down

hope helps,
jd


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -