i've a setup script in \app\code\local\Namespace\Modulename\sql\modulename_setup

$installer = $this;
$installer->addAttribute('catalog_product', 'supplier', array(
  'type'              => 'varchar',
  'backend'           => 'eav/entity_attribute_backend_array',
  'frontend'          => '',
  'label'             => 'Supplier',
  'input'             => 'select',
  'class'             => '',
  'source'            => 'modulename/source_option',
  'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
  'visible'           => true,
  'required'          => true,
  'user_defined'      => true,
  'default'           => '',
  'searchable'        => false,
  'filterable'        => false,
  'comparable'        => false,
  'option'            => array ('value' => 
                               array('optionone' => array('Sony'),
                                     'optiontwo' => array('Samsung'),
                                     'optionthree' => array('Apple'),                                                
  'visible_on_front'  => false,
  'unique'            => false,
  'group'             => 'Default'



<?xml version="1.0"?>

i want to add a attribute to default group for every product type, but it didn't run, anyone know what is the problem?

  • the version number in config.xml is 0.1.0 and install script is mysql4-install-0.1.0.php
    – hkguile
    Aug 8, 2016 at 7:17
  • Can you show your config.xml? Aug 8, 2016 at 11:00
  • updated ...........
    – hkguile
    Aug 8, 2016 at 11:47
  • 1
    If you ran the setup once, and a row is in the setup table for your version, the setup script won't run a second time. You need to remove that from the database. Check module entry in "core_resource table" table. Aug 8, 2016 at 12:07
  • i know, i use VM to restore everytime
    – hkguile
    Aug 8, 2016 at 12:09

1 Answer 1


You can try this code to add your attribute to one attribute set

// make sure they are all in the default set:
$attributeCode        = 'supplier';
$group_name           = 'General';
$entityTypeId         = $installer->getEntityTypeId('catalog_product');
$eav_setup            = new Mage_Eav_Model_Entity_Setup('core_setup');

$attributeSets = $installer->_conn->fetchAll('select * from '.$this->getTable('eav/attribute_set').' where entity_type_id=?', $entityTypeId);

foreach ($attributeSets as $attributeSet) {
    //-------------- add attribute to set and group
    $attribute_set_id   = $attributeSet['attribute_set_id'];
    $attribute_group_id = $eav_setup->getAttributeGroupId('catalog_product', $attribute_set_id, $group_name);
    $attribute_id       = $eav_setup->getAttributeId('catalog_product', $attributeCode);

     $eav_setup->addAttributeToSet($entityTypeId='catalog_product',$attribute_set_id, $attribute_group_id, $attribute_id);


And in your code, the line

 'group'             => 'Default'

is not required at all or should look like

'group'             => 'General'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.