0

I'm trying to add attribute to product entity. It seems that my upgrade script run, because module version is upgraded in core_resource table.

However I can't find it at catalog attributes listing.

Upgrade script code:

/* @var $installer Mage_Catalog_Model_Resource_Setup */
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
$installer->startSetup();

$installer->addAttribute(
  Mage_Catalog_Model_Product::ENTITY,
  'use_discount_label',
  array(
    'label' => 'Use discount label?',
    'default' => '0',
    'group' => 'Other',
    'type' => 'int',
    'input' => 'boolean',
    'source' => 'eav/entity_attribute_source_boolean',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'required' => false,
    'user_defined' => false,
    'unique' => false,
    'filterable' => 1,
    'is_configurable' => false,
    'comparable' => true,
    'filterable_in_search' => false,
    'is_html_allowed_on_front' => false,
    'searchable' => true,
    'used_for_promo_rules' => false,
    'used_for_sort_by' => true,
    'used_in_product_listing' => true,
    'visible' => false,
    'visible_in_advanced_search' => false,
    'visible_on_front' => false,
    'wysiwyg_enabled' => false,
  )
);

$installer->endSetup();

I'm using Magento EE 1.14.2.2.

6
  • Did you remove the entry for your module from core_resource and try again? – Jaimin Sutariya Feb 10 '17 at 10:30
  • I downgrade it every time, from 0.0.2 to 0.0.1 and then refresh, is that procedure ok for testing? – Codium Feb 10 '17 at 10:32
  • Yes that is okay if your filename is upgrade-0.0.1-0.0.2.php – Jaimin Sutariya Feb 10 '17 at 10:38
  • Yes, my file has exactly that name – Codium Feb 10 '17 at 10:46
  • Please check if you get your attribute in eav_attribute table – Jaimin Sutariya Feb 10 '17 at 11:08
3

Your setup script looks correct, Try removing attribute before creating it. downgrade entry from core_resource and run the script again.

$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
$installer->removeAttribute('catalog_product','use_discount_label');
$installer->startSetup();

$installer->addAttribute(
  Mage_Catalog_Model_Product::ENTITY,
  'use_discount_label',
  array(
    'label' => 'Use discount label?',
    'default' => '0',
    'group' => 'Other',
    'type' => 'int',
    'input' => 'boolean',
    'source' => 'eav/entity_attribute_source_boolean',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'required' => false,
    'user_defined' => false,
    'unique' => false,
    'filterable' => 1,
    'is_configurable' => false,
    'comparable' => true,
    'filterable_in_search' => false,
    'is_html_allowed_on_front' => false,
    'searchable' => true,
    'used_for_promo_rules' => false,
    'used_for_sort_by' => true,
    'used_in_product_listing' => true,
    'visible' => false,
    'visible_in_advanced_search' => false,
    'visible_on_front' => false,
    'wysiwyg_enabled' => false,
  )
);

$installer->endSetup();

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.