How to change the product list 'desc' direction?

Now Old product is default.

I want to change is new product position is default > ?product_list_dir=desc

using Magento Version 2.2.4

thank you!

  • plz explain properly May 5, 2018 at 15:31
  • want to change the date position : asc to desc <-- @MuhammadAhsanHorani
    – niceonelee
    May 7, 2018 at 17:27

3 Answers 3


You should add the below code app/design/frontend/Vendor/theme/Magento_Catalog/layout/catalog_category_view.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        <referenceContainer name="content">
            <referenceBlock name="product_list_toolbar">
                <action method="setDefaultDirection">
                    <argument name="dir" xsi:type="string">desc</argument>

The only solution I found is this, edit the file located in:


add this line:

$this->_direction = strtolower('desc'); //choose 'asc' or 'desc'

in this position:

    public function setCollection($collection)
    $this->_collection = $collection;


    $this->_direction = strtolower('desc'); // *** THIS POSITION ***

    // we need to set pagination only if passed value integer and more that 0
    $limit = (int)$this->getLimit();
    if ($limit) {
    if ($this->getCurrentOrder()) {
        if ($this->getCurrentOrder() == 'position') {
            )->addAttributeToSort('entity_id', $this->getCurrentDirection());
        } else {
            $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
    return $this;

I hope I was helpful


Another solution could be overwriting the method prepareSortableFieldsByCategory of the class Magento\Catalog\Block\Product\ListProduct and add the following code to the method

if (!$this->getDefaultDirection()) {

Complete code:

    public function prepareSortableFieldsByCategory($category)
    if (!$this->getAvailableOrders()) {
    $availableOrders = $this->getAvailableOrders();
    if (!$this->getSortBy()) {
        $categorySortBy = $this->getDefaultSortBy() ?: $category->getDefaultSortBy();
        if ($categorySortBy) {
            if (!$availableOrders) {
                $availableOrders = $this->_getConfig()->getAttributeUsedForSortByArray();
            if (isset($availableOrders[$categorySortBy])) {
    /***Change direction***/
    if (!$this->getDefaultDirection()) {

    return $this;

Another solution could be using xml mentioned in the following post

Link: Change product sorting from desc to asc on category page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.