Step for adding an attribute to a category
1:
<? XML version = "1.0"?>
<Config>
<Modules>
<Tw_attribute>
<Active> true </active>
<Codepool> community </codepool>
</Tw_attribute>
</Modules>
</Config>
2
<? XML version = "1.0"?>
<Config>
<Modules>
<Tw_attribute>
<Version> 0.0.1 </version>
</Tw_attribute>
</Modules>
<Global>
<Resources>
<Attribute_setup>
<Setup>
<Module> tw_attribute </module>
<Class> mage_catalog_model_resource_eav_mysql4_setup </class>
</Setup>
<Connection>
<Use> core_setup </use>
</Connection>
</Attribute_setup>
<Attribute_write>
<Connection>
<Use> core_write </use>
</Connection>
</Attribute_write>
<Attribute_read>
<Connection>
<Use> core_read </use>
</Connection>
</Attribute_read>
</Resources>
</Global>
</Config>
3
<? PHP
/**
* Aheadworks Co.
*
* Notice of license
*
* This source file is subject to the EULA
* That is bundled with this package in the file license.txt.
* It is also available through the World-Wide-web at this URL:
* Http://ecommerce.aheadworks.com/LICENSE-L.txt
*
* @ Category AW
* @ Package aw_blog
* @ Copyright (c) 2009-2010 aheadworks Co. (http://www.aheadworks.com)
* @ License http://ecommerce.aheadworks.com/LICENSE-L.txt
*/
Class tw_attribute_helper_data extends mage_core_helper_abstract {
}
4
\ SQL \ attribute_setup \ mysql4-install-0.0.1.php
<? PHP
$ Installer = $ this;
$ Installer-> startsetup ();
$ Entitytypeid = $ installer-> getentitytypeid ('catalog _ category ');
$ Attributesetid = $ installer-> getdefadefaattributesetid ($ entitytypeid );
$ Attributegroupid = $ installer-> getdefadefaattributegroupid ($ entitytypeid, $ attributesetid );
$ Installer-> addattriory ('catalog _ category ', 'produmg MG', array (
'Type' => 'varchar ',
'Label' => 'product IMG ',
'Input' => 'text ',
'Global' => mage_catalog_model_resource_eav_attribute: scope_store,
'Visible '=> true,
'Requestred' => false,
'User _ defined' => false,
'Default' =>''
));
$ Installer-> addattributetogroup (
$ Entitytypeid,
$ Attributesetid,
$ Attributegroupid,
'Productid ',
'11' // last magento's attribute position in General tab is 10
);
$ Attributeid = $ installer-> getattributeid ($ entitytypeid, 'produmg MG ');
$ 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 ')}';
");
// This will set data of your custom attribute for root category
Mage: GetModel ('catalog/Category ')
-> Load (1)
-> Setimportedcatid (0)
-> Setinitialsetupflag (true)
-> Save ();
// This will set data of your custom attribute for default category
Mage: GetModel ('catalog/Category ')
-> Load (2)
-> Setimportedcatid (0)
-> Setinitialsetupflag (true)
-> Save ();
$ Installer-> endsetup ();
OK.