grid , get all stores of a block cms
-
23-12-2020 - |
Pregunta
I m trying to get all stores of a block cms in an adminhtml page. But something is wrong :( Here is my code :
class Upecom_Brandhub_Block_Adminhtml_Grid_Grid
extends Mage_Adminhtml_Block_Widget_Grid implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
/**
* Get tab label
*
* @return string
*/
public function getTabLabel()
{
return Mage::helper('Upecom_Brandhub')->__('Blocks');
}
/**
* Get tab title
*
* @return string
*/
public function getTabTitle()
{
return Mage::helper('Upecom_Brandhub')->__('Blocks');
}
/**
* Check if tab can be displayed
*
* @return boolean
*/
public function canShowTab()
{
return true;
}
/**
* Check if tab is hidden
*
* @return boolean
*/
public function isHidden()
{
return false;
}
public function __construct()
{
parent::__construct();
$this->setId('myTabGridBlocks');
$this->setUseAjax(false);
$this->setDefaultSort('entity_id');
$this->setDefaultDir('DESC');
$this->setEmptyText(Mage::helper('Upecom_Brandhub')->__('No records found!'));
}
protected function _prepareCollection()
{
$collection = Mage::getModel('cms/block')->getCollection()
->addFieldToFilter("brand_id", 500)
->addFieldToFilter("type_block", 6);
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn(
'identifier',
array(
'header' => Mage::helper('Upecom_Brandhub')->__('Identifier'),
'width' => '200px',
'index' => 'identifier',
)
);
if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('store_id', array(
'header' => Mage::helper('cms')->__('Store View'),
'index' => 'store_id',
'type' => 'store',
'store_all' => true,
'store_view' => true,
'sortable' => false,
'filter_condition_callback'
=> array($this, '_filterStoreCondition'),
));
}
}
}
It return me all the time nothing in the store columns (but i have everything else )
Solución
I found it, I just need to add :
protected function _afterLoadCollection()
{
$this->getCollection()->walk('afterLoad');
parent::_afterLoadCollection();
}
protected function _filterStoreCondition($collection, $column)
{
if (!$value = $column->getFilter()->getValue()) {
return;
}
$this->getCollection()->addStoreFilter($value);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange