1

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 )

  • Are you able to see your store column in your grid? – Priyank Dec 27 '17 at 9:59
  • Yes, but not values. , i just found the answer (see the asnwer :) ) – thomas poidevin Dec 27 '17 at 10:02
0

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);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.