0

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 – Ahsan Horani May 5 '18 at 15:31
  • want to change the date position : asc to desc <-- @MuhammadAhsanHorani – niceonelee May 7 '18 at 17:27
0

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

..MAGENTO_DIR/vendor/magento/module-catalog/Block/Product/ProductList/Toolbar.php

add this line:

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

in this position:

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

    $this->_collection->setCurPage($this->getCurrentPage());

    $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) {
        $this->_collection->setPageSize($limit);
    }
    if ($this->getCurrentOrder()) {
        if ($this->getCurrentOrder() == 'position') {
            $this->_collection->addAttributeToSort(
                $this->getCurrentOrder(),
                $this->getCurrentDirection()
            )->addAttributeToSort('entity_id', $this->getCurrentDirection());
        } else {
            $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
        }
    }
    return $this;
}

I hope I was helpful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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