Add an attribute to a category

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.