Magento - Retrieve Advanced Search results as a plain array
I am currently working on a Magento application and have a requirement to sort advanced search results based on the precedence of the categories in the store.
Basically, i have the algorithm prepared where i would loop through the advanced search results, run a query to retrieve the position of the products category and then sort the final result set before returning it back to the calling function.
But the issue I'm having is that i am unable to retrieve the search results as a plain array to work with. Could any one of the experts tell a way to retrieve开发者_如何学编程 this array please?
Regards,
Maximumus 69
assuming that you're working in list.phtml
, this should work.
$_productCollection=$this->getLoadedProductCollection();
$_productCollection->toArray($requiredFields)
where $requiredFields
is null (if you want all fields) or an array containing the fields that you're interested in.
Note that your choice to convert to array and then sort is particularly inefficient. You should be using Magento's inbuilt Collection sorting mechanisms. Read the documentation and API then then give setOrder('position')
a try.
Good luck,
JD
精彩评论