It’s common knowledge that Magento can be a bit of a beast to modify and customize. On a recent project I wanted to add a custom field to the admin side of a product, which is a simple process, but I also wanted to reorder them within the tab. My custom field needed to come after the "Name" field, not at the end (after "Country of Manufacture") of the options. Simple request, simple execution, but hours of searching for the answer.
Question: How do I reorder the admin fields within the "General" product tab?
Answer: Magento orders these fields according to a sort order pulled from the database. With all the foreign keys and EAV structure this took quite a while to track down. Ultimately, the table you need to modify is named
eav_entity_attribute, but you need to first find the ID of the element you would like to change. This can be found in the
eav_attribute table and is called
attribute_id. Once you have that number, you can navigate to the
eav_entity_attribute table and find the ID in the
attribute_id column. Make note of the
attribute_group_id as these are the other elements that are in the tab in the admin section. By default there are 29 elements, plus the one you added, and you will notice the
sort_order column. Your custom element will have the value of 30 (if this is the first custom attribute you added to Magento) and is thus last in the sort order. In my use case above, I wanted my custom attribute to be after the "Name" field which means setting the value of the
sort_order field to 2. Before you make the change, you need to make a space for it, so you need to increment every value in
sort_order by 1 starting from the value you want your element to be. This is easily accomplished with the MySQL query below:
UPDATE eav_entity_attribute SET sort_order=sort_order+1 WHERE attribute_group_id = 7 AND sort_order > 1
Make sure that the value in
sort_order > 1 is set appropriately for your own placement. Since I want my custom element to appear second, I need to update the values for 2 through 30. The sort order is now appearing as 1, 3, 4, 5, 6, etc. which leaves the spot for my custom attribute. Now, it’s merely a fact of changing the sort order value for my element from 31 to 2! If you go back to the admin page and refresh, your custom attribute should appear in it’s correct place.