Question

I have created an attributes using an install script for a custom module. One attribute is a drop-down which only has two options as 'yes','no'. The other attribute is a text field. I need to set default values through this script. I tied the following. But didn't work.

$th =  new Mage_Catalog_Model_Resource_Setup();  
$th->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'credit', array(
            'group' => 'Prices',
            'type' => 'text',
            'backend' => '',
            'frontend' => '',
            'label' => 'Credit rewards',
            'input' => 'text',
            'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
            'visible' => true,
            'required' => false,
            'user_defined' => true,
            'default' => 'kkkkkkkk', // this is default value. but is's not setting
            'searchable' => false,
            'filterable' => true,
            'comparable' => false,
            'visible_on_front' => true,
            'visible_in_advanced_search' => true,
            'used_in_product_listing' => true,
            'unique' => false,
            'apply_to' => 'simple',
        ) );

Any suggestion will be appreciated. Thanks in advanced.

Was it helpful?

Solution

         /**
         * @var $th Mage_Eav_Model_Entity_Setup
         */
        $th =new Mage_Eav_Model_Entity_Setup('core_setup');
        $th->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'credit', array(
            'group'                      => 'Prices',
            'type'                       => 'text',
            'backend'                    => '',
            'frontend'                   => '',
            'label'                      => 'Credit rewards',
            'input'                      => 'text',
            'global'                     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
            'visible'                    => true,
            'required'                   => false,
            'user_defined'               => true,
            'default'                    => 'kkkkkkkk', // this is default value.
            'searchable'                 => false,
            'filterable'                 => true,
            'comparable'                 => false,
            'visible_on_front'           => true,
            'visible_in_advanced_search' => true,
            'used_in_product_listing'    => true,
            'unique'                     => false,
            'apply_to'                   => 'simple',
        ));

OTHER TIPS

     /**
     * @var $th Mage_Eav_Model_Entity_Setup
     */
    $th =new Mage_Eav_Model_Entity_Setup('core_setup');
    $th->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'credit', array(
        'group'                      => 'Prices',
        'type'                       => 'text',
        'backend'                    => '',
        'frontend'                   => '',
        'label'                      => 'Credit rewards',
        'input'                      => 'text',
        'global'                     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'visible'                    => true,
        'required'                   => false,
        'user_defined'               => true,
        'default'                    => 'kkkkkkkk', // this is default value.
        'searchable'                 => false,
        'filterable'                 => true,
        'comparable'                 => false,
        'visible_on_front'           => true,
        'visible_in_advanced_search' => true,
        'used_in_product_listing'    => true,
        'unique'                     => false,
        'apply_to'                   => 'simple',
    ));
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top