1

Working on magento 1 website.

I want to sort the product sorting by new in all product categories. So that when any new product is added that shows on first.

Can i be please guided how can same be done.

  • You can sort the field created_at. – kiatng Aug 25 '18 at 4:11
0

Rewrite Toolbar block in your custom module

app/code/local/Vendor/Module/etc/config.xml

...
...
<global>
    <blocks>
        <catalog>
            <rewrite>
                <product_list_toolbar>Dinesh_Expiredproducts_Block_Catalog_Product_List_Toolbar</product_list_toolbar>
            </rewrite>
        </catalog>
    </blocks>
</global>
...
...

Now create your custom block which rewrites the Toolbar block.

app/code/local/Vendor/Module/Block/Catalog/Product/List/Toolbar.php

<?php
class Vendor_Module_Block_Catalog_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar
{
    public function setCollection($collection)
    {
        $this->_collection = $collection;

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

        // 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())=='new'){
                $this->_collection->setOrder('entity_id','desc');
            }
            else {
                $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
            }
        }
        return $this;
    }

    public function setDefaultOrder($field)
    {
        if (isset($this->_availableOrder[$field])) {
            $new = ['new' => 'New'];
            $this->_availableOrder = $new + $this->_availableOrder;
            //$this->_orderField = $field;
            $this->_orderField = 'new';
        }
        return $this;
    }
}

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.