2

I'm trying to add attribute from the setup script.Even though attribute is getting added,some of the options has different values than the one specified in the setup script

/* @var $installer Mage_Eav_Model_Entity_Setup */
$installer = $this;

$installer->startSetup();


$entityTypeId = 'catalog_product';
$attributeCode ='dz_video';

$data = array(
    'type'=>'textarea',
    'input'=>'text',
    'label'=>'Video',
    'is_required' =>'0',
    'is_unique' =>'0',
    'is_global' =>Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'is_comparable'=>'0',
    'is_wysiwyg_enabled'=>'0',
    'is_searchable'=>'0',
    'is_used_for_price_rules'=>'0',
    'is_html_allowed_on_front'=>'1',
    'is_visible_on_front'=>'1',
    'used_in_product_listing'=>'0',
    'used_for_sort_by'=>'0',
    'user_defined'=>'1',
    'is_configurable'=>'1'
);

$installer->addAttribute($entityTypeId,$attributeCode,$data);

For example,specified value for 'is_required' is 0 but in the admin "Required" option is set to Yes

0

2 Answers 2

3

This is a somewhat weird behavior in the EAV setup class. When you use addAttribute, then your data array is remapped. This is not the case in updateAttribute. Check the class Mage_Eav_Model_Entity_Setup and its _prepareValues() method. For example your is_required needs to be simply "required" to work as expected!

Sign up to request clarification or add additional context in comments.

Comments

2

mpaepper's answer is correct. Also in some cases rather than 1 or 0, the value needs to be true or false. E.g:

'required' => false,

Comments

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.