Know Magento
Create Custom Category ...

Create Custom Category Attributes with phpMyAdmin (Tutorial)

Category: Categories, Database – Posted Friday, June 19th, 2009.

The following is a brief tutorial for creating a custom category attribute. This has only been tested by creating a textfield-type attribute in Magento’s version 1.3.2. However, to the best of my current knowledge, it should work in any versions 1.2+ and for any type of attribute. Note: changing the attribute type will require a couple changes to the SQL below. So on we go…

  1. Open your Magento database using phpMyAdmin.
  2. We will first find the proper attribute_id for your new attribute.  Run the following SQL statement and keep the resulting number handy: 
    SELECT MAX(attribute_id) + 1 from eav_attribute
  3. From the left pane, click the eav_attribute table link.
  4. Click Export tab link near the top of the page.
  5. Ensure the Data box is checked then click the Go button.
  6. Scroll through the list of attributes on your page and find the one that has a second comma delimited value of 3 and a third comma delimited value of meta_description.
  7. Copy that entire row, excluding the comma at the end (i.e from opening parenthesis to closing parenthesis).
  8. Click your browser’s back button.
  9. Now run the following SQL command:
    INSERT INTO eav_attribute VALUES

    followed by the text you copied about the meta_description.  Don’t click the Go button just yet – let’s alter that command a bit:

  10. Change the first comma delimited number value to your new attribute_id value (found in step 2 above).  Then change the value from meta_description to some unique identifier for your attribute.  Then change the value that reads Meta Description to a proper label for your new attribute.  Now you can click Go to run the command.
  11. The new attribute is created.  Now we need to ensure it has a proper sort order.  For this tutorial we will place it at the end of the list under the category’s General Information tab in the admin panel.  Run the following SQL command and keep the resulting number handy as it will be the new attribute’s sort order:
    SELECT MAX(sort_order) + 1 from eav_entity_attribute where attribute_set_id = 3
  12. Now run the following SQL command, but replace the last two fields with the values from step 2 and step 11: 
    INSERT INTO eav_entity_attribute ( entity_type_id, attribute_set_id, attribute_group_id, attribute_id, sort_order ) VALUES ( 3, 3, 3, [your new attribute_id], [your new sort_order] )

And that should do it.  If you bounce into your admin panel, you should see your new attribute for any given category – new or edit.  I’ll let you figure out how to use it from there ;)


  • Matt

    Absolutely brilliant article! Short and sweet. Thanks :)

  • Matt

    Just one heads up, at least on my Magento install, the entity_type_id for “catalog/category” is 9, not 3. And my appropriate attribute_set_id is 12 instead of 3. And finally, my “General Information” attribute_group_id is 7 and not 3.

    Also, the attribute_id column in eav_attribute is auto_increment, so I don’t think you need to calculate the MAX(attribute_id) + 1.

    Your post certainly helped me find where to go!

  • Muza

    Thanks, that was very helpful.. Please keep posting Magento development tricks :)

  • Jacob

    This works great; thank you for sharing! I’ve just bookmarked this blog. :)

  • Nirnajan

    It is great for text box but I needed it for select box. Is there any solution. I need it.
    Thanks In advance.

  • Mal

    This was very helpful, thanks! Now, I just need to determine how to display it on the category page as a block of text just above the footer. Any pointers are welcome!

  • anand

    thank you soooo much bro…..
    i was searching this for last 2days…. n jz found this.. hours b4 ma deadline… thank you… :D :D

  • anand

    n i added an image gallery…. we can add anything we need, jz look the result of the 1st export.. n we can easly identify,.. n change the values accordingly

  • soumraky

    Many thanks! Brief and efficient. For an alternative, there is also a modular way to do this, without going through phpmyadmin: http://www.magentix.fr/modules-magento/ajouter-categorie-attributs-champs-personnalises.html

  • http://n/a Chris

    Hi Jeff,

    This is a very clear tutorial, however I am running version 1.4 and even though the updates went through without errors, my attribute is only showing up in “Manage Attributes” and not on the category page as intended.

    What I mean is that its listed under “General” in Attribute Sets, but it doesn’t show up on the category admin page…

    …any ideas? Anyone? :)

    Thanks,
    Chris

  • Shaun

    Chris,

    Haveen’t trid it or not but there was someone who posted a “fix” for a similar solution at this post. He said it worked for 1.4.
    http://www.sonassi.com/knowledge-base/magento-knowledge-base/custom-attributes-for-categories-in-magento/

    I am not on 1.4 yet so I couldn’t say whether it really works or not.

    Good luck.

  • http://www.nvncbl.com/2010/03/magento-add-custom-category-attributes/ Magento – Add Custom Category Attributes | Solution Log | Antonio David – NVNCBL

    [...] For the fully detailed procedure, see Create Custom Category Attributes with phpMyAdmin [...]

  • Demar

    Hi Chris,
    I had the same problem. Since version 1.4 you need to add a row in “catalog_eav_attribute” and it works! Insert the attribute id from the added row in eav_attribute and fit the other colomns to your needs.

  • http://www.rutley.co.uk/ Sam

    Great tutorial.

    To retrieve the new category attribute use:-

    $_category->getData(‘your_attribute_code’);

  • Charly Bronson

    I have mag ver. 1.4.0.1. This worked, but there is a little extra work involved. Just to recap, follow the instructions above and stop after you complete step 10. Like Demar said, go into “catalog_eav_attribute” and follow the same steps (1-10). In my particular case, in “eav_attribute” I was replicating “id_37″ which is the image field (I needed an extra image for my categories). I was able to locate the same row with “id_37″ in “catalog_eav_attribute”. Once you create the new row, then run steps 11 & 12. If you do steps 11 & 12 WITHOUT creating the new row in “catalog_eav_attribute”, you’ll get an error. Hope this helps.

  • Dhara

    I have magento enterprise version 1.8 and i also had the same problem until i add the row in “catalog_eav_attribute” table. now it works fine… Thanks, this tutorial helped a lot.. :)

  • andy

    everything goes fine, no errors, no issues, but nothing shows up in admin, I have cleard the cache, cleared browser cache and removed cookies…. still not showing. I am using Magento ver. 1.3.2.4

  • Louise

    How would you output the custom field to the frontend?

  • http://www.w3interviewquestions.com magento questions

    Great tutorial.

  • http://www.limonadaweb.com.br Lucas Gabriel

    I did not worked for me, I’ve done the tutorial over and over step by step, just can’t get it to work. I’ve used as reference the filed Name cuz I wanted it to be the first in the sort-order. I used the same group_id same set_id same type_id and same sort_order just changed the attribute_id.

  • http://www.testblast1234.com/ test blast

    test blasts

  • http://web-designz.net/blog/ Mirza Tauseef

    Hi,

    Dear Admin I have placed your feeds on my blog page. Can you place a back link. Message For ADMIN only.

    Thanks,
    Tauseef

  • Bart

    Very useful Sam, I’d been looking for a simple way to do that for some time now.

  • http://twitter.com/touringbuddy Touring Buddy

    Thanks for the info man, you rock. This site rocks.

Buy Magento Books and learn more tips and guides

Copyright © 2011 KnowMagento.com. All rights reserved. Designed by . Privacy Policy