3

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.

5
         /**
         * @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',
        ));
  • I want to add a product attribute – Sukeshini Oct 24 '13 at 11:20
  • It will add "credit" attribute to product entity – mageUz Oct 24 '13 at 11:22
  • tested. But it's not setting the default vale in the text box – Sukeshini Oct 24 '13 at 11:33
  • you should remove first installed attribute, I also tested and it works perfect – mageUz Oct 24 '13 at 11:41
  • 1
    let us continue this discussion in chat – Sukeshini Oct 24 '13 at 11:47
2
     /**
     * @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',
    ));

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.