Tuesday, 28 May 2013

Re-Write Toolbar for grid on front side magento

Re-Write Toolbar for grid on front side magento

I want to override the Product grid tool-bar for custom work in my module.I inlcude my filters in the filters array but the product grid is not executing my code when i select my filter like , i want to add best seller and most viewed filters to toolbar ,My config.xml code is :
<catalog>
             <rewrite>
               <product_list_toolbar>Mymodule_Block_Catalog_Product_List_Toolbar</product_list_toolbar>
            </rewrite>
         </catalog>.
I created a block class for that like :
<?php

class Mymoudle_Block_Catalog_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar
{


    public function getAvailableOrders()
    {
      $vari = Mage::helper('Mymoudle')->getMethods();

        return $vari;
    }
 public function getCurrentDirection()
    {
        $dir = parent::getCurrentDirection();
        $url = strtolower($this->getRequest()->getParam($this->getDirectionVarName()));  
        if (!$url){
            $dir = 'desc';
        }   
        return $dir;
    } 

    public function setCollection($collection)
    {
       parent::setCollection($collection);       


        $methods = $this->getMethods();
        if (isset($methods[$this->getCurrentOrder()])){
            $methods[$this->getCurrentOrder()]->apply($collection, $this->getCurrentDirection());
        }
        if($this->getCurrentOrder() == 'bestselling'){
        if(Mage::helper('Mymoudle')->getbestperiod() > 0){
            $limit = (int)$this->getLimit();
            $collection = Mage::helper('Mymoudle')->getBestsellingProducts($limit,$this->getCurrentDirection());
        }
    }
      if($this->getCurrentOrder() == 'most_viewed'){
        if(Mage::helper('Mymoudle')->getviewdtimeperiod() > 0){
            $limit = (int)$this->getLimit();
             $collection = Mage::helper('Mymoudle')->getMostViewedProducts($limit);
        }
        }
echo $collection->getSelect();
        return $collection;
    }
    public function getCollection()
    {
        return $this->_collection;
    }
}.
this is my Helper class :
<?php

class Mymodule_Helper_Data extends Mage_Core_Helper_Abstract
{
     const SORT_PRODUCTS_STATUS             = 'sortproducts/setting/settings';
     const SORT_PRODUCTS_POSITION_FILTER    = 'sortproducts/general/position_filter';
     const SORT_PRODUCTS_BEST_PERIOD        = 'sortproducts/general/best_period';
     const SORT_PRODUCTS_VIEWD_PERIOD       = 'sortproducts/general/viewed_period';
     const SORT_PRODUCTS_WHISLIST_PERIOD    = 'sortproducts/general/wishlist_period';

     public function getextEnable()
     {
            return Mage::getStoreConfig(self::SORT_PRODUCTS_STATUS);       
     }
    public function getpositionstatus()
    {
            return Mage::getStoreConfig(self::SORT_PRODUCTS_POSITION_FILTER);
    }
    public function getbestperiod()
    {
            return Mage::getStoreConfig(self::SORT_PRODUCTS_BEST_PERIOD);
    }
    public function getviewdtimeperiod()
    {
            return Mage::getStoreConfig(self::SORT_PRODUCTS_VIEWD_PERIOD);
    }
    public function getwishlistperiod()
    {
            return Mage::getStoreConfig(self::SORT_PRODUCTS_WHISLIST_PERIOD);
    }
    public functi

No comments:

Post a Comment