I am trying to add a custom attribute programmatically within a module upgrade script. The script runs fine and creates the new attribute (i.e. it appears in the Magento admin list under Catalog->Attributes->Manage Attributes once the script has run).
At first I was using the class Mage_Eav_Model_Entity_Setup
(as recommended here and neither the 'visible' nor 'apply_to' fields were being set as intended ('visible' was always false and 'apply-to' remained as "All product types" rather than using the list supplied in the script).
Then I found this, which explained that I should use Mage_Catalog_Model_Resource_Setup
instead, and that has fixed the problem with 'apply_to'.
But still I can't get the attribute's 'visible' attribute to set to true. If anyone has any ideas why the 'visible' attribute is still not being set as it should I would be very grateful to hear, thanks!
Here is my upgrade script code:
$updater = $this; // $this is class Mage_Eav_Model_Entity_Setup
$updater->startSetup();
$updater->addAttribute('catalog_product', 'my_test_attribute', array(
'label' => 'My Test Attribute',
'type' => 'int',
'input' => 'select',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'apply_to' => 'simple,configurable',
'group' => 'General',
'visible' => true,
'required' => true,
'user_defined' => true,
));
$updater->endSetup();
I am running Magento 1.7.0.1 in WAMP on Windows 7.
I have solved this now - what it needed was the "visible_on_front" attribute to be set too, rather than just the "visible". i.e. I added this line to the above script and it now works:
'visible_on_front' => true,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With