http://www.atwix.com/magento/add-category-attribute/
1st step:
Create: app/etc/modules/GaussDev_CustomCatAttrb.xml
<?xml version="1.0"?>
<config>
<modules>
<GaussDev_CustomCatAttrb>
<active>true</active>
<codePool>local</codePool>
</GaussDev_CustomCatAttrb>
</modules>
</config>
2nd step:
Create: app/code/local/GaussDev/CustomCatAttrb/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<GaussDev_CustomCatAttrb>
<version>0.0.1</version>
</GaussDev_CustomCatAttrb>
</modules>
<global>
<resources>
<CustomCatAttrb_setup>
<setup>
<module>GaussDev_CustomCatAttrb</module>
<class>Mage_Eav_Model_Entity_Setup</class>
</setup>
<connection>
<use>default_setup</use>
</connection>
</CustomCatAttrb_setup>
</resources>
</global>
</config>
3rd step:
Create: app/code/local/GaussDev/CustomCatAttrb/sql/CustomCatAttrb_setup/mysql4-install-0.0.1.php
Change “CUSTOM FIELD NAME” with your label name and “CUSTOM_FIELD_CODE” with your attribute code.
Create: app/code/local/GaussDev/CustomCatAttrb/sql/CustomCatAttrb_setup/mysql4-install-0.0.1.php
Change “CUSTOM FIELD NAME” with your label name and “CUSTOM_FIELD_CODE” with your attribute code.
<?php
$installer = $this;
$installer->startSetup();
$attribute = array(
'type' => 'text',
'label' => 'CUSTOM FIELD NAME',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => "",
'group' => "General Information"
);
$installer->addAttribute('catalog_category', 'CUSTOM_FIELD_CODE', $attribute);
$installer->endSetup();
?>
4th step:
You can get attribute with:
You can get attribute with:
$category = Mage::registry('current_category');
if ($category){
$value = $category->getData('YOUR_CUSTOM_ATTRIBUTE_CODE');
}
<?php
if
(
$_customAttribute
=
$this
->getCurrentCategory()->getCustomAttribute()): ?>
<?php
echo
$_helper
->categoryAttribute(
$_category
,
$_customAttribute
,
'custom_attribute'
) ?>
<?php
endif
; ?>
=============================================
Yes/No option
$this->startSetup();
$this->addAttribute( 'catalog_category', 'home_category', array(
'group' => 'General Information',
'type' => 'int',
'label' => 'Home page category',
'input' => 'select',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => 0,
'source' => 'eav/entity_attribute_source_boolean'
) );
$this->endSetup();