0

I am trying to provide the custom attribute in sort-by, when am trying to fetching the products list order by custom attribute those are not in Ascending order.

  if ($attribute == 'paidship') {
        //$dir = 'ASC';
        if (isset($this->_joinFields[$attribute])) {

            $this->getSelect()->order($this->_getAttributeFieldName($attribute) . ' ' . $dir,'e.name'.$dir);

        }
    }

My custom attribute is "paidship", i want fetch them in first in Ascending order and remaining products should display after those products and those are also be in Ascending order

1 Answer 1

0

You can add custom attribute to sort the collection as follows:

$collection->addAttributeToSort('paidship','ASC');
1
  • Sorry, i am writing script for addAttributeToSort if (isset($this->_joinFields[$attribute])) { $this->getSelect()->order($this->_getAttributeFieldName($attribute) . ' ' . $dir); return $this; } return $this; } elseif($attribute == 'is_saleable'){ $this->getSelect()->order("is_saleable " . $dir); return $this; }
    – Ramesh
    Commented Nov 21, 2016 at 11:01

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.