1

I need to have recently added sort by option how can I get this.I searched google and also SE's but cannot found the solutions but not worked.

1 Answer 1

5

To get recently added sort by option open app/code/core/Mage/Catalog/Block/Product/List/toolbar.php and find and replace the below code will be in line 232

if ($this->getCurrentOrder()) {
            $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
        }
        return $this;

by

if ($this->getCurrentOrder()) {
          if(($this->getCurrentOrder())=='recentlyadded'){
              $this->_collection->setOrder('entity_id','desc');
          }
          else {
           $this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
          }
        }
        return $this;

also in line no 391 find and replace this code

public function setDefaultOrder($field)
{
    if (isset($this->_availableOrder[$field])) {
        $this->_orderField = $field;
    }
    return $this;
}

with this code

 public function setDefaultOrder($field) {
    if (isset($this->_availableOrder[$field])) {
        $this->_availableOrder = array(

            'recentlyadded'    => $this->__('Recently Added'),
            'name'        => $this->__('Name'),
            'price'       => $this->__('Price'),
        );
        $this->_orderField = $field;
    }

    return $this;
}

this should help you in getting the required recently added functionality if any queries please let me know.

5
  • what for the code to be pasted in line no 391??
    – dhoni7
    Dec 16, 2014 at 11:14
  • It helps you maintain the dropdown option in frontend.
    – dh47
    Dec 16, 2014 at 11:15
  • Integrity constraint violation: 1052 Column 'parent_item_id' in where clause is ambiguous
    – Ajay Patel
    Mar 28, 2016 at 5:29
  • @dh47, how can we show this option only for specific categories? Jun 3, 2019 at 14:00
  • @dh47, this will not load if any color and size filters are present, Nov 5, 2019 at 12:01

Your Answer

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

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