i need some custom attribute on every category so i create a module and in mysql4-install-0.0.1.php i write :
$installer = $this;
$installer->startSetup();
$tagline = array(
'type' => 'text',
'label' => 'tag-line',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => "",
'group' => "General Information",
'visible_on_front' => 1
);
$visible = array(
'type' => 'int',
'label' => 'is visible on homepage',
'input' => 'select',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => 0,
'group' => "General Information",
'visible_on_front' => 1,
'source' => 'eav/entity_attribute_source_boolean'
);
$installer->addAttribute('catalog_category', 'tagline', $tagline);
$installer->addAttribute('catalog_category', 'on_index_page', $visible);
$installer->endSetup();
setup work as expected and eveything is good, now i want to update the option of the on_index_page attribute so i create an other file name mysql4-upgrade-0.0.1-0.0.2.php in my setup folder, change the version form the config file and write this code :
$installer = $this;
$installer->startSetup();
file_put_contents("filename.txt", "data5"); // checking if file ever executed
$options = array ( 'value' => array(
'0' => array('no'),
'1' => array('Brands'),
'2' => array('Fruits'),
)
);
//$installer->updateAttribute('catalog_category','on_index_page','source','Hsn_Cat/Cat');
$installer->updateAttribute('catalog_category','on_index_page', 'option' , $options);
$installer->endSetup();
Magento run this file , as i do get the "filename.txt", but the option remain the same.
information 1. the setup file is properly configured,and it execute without error.
while creating the attribute i use the
'source' => 'eav/entity_attribute_source_boolean'so i also test to undo that by doing this$installer->updateAttribute('catalog_category','on_index_page','source','');i also tried to set the source to my own class as i see that the
eav/entity_attribute_source_booleanhave a function which return the array of option so i create a class like:
class Hsn_Cat_Model_Cat extends Mage_Core_Model_Abstract{
public function getAllOptions() {
file_put_contents("called", "im called");
if (is_null($this->_options)) {
$this->_options = array(
array(
'label' => 'Brands',
'value' => 2
),
array(
'label' =>'Fruits',
'value' => 1
),
array(
'label' => 'No',
'value' => 0
),
);
}
return $this->_options;
}
}