Change attribute ordering in Magento's advanced search page
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 _____ 开发者_如何学PythonSKU _____ 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?
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
In Magento 1.7x this can be done through the management of the Product Attribute Set.
Go to Catalog-> Attributes -> Manage Attribute Set --- Select Your Attribute Set
From there you can reorder, add and remove attributes for a set.
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
精彩评论