Creating a Hidden Product Attribute in a Magento Setup Script

Creating a Hidden Product Attribute in a Magento Setup Script

Some product data, such as a seller name set by an integration, should be stored but not edited by hand. A hidden attribute does exactly that.

Setup script

Add this to your module’s install or upgrade script:

$setup->addAttribute('catalog_product', 'seller_name', array(
  'group'     	=> 'Meta Information',
  'input'         => 'hidden',
    'type' 			=> 'text',
    'label'         => 'Seller Name',
  'backend'       => '',
  'visible'       => 0,
  'required'		=> 0,
  'user_defined' => 1,
  'searchable' => 1,
  'filterable' => 0,
  'comparable'	=> 0,
  'visible_on_front' => 1,
  'visible_in_advanced_search'  => 0,
  'is_html_allowed_on_front' => 0,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

Run the upgrade, then set the value in code with $product->setData('seller_name', ...).

Stuck on something similar? Our Magento development team is happy to take a look.

Keep reading

Related articles

All articles

Need a hand?

Stuck on something similar?
We can fix it with you.

Send us the problem. A senior developer reads every message and replies within one working day.