Home » Magento tutorials » How to create a new Magento attribute and attribute group using the sql setup file

How to create a new Magento attribute and attribute group using the sql setup file

How to create a new Magento attribute and attribute group using the sql setup file?

More than often, we need to create a new Magento attribute to extend some Magento functions, or even a new attribute group to serve our own module.  Here is how we do it using the sql setup file.

First, a few words about the sql setup file.

If this is the first time building the module or fresh installation, create a php file, say “mysql4-install-0.1.0.php”, in [company]/[module]/sql/[module]/[module]_setup/ folder, where the version 0.1.0 is defined the the config.xml file.

In case of module upgrade, try something like “mysql4-upgrade-0.1.0-0.2.0.php”, again, verify your upgrade version in the config.xml file.

Inside this file, first we need to initiate:

Then if you want to create a new attribute group:

You can skip this line if you don’t want to create a new attribute group, here ‘catalog_product’ is used to retrieve the entityTypeId, you can use ‘sales_order’, ‘customer/customer’, ‘customer/address’ as well. ‘Default’ is the attributeSet Name. ‘Test Group’ is the Group name you want to create, you can just use the existing ones, such as ‘General’. 1000 is just the sort order, give it a big number so the new one will append to the end.

Next, adding a new attribute:

The attribute added above will show up under the group/tab Special Attributes in product edit page.

About Brian Wilson

avatar
Brian is a freelance Magento developer with 5 years of experience with customizing Magento extensions, magento themes. He's interested in sharing Magento Tutorials to the community

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Scroll To Top