1

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

$installer = $this;
$installer->startSetup();
$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'
));

$installer->endSetup();

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Module_Modulename>
            <version>0.1.0</version>
        </Module_Modulename>
    </modules>
    <global>
       <blocks>
           <adminhtml>
               <rewrite>
                   <catalog_product_grid>Module_Modulename_Block_Adminhtml_Catalog_Product_Grid</catalog_product_grid>
               </rewrite>
           </adminhtml>
       </blocks>
            <resources>
                <modulename_setup>
                    <setup>
                        <module>Module_Modulename</module>
                    </setup>
                    <connection>
                        <use>core_setup</use>
                    </connection>
                </modulename_setup>
                <modulename_write>
                    <connection>
                        <use>core_write</use>
                    </connection>
                </modulename_write>
                <modulename_read>
                    <connection>
                        <use>core_read</use>
                    </connection>
                </modulename_read>
            </resources>
    </global>
</config>

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

5
  • the version number in config.xml is 0.1.0 and install script is mysql4-install-0.1.0.php Commented Aug 8, 2016 at 7:17
  • Can you show your config.xml? Commented Aug 8, 2016 at 11:00
  • updated ........... Commented 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. Commented Aug 8, 2016 at 12:07
  • i know, i use VM to restore everytime Commented Aug 8, 2016 at 12:09

1 Answer 1

0

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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.