I'm having problems applying a default sort order to the product collection for the listing page. When some conditions are met I want to sort by 'region' and then by 'price'. I have added the following in app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php.
public function setCollection($collection)
{
$this->_collection = $collection;
$this->_collection->setCurPage($this->getCurrentPage());
$limit = (int)$this->getLimit();
if ($limit) {
$this->_collection->setPageSize($limit);
}
if(Mage::registry('current_category')->getName() == 'France'){
$this->_collection->setOrder(array('region', 'price'), $this->getCurrentDirection());
}else{
if ($this->getCurrentOrder()) {
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}
}
return $this;
}
This sorts by region successfully but not by price. I did read somewhere that different resources are used by price than other attributes when using them for sorting. If this is the case it makes sense because when I substituted price with name - $this->_collection->setOrder(array('region','name'), 'asc');
I get the collection sorted by region and then by name.
To confirm, both attributes are set yes to - Used in Product Listing and Used for Sorting in Product Listing. Any suggestions on getting price to work with region?