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.

4 REPLIES 4

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.

Re: Sort products by Newest first

Thank you!

Re: Sort products by Newest first

You may override/inject in the "Toolbar" block class to incorporate one more sorting option which can sort the products by created_at  column in the database.

But, if you are using Magento's out of the box 'New From Date' and 'New To Date' attributes to tag products as New products, I would recommend to go with the following extension which takes care of the New From Date and New To Date attributes of Magento Products. If you are using Product Labels then also this extension should be used to avoid confusing customers by new products sorting.

https://marketplace.magento.com/mk-sortby.html

Sorting by New | Best Sellers Products.