I have created a custom backend module which contains four fields namely name, image, date, and store view selector. Everything is working fine except store view selector, I have used a renderer to display the selected store view in Grid.
If the store is selected individually it shows correctly if All Store view option is selected it is not showing in any store during filtering. Filtering is not working for All Store View option kindly help me out to solve this issue !!
This is my renderer to show store details in the grid
<?php
class Hm_Blog_Block_Adminhtml_Blog_Renderer_Store extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$stores = $row->getStoreId();
if($stores == 0){
$store_details = Mage::app()->getStores();
foreach($store_details as $astore)
{
$websiteId = $astore->getWebsiteId();
$web = Mage::app()->getWebsite($websiteId)->getName();
echo $web ."<br>";
$data = $astore->getGroupId();
echo $data = ' '. Mage::app()->getGroup($data)->getName().'<br />';
echo $data =' '.$astore->getName().'<br />';
}
}
else{
$ids = explode(',', $stores);
foreach($ids as $storeID){
//Website details
$store = Mage::getModel('core/website')->load($storeID)->getWebsiteId();
$website_details = Mage::app()->getWebsite($store);
$web = $website_details->getName();
echo ' '. $web ."<br>";
//Store_view details
$store = Mage::getModel('core/store')->load($storeID);
$store_view =$store->getGroupId();
$store_details = Mage::app()->getGroup($store_view);
$store_view_name = $store_details->getName();
echo ' '. $store_view_name."<br>" ;
$name= $store->getName();?>
<?php //echo $store_view_name ?>
<?php echo ' '. $name ?><br>
<?php }
}
}
}
?>
This is my Grid.php
<?php
class Hm_Blog_Block_Adminhtml_Blog_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('blogGrid');
$this->setDefaultSort('blog_id');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
$this->setUseAjax(true);
}
/*public function initForm()
{
return $this;
}*/
protected function _prepareCollection()
{
$collection = Mage::getModel('blog/blog')->getCollection();
/*foreach($collection as $view){
if($view->getStoreId() && $view->getStoreId() != 0 ){
$view->setStoreId(explode(',',$view->getStoreId()));
}
else{
$view->setStoreId(array('0'));
}
}*/
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$profile = Mage::getModel('blog/blog');
$this->addColumn('blog_id', array(
'header' => Mage::helper('hm_blog')->__('Blog ID'),
'align' =>'right',
'width' => '50px',
'sortable' => true,
'index' => 'blog_id',
));
$this->addColumn('blog_name', array(
'header' => Mage::helper('hm_blog')->__('Blog Name'),
'align' =>'left',
'index' => 'blog_name',
//'width' => '200px',
));
$this->addColumn('blog_image', array(
'header' => Mage::helper('hm_blog')->__('Blog Image'),
'width' => '10px',
'index' => 'blog_image',
'renderer' => 'hm_blog/adminhtml_blog_renderer_image',
));
$this->addColumn('published_date', array(
'type' => 'datetime',
'header' => Mage::helper('hm_blog')->__('Published Date'),
//'width' => '100px',
'index' => 'published_date',
));
if (!Mage::app()->isSingleStoreMode()) {
$field = $this->addColumn('store_id', array(
'type' => 'store',
'header' => Mage::helper('hm_blog')->__('Store View'),
//'width' => '100px',
'index' => 'store_id',
'store_all' => true,
'sortable' => false,
'store_view'=> true,
'renderer' => 'Hm_Blog_Block_Adminhtml_Blog_Renderer_Store',
//'renderer' => 'adminhtml/store_switcher_form_renderer_fieldset_element',
'filter_condition_callback' => array($this,'_filterStoreCondition'),
));
//$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
//$field->setRenderer($renderer);
}
return parent::_prepareColumns();
}
protected function _afterLoadCollection()
{
$this->getCollection()->walk('afterLoad');
parent::_afterLoadCollection();
}
protected function _filterStoreCondition($collection, $column)
{
if (!$value = $column->getFilter()->getValue()){
return $this;
}
$store = Mage::app()->getWebsite($value);
// $collection->addStoreFilter($value);
return $this->getCollection()->addFieldToFilter('store_id', array('finset' => $value));
//return $this->getCollection()->addStoreFilter($value);
}
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=>true));
}
}
renderer
??