Created
February 22, 2016 10:17
-
-
Save chickenland/0ea9c7f0681a2c53f995 to your computer and use it in GitHub Desktop.
Magento1 - Create category attribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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