Skip to content

Instantly share code, notes, and snippets.

@chickenland
Created February 22, 2016 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chickenland/0ea9c7f0681a2c53f995 to your computer and use it in GitHub Desktop.
Save chickenland/0ea9c7f0681a2c53f995 to your computer and use it in GitHub Desktop.
Magento1 - Create category attribute
<?php
//XML <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
/* @var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();
$entityTypeId = $installer->getEntityTypeId('catalog_category');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$installer->addAttribute('catalog_category', 'banner_link', array(
'type' => 'int',
'label' => 'Banner Link',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => 0
));
$installer->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'banner_link',
'11' //last Magento's attribute position in General tab is 10
);
$attributeId = $installer->getAttributeId($entityTypeId, 'banner_link');
$installer->run("
INSERT INTO `{$installer->getTable('catalog_category_entity_int')}`
(`entity_type_id`, `attribute_id`, `entity_id`, `value`)
SELECT '{$entityTypeId}', '{$attributeId}', `entity_id`, '1'
FROM `{$installer->getTable('catalog_category_entity')}`;
");
$installer->endSetup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment