SHARE
TWEET

Untitled

a guest Jun 18th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Company_Banner_Block_Adminhtml_Homepage_Grid extends Mage_Adminhtml_Block_Widget_Grid {
  4.  
  5.     public function __construct() {      
  6.         parent::__construct();
  7.         $this->setId("homepageGrid");
  8.         $this->setDefaultSort("order");
  9.         $this->setDefaultDir("DESC");
  10.         $this->setSaveParametersInSession(true);
  11.     }
  12.  
  13.     public function initForm()
  14.     {
  15.         return $this;
  16.     }
  17.  
  18.     protected function _prepareCollection()
  19.     {
  20.         $collection = Mage::getModel("company_banner/homepage")
  21.             ->getCollection();
  22.  
  23.         $collection->getSelect();
  24.  
  25.         foreach ($collection as $view) {
  26.             if ( $view->getStores() && $view->getStores() != 0 ) {
  27.                 $view->setStores(explode(',',$view->getStores()));
  28.             } else {
  29.                 $view->setStores(array('0'));
  30.             }
  31.         }
  32.         $this->setCollection($collection);
  33.         return parent::_prepareCollection();
  34.     }
  35.  
  36.     protected function _prepareColumns()
  37.     {
  38.         $this->addColumn("entity_id", array(
  39.             "header" => Mage::helper("company_banner")->__("ID"),
  40.             "align" => "right",
  41.             "width" => "50px",
  42.             "type" => "number",
  43.             "index" => "entity_id",
  44.         ))
  45.  
  46.         ->addColumn("title", array(
  47.             "header" => Mage::helper("company_banner")->__("Title"),
  48.             "align" => "left",
  49.             "type" => "text",
  50.             "index" => "title",
  51.         ))
  52.         ->addColumn("subtitle", array(
  53.             "header" => Mage::helper("company_banner")->__("Subtitle"),
  54.             "align" => "left",
  55.             "type" => "text",
  56.             "index" => "subtitle",
  57.         ));
  58.  
  59.  
  60.         $this->addColumn('store_id', array(
  61.             'header'        => Mage::helper('company_banner')->__('Store View'),
  62.             'index'         => 'stores',
  63.             'type'          => 'store',
  64.             'store_all'     => true,
  65.             'store_view'    => true,
  66.             'sortable'      => false,
  67.             'filter_condition_callback' => array($this, '_filterStoreCondition'),
  68.  
  69.         ));
  70.  
  71.  
  72.  
  73.         return parent::_prepareColumns();
  74.     }
  75.  
  76.  
  77.  
  78.    protected function _filterStoreCondition($collection, $column)
  79.     {
  80.         if (!$value = $column->getFilter()->getValue()) {
  81.             return;
  82.         }
  83.  
  84.          $this->getCollection()->addFieldToFilter('stores', array('finset' => $value));
  85.     }
  86.  
  87. }
  88.      
  89. foreach ($collection as $view) {
  90.             if ( $view->getStores() && $view->getStores() != 0 ) {
  91.                 $view->setStores(explode(',',$view->getStores()));
  92.             } else {
  93.                 $view->setStores(array('0'));
  94.             }
  95.         }
  96.      
  97. $this->addColumn('store', array(
  98.                     'header' => 'Website',
  99.                     'index' => 'store',
  100.                     'type' => 'store',
  101.                     'width' => '100px',
  102.                     'store_view'=> true,
  103.                     'display_deleted' => false,
  104.                     'renderer' => 'Namespace_Modulename_Block_Adminhtml_Store',
  105.                     ));
  106.      
  107. <?php
  108.  
  109. class Namespcae_Modulename_Block_Adminhtml_Store
  110.     extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
  111. {
  112.     public function render(Varien_Object $row)
  113.     {    $store=explode(',',$row->getStore());
  114.  
  115.             $data="";
  116.          if($row->getStore()!="" and $row->getStore()==0)
  117.          {
  118.             $allstore=Mage::app()->getStores();
  119.             foreach($allstore as $astore)
  120.             {
  121.                 $data.=$astore->getName().'<br />';
  122.             }
  123.  
  124.              } else {
  125.                 $data="";
  126.                 $a=0;
  127.                 foreach ($store as $sto)
  128.                 {
  129.                      $data= $data.Mage::getModel('core/store')->load($sto[$a])->getName().'<br>';
  130.                  $a+1;}
  131.              }
  132.  
  133.         return $data;
  134.     }
  135. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top