cancel
Showing results for 
Search instead for 
Did you mean: 

Sort products by Newest first

Sort products by Newest first

Perhaps I'm missing this, but is there a place to set products to be sorted by newest first? I currently am sorting by color, expecting the items to be in the order of the attribute value sort order, but it seems to be random.

2 REPLIES

Re: Sort products by Newest first

I believe this tutorial will help you solve your problem very well http://magento2x.com/magento-sort-newest-products-solution/

Re: Sort products by Newest first

Thank you for the link. It is similar to this Stack Exchange question, but not perfect..

--

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;

with

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

 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;
}

I copied toolbar.php to app/code/local/Mage/Catalog/Block/Product/List/ and made the changes.

 

I have the options 'position, name, price, color' as options to sort in the product listing (and set up in admin), the above soliution appears to manually rename the dropdown, taking away my current options, otherwise it does default to sorting the listing by newest.