1

I am wondering if it's possible to specify multiple sorting conditions for the order grid in the Admin Panel.

Let's say for example I wanted to sort all orders first by their Bill to Name and then the Purchased On column. Any ideas how that can be done?

I have looked at the code but I got stuck at the Varien_Data_Collection_Db::_setOrder method, with no idea how to implement a solution there:

private function _setOrder($field, $direction, $unshift = false)
{
    $this->_isOrdersRendered = false;
    $field = (string)$this->_getMappedField($field);
    $direction = (strtoupper($direction) == self::SORT_ORDER_ASC) ? self::SORT_ORDER_ASC : self::SORT_ORDER_DESC;

    unset($this->_orders[$field]); // avoid ordering by the same field twice
    if ($unshift) {
        $orders = array($field => $direction);
        foreach ($this->_orders as $key => $dir) {
            $orders[$key] = $dir;
        }
        $this->_orders = $orders;
    } else {
        $this->_orders[$field] = $direction;
    }
    return $this;
}

1 Answer 1

6

Never mind, I figured it out. I can just call Varien_Data_Collection_Db::setOrder twice, e.g.:

$collection->setOrder('bill_to', 'DESC');
$collection->setOrder('created_at', 'ASC');

This example would first sort the collection by the bill to attribute and then the created at attribute.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.