tags:

views:

30

answers:

2

I have a few custom attributes on my products in Magento and they are searchable in Magento's search page; problem is that the fields are listed in the wrong order on the search page;

For example:

Title  _____
Author _____
SKU    _____
ISBN   _____

Should be:

Author _____
Title  _____
ISBN   _____
SKU    _____

I've taken a look at the template file and it seems to be outputting an array (or object) from it's internal ordering. I would like to know how to change this ordering :).

Any (relatively straight-forward) ideas?

A: 

Tried setting the position attribute on those attributes?

Catalog -> Attributes -> Manage Attributes -> Attribute -> Frontend Properties -> Position

Edit:

Actually, it looks like you may have to apply manual sorting to the search results block/template.

Start here for details on how to do that kind of thing: http://alanstorm.com/category/magento

andrewd
from magento IRC: Position of attribute in layered navigation block is referring to when the attribute is a Dropdown, Select or Price the position is actually in the is_anchor navigation or something similar. So, if the attribute is just a text input, then the position is disabled.
Mythril
A: 

If you open the Block that matches your template (catalogsearch\advanced\form.phtml -> Mage_CatalogSearch_Block_Advanced_Form), you will see that it's calling the getAttributes method of Mage_CatalogSearch_Model_Advanced which in turn is executing:

$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
            ...
            ->setOrder('main_table.attribute_id', 'asc')
            ->load();

All of which means that it's sorting by the attribute_id field in the eav_attribute table, not a particular useful field.

However, the actual query performs a join on the catalog_eav_attribute table as additional_table which means that you could alter the sort portion of the code to be ->setOrder('additional_table.position', 'asc') and then change the values of the "position" field in that table via phpMyAdmin.

In order to make this alteration in a future-proof manner, take a copy of the Mage_CatalogSearch_Model_Advanced file and copy it to app/code/local/Mage/CatalogSearch/Model before making any alterations.

To debug the SQL query, turn on $_debug and $_logAllQueries in lib/varien/Db/Adapter/Pdo/Mysql.php. Don't forget to turn that off in production!!

Hope this helps, JD

Jonathan Day