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
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:
<code>$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());</code>
and change it to:
<code>$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection())->setOrder('entity_id', 'desc');</code>
.
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.