0

in my case i want to delete a column 'Status' ,my problem is that i can't remove it by preference in di.xml

the preference override it works fine with other methods but this method no , i dont know why

this file is Mymodule\Dealer\Block\Adminhtml\Dealer\Grid\Reports


protected function _prepareColumns()
    {
        $this->addColumn('m_increment_id', array(
            'header'       => __('Order #'),
            'width'        => '100',
            'index'        => 'm_increment_id',
            'filter_index' => 'main_table.increment_id',
        ));

        $this->addColumn('m_created_at', array(
            'header'       => __('Purchase On'),
            'index'        => 'm_created_at',
            'type'         => 'm_datetime',
            'filter_index' => 'main_table.created_at',
        ));

          //$this->addColumn('status', array(
           // 'header'       => __('Status'),
           // 'index'        => 'm_status',
           // 'filter_index' => 'main_table.status',
           // 'type'         => 'options',
            //'width'        => '70px',
//            'options'      => Mage::getSingleton('sales/order_config')->getStatuses(),
       // ));

        return parent::_prepareColumns();
    }

the file for override in di.xml

<preference for="\Amasty\Perm\Block\Adminhtml\Dealer\Grid\Reports"
                type="Mymodule\Dealer\Block\Adminhtml\Dealer\Grid\Reports" />

can anyone help me please ?

1 Answer 1

3

The problem is that you call return parent::_prepareColumns(); and in that parent class in that method the status column is again declared. Maybe try to override method like this:

protected function _prepareColumns()
{
    parent::_prepareColumns();
    $this->removeColumn('status');
}

or just remove return parent::_prepareColumns(); in your code. But the first solution in better.

5
  • thank you bro , it work but with just return parent::_prepareColumns(); , but when i add this it didn't work , they tell to me "'Unreachable statement " Commented May 7, 2020 at 22:47
  • 1
    probably the parent metod return $this so, modify the metod like this: protected function _prepareColumns() { $return = parent::_prepareColumns(); $return->removeColumn('status'); return $return; }
    – Adam S.
    Commented May 8, 2020 at 7:36
  • yes it work thanks a lot Commented May 8, 2020 at 10:20
  • how can i see what does parent::_prepareColumns(); contain , i have do vardump() to it but it didn't work Commented May 8, 2020 at 10:32
  • 1
    Better tool to verify the content of the returned method is use the xdebug. But you can simply read the parent code and you should be able to understand what happened there - go to the parent class you override it’s located under vendor/magento directory.
    – Adam S.
    Commented May 9, 2020 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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