Home > Backend Development > PHP Tutorial > How to make Magento's newly uploaded products appear at the front of the category?

How to make Magento's newly uploaded products appear at the front of the category?

WBOY
Release: 2016-07-29 09:05:06
Original
1009 people have browsed it

In the actual environment, you will encounter this situation. Every time you add a product, on the product display page, the one added first is always in front, and the one added later sometimes needs to be turned over to see. This is because of Magento. Products are arranged in ascending order by default on the list page, which means that products added first are always displayed at the front, and products added later are displayed at the end. If we want to sort the last added product first, that is, in reverse order, how should we modify it?
First open the following directory file:
File: appcodecoreMageCatalogBlockProductListToolbar.php,
Find
How to make Magento's newly uploaded products appear at the front of the category?
protected $_direction = ‘asc’;
This parameter is the default order
Change to:
protected $_direction = ‘desc’;
Then save.
You can also think about it through the following method. Every time Magento uploads a product, it will be given a unique ID value. The order of the ID values ​​​​increases by 1. Therefore, the display method can be based on the last uploaded product, in reverse order of ID. way to sort.
Similarly modify the current Toolbar.php
to find:
How to make Magento's newly uploaded products appear at the front of the category?

<code>$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());</code>
Copy after login

and change it to:

<code>$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection())->setOrder('entity_id', 'desc');</code>
Copy after login

.

The above introduces how to make the newly uploaded products in Magento appear at the top of the category display? , including relevant content, I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template