Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is one of the sample code which I had used to create my own custom Product Attribute:-</p> <pre><code>$installer = $this; /* @var $installer Mage_Core_Model_Resource_Setup */ $installer-&gt;startSetup(); $attrCode = 'test2'; $attrGroupName = 'Test Group'; $attrLabel = 'Test 2'; $attrNote = 'Test Note'; $objCatalogEavSetup = Mage::getResourceModel('catalog/eav_mysql4_setup', 'core_setup'); $attrIdTest = $objCatalogEavSetup-&gt;getAttributeId(Mage_Catalog_Model_Product::ENTITY, $attrCode); if ($attrIdTest === false) { $objCatalogEavSetup-&gt;addAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCode, array( 'group' =&gt; $attrGroupName, 'sort_order' =&gt; 7, 'type' =&gt; 'varchar', 'backend' =&gt; '', 'frontend' =&gt; '', 'label' =&gt; $attrLabel, 'note' =&gt; $attrNote, 'input' =&gt; 'text', 'class' =&gt; '', 'source' =&gt; '', 'global' =&gt; Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 'visible' =&gt; true, 'required' =&gt; false, 'user_defined' =&gt; true, 'default' =&gt; '0', 'visible_on_front' =&gt; false, 'unique' =&gt; false, 'is_configurable' =&gt; false, 'used_for_promo_rules' =&gt; true )); } $installer-&gt;endSetup(); </code></pre> <p>This is used with the references of these two articles:-</p> <ul> <li><a href="http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/installing_custom_attributes_with_your_module" rel="noreferrer">Magento Wiki: Installing Custom Attributes with Your Module</a></li> <li><a href="http://blog.chapagain.com.np/magento-adding-attribute-from-mysql-setup-file/" rel="noreferrer">Mukesh Chapagain Blog: Magento Adding attribute from MySQL setup file</a></li> </ul> <p>Also, you will find that I have used the array key "<code>group</code>" to mention the Attribute Group Name, where this new custom Attribute will reside. The irony is that mentioning of this key, in the above code sample, automatically creates this Attribute in every Attribute Set found in this Magento. </p> <p>So you do not need to call any method (like "<code>addAttributeToSet()</code>") to add this Attribute to all Attribute Sets. </p> <p>Hope it helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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