Display newly added products first in Category of Opencart

opencart-category-ordering-by-date-added

Opencart doesn’t have settings to show newly added products to show on top of the list in a category. This can be achieved by changing a simple file or you can say a simple customization.
Fire up your FTP and navigate to /catalog/controller/product and open up category.php in your favourite editor. Find the part, most commonly in line 21 and edit the following code

opencart-category-ordering-by-date-added

Original code:
if (isset($this->request->get[‘sort’])) {
$sort = $this->request->get[‘sort’];
} else {
$sort = ‘p.sort_order’;
}

Change it to:
if (isset($this->request->get[‘sort’])) {
$sort = $this->request->get[‘sort’];
} else {
$sort = ‘p.date_added’;
}

And it is sorting by date, we will need to change the order too. After the above code block, in line 27 you will see the following code block to change the order.

Original Code:

if (isset($this->request->get[‘order’])) {
$order = $this->request->get[‘order’];
} else {
$order = ‘ASC’;
}

Change it to:
if (isset($this->request->get[‘order’])) {
$order = $this->request->get[‘order’];
} else {
$order = ‘DESC’;
}

That’s it, then your newly added products will shown on top. This customization works well with Opencart 2.x.x but haven’t tested with newer OC 3.x.x versions.

Alternatively, if you want to sort by price, you can use the p.price instead of p.date_added in the above code.
Do let us know if you encounter any problem.