Friday, 22 August 2014

Magento Add a “mode” to Toolbar and Product Listing

Have done it by myself.

Go to - app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListMode.php

Add the highlighted code in this function :


class Mage_Adminhtml_Model_System_Config_Source_Catalog_ListMode
{
    public function toOptionArray()
    {
        return array(
            //array('value'=>'', 'label'=>''),
            array('value'=>'grid', 'label'=>Mage::helper('adminhtml')->__('Grid Only')),
            array('value'=>'list', 'label'=>Mage::helper('adminhtml')->__('List Only')),
array('value'=>'listnew', 'label'=>Mage::helper('adminhtml')->__('List New Only')),
            array('value'=>'grid-list-listnew', 'label'=>Mage::helper('adminhtml')->__('Grid (default) / List / List New')),
            array('value'=>'list-grid-listnew', 'label'=>Mage::helper('adminhtml')->__('List (default) / Grid / List New')),
array('value'=>'listnew-list-grid', 'label'=>Mage::helper('adminhtml')->__('List New (default) / Grid / List')),
        );
    }
}


then go to app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php

Add the highlighted code in this function :

 protected function _construct()
    {
        parent::_construct();
        $this->_orderField  = Mage::getStoreConfig(
            Mage_Catalog_Model_Config::XML_PATH_LIST_DEFAULT_SORT_BY
        );

        $this->_availableOrder = $this->_getConfig()->getAttributeUsedForSortByArray();

        switch (Mage::getStoreConfig('catalog/frontend/list_mode')) {
            case 'grid':
                $this->_availableMode = array('grid' => $this->__('Grid'));
                break;

            case 'list':
                $this->_availableMode = array('list' => $this->__('List'));
                break;

case 'listnew':
                $this->_availableMode = array('listnew' => $this->__('List New Only'));
                break;

            case 'grid-list-listnew':
                $this->_availableMode = array('grid' => $this->__('Grid'), 'list' =>  $this->__('List'), 'listnew' =>  $this->__('List New Only'));
                break;

            case 'list-grid-listnew':
                $this->_availableMode = array('list' => $this->__('List'), 'grid' => $this->__('Grid'), 'listnew' =>  $this->__('List New Only'));
                break;


case 'listnew-list-grid':
                $this->_availableMode = array('listnew' =>  $this->__('List New Only'), 'list' => $this->__('List'), 'grid' => $this->__('Grid'));
                break;
        }
        $this->setTemplate('catalog/product/list/toolbar.phtml');
    }

Then select the list mode in admin panel

Admin - System - Configuration - Catalog - Frontend
change the list mode there.







No comments:

Post a Comment

Thanks for your comments.