Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save evgv/3a406f361128128702892b658ec469ee to your computer and use it in GitHub Desktop.
Save evgv/3a406f361128128702892b658ec469ee to your computer and use it in GitHub Desktop.
Magento. Add new product attribute and add it to all attribute sets.
/* @var $installer Mage_Catalog_Model_Resource_Setup */
$installer = Mage::getResourceModel('catalog/setup','default_setup');

$attributeCode = "oversized";
$installer->startSetup();

$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode, array(
    'group'                         => 'General',
    'type'                          => 'int',
    'input'                         => 'boolean',
    'source'                        => 'eav/entity_attribute_source_boolean',
    'backend'                       => '',
    'frontend'                      => '',
    'label'                         => 'Oversized',
    'class'                         => '',
    'global'                        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
    'visible'                       => true,
    'is_wysiwyg_enabled'            => false,
    'is_html_allowed_on_front'      => false,
    'required'                      => false,
    'user_defined'                  => true,
    'searchable'                    => false,
    'filterable'                    => false,
    'comparable'                    => false,
    'visible_on_front'              => false,
    'unique'                        => false,
    'apply_to'                      => 'simple,configurable,bundle,grouped',
    'used_in_product_listing'       => false,
    'is_configurable'               => false,
    'note'                          => "select yes no"
));

$sets = $installer->getAllAttributeSetIds(Mage_Catalog_Model_Product::ENTITY);
foreach ($sets as $set) {
    $installer->addAttributeToGroup(Mage_Catalog_Model_Product::ENTITY, $set, "Oversized", $attributeCode);
}
$installer->endSetup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment