Create Custom Category Attributes with phpMyAdmin (Tutorial)

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 ;)

0 comments: