Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is the code for a basic <code>int</code> attribute with <code>text</code> renderer:</p> <pre><code>$installer = $this; $installer-&gt;startSetup(); $setup = new Mage_Eav_Model_Entity_Setup('core_setup'); $entityTypeId = $setup-&gt;getEntityTypeId('customer'); $attributeSetId = $setup-&gt;getDefaultAttributeSetId($entityTypeId); $attributeGroupId = $setup-&gt;getDefaultAttributeGroupId($entityTypeId, $attributeSetId); $setup-&gt;addAttribute('customer', 'your_attribute_code_here', array( 'input' =&gt; 'text', 'type' =&gt; 'int', 'label' =&gt; 'Some textual description', 'visible' =&gt; 1, 'required' =&gt; 0, 'user_defined' =&gt; 1, )); $setup-&gt;addAttributeToGroup( $entityTypeId, $attributeSetId, $attributeGroupId, 'your_attribute_code_here', '999' //sort_order ); $oAttribute = Mage::getSingleton('eav/config')-&gt;getAttribute('customer', 'your_attribute_code_here'); $oAttribute-&gt;setData('used_in_forms', array('adminhtml_customer')); $oAttribute-&gt;save(); $setup-&gt;endSetup(); </code></pre> <p>The unusual step for adding attributes is the <code>setData('used_in_forms')</code> this seems to be unique to customer attributes. Without it, the field won't get rendered, certainly not in the adminhtml anyway. You can see the valid options for this array in the <code>customer_form_attribute</code> database table. </p> <p>In terms of using a <code>select</code> with predefined options, this is what you need: </p> <pre><code>$iAttributeId = $installer-&gt;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&lt;sizeof($aClasses);$iCount++){ $aOption['value']['option'.$iCount][0] = $aClasses[$iCount]; } $setup-&gt;addAttributeOption($aOption); </code></pre> <p>And here is a <a href="http://subesh.com.np/2010/01/creating-custom-sourced-multiselect-product-attribute/" rel="noreferrer">walk-through</a> on using a custom source for your drop-down </p> <p>Hope this helps,<br> JD</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload