Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visibility of new attribute created by Magento upgrade script

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.

like image 725
Kev K Avatar asked Nov 13 '22 18:11

Kev K


1 Answers

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,
like image 105
Kev K Avatar answered Dec 24 '22 01:12

Kev K