1

I'm overwriting a method to change the configuration of the table, the problem is that this column doubles it, magento adds the column of the overwritten file and the original file, if I delete the original file does not appear but is not a good solution.

Why it happens?

enter image description here

Original file:

namespace Mod\SapOnlineCrm\Block\Adminhtml\Docs;

class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
{    
    /**
     * @var \Magento\Framework\Message\ManagerInterface
     */
    protected $messageManager;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Backend\Helper\Data $backendHelper,
        \Gsp\SapOnlineCrm\Framework\Data\CollectionFactory $collectionFactory,
        \Magento\Framework\DataObjectFactory $dataObjectFactory,
        \Gsp\SapOnlineCrm\Helper\DocsWS $docsWS,
        \Magento\Backend\Model\Auth\Session $authSession,
        \Magento\Framework\Message\ManagerInterface $messageManager,
        array $data = []
    )
    {
        $this->collectionFactory = $collectionFactory;
        $this->dataObjectFactory = $dataObjectFactory;
        $this->docsWS = $docsWS;
        $this->authSession = $authSession;

        $this->messageManager = $messageManager;

        parent::__construct($context, $backendHelper, $data);
    }       

    protected function _prepareColumns()
    {
        if ($this->isOrder()) {
            $this->addColumn(
                'OrderStatus',
                [
                    'header' => __('Order status'),
                    'index' => 'OrderStatus',
                    'type' => 'options',
                    'options' => $this->getAttributeOptionsOrderStatuses()
                ]
            );
        }
        $this->addColumn(
            'DocNum',
            [
                'header' => __('Number'),
                'index' => 'DocNum',
                'type' => 'range'
            ]
        );
        $this->addColumn(
            'ExternalDocEntry',
            [
                'header' => __('Web Order'),
                'index' => 'ExternalDocEntry',
                'type' => 'range'
            ]
        );
        $this->addColumn(
            'CardCode',
            [
                'header' => __('Customer'),
                'index' => 'CardCode',
                'type' => 'text'
            ]
        );
        $this->addColumn(
            'CardName',
            [
                'header' => __('Name'),
                'index' => 'CardName',
                'type' => 'text'
            ]
        );
        $this->addColumn(
            'DocDate',
            [
                'header' => __('Date'),
                'index' => 'DocDate',
                'type' => 'date',
            ]
        );

        $this->addColumn(
            'DocDueDate',
            [
                'header' => __('DueDate'),
                'index' => 'DocDueDate',
                'type' => 'date',
            ]
        );

        if ($this->getModaEnabled()) {
            $this->addColumn(
                'SeasonCode',
                [
                    'header' => __('Season'),
                    'index' => 'SeasonCode',
                    'type' => 'options',
                    'options' => $this->getAttributeOptionsSeasons()
                ]
            );
        }

        $this->addColumn(
            'DocTotal',
            [
                'header' => __('Amount'),
                'index' => 'DocTotal',
                'type' => 'range',
                'renderer' => '\Mod\SapOnlineCrm\Block\Widget\Grid\Column\Renderer\Currency',
            ]
        );

        return parent::_prepareColumns();
    }    


    protected function getAttributeOptionsOrderStatuses()
    {
        return [
            '' => ' ',
            'O' => __('Opened'),
            'C' => __('Closed'),
            'E' => __('Orders partially delivered'),
            'EC' => __('Orders delivered completely'),
            'L' => __('Blocked orders'),
            'P' => __('Pending orders')
        ];
    }


}

Intermediate file

namespace Mod\SapOnlineCrm\Block\Adminhtml\Orders;

class Grid extends \Mod\SapOnlineCrm\Block\Adminhtml\Docs\Grid
{
    /**
     * {@inheritdoc}
     */
    protected function _prepareLayout()
    {
        $this->type = parent::ORDERS;
        return parent::_prepareLayout();
    }

    /**
     * {@inheritdoc}
     */
    protected function _beforeToHtml()
    {
        $this->_prepareData();
        return parent::_beforeToHtml();
    }
}

Override file:

namespace Mod\ShadFamilyProducts\Block\SapOnlineCrm\Adminhtml\Docs;

class Grid extends \Mod\SapOnlineCrm\Block\Adminhtml\Orders\Grid
{

    const PARAM_ORDERSTATUS = 'OrderStatusShad';

    protected function _prepareColumns()
    {
        if ($this->isOrder()) {
            $this->addColumn(
                'OrderStatusShad',
                [
                    'header' => __('Order status'),
                    'index' => 'OrderStatusShad',
                    'type' => 'options',
                    'options' => $this->getAttributeOptionsOrderStatuses()
                ]
            );
        }
        $this->addColumn(
            'DocNum',
            [
                'header' => __('Document Number'),
                'index' => 'DocNum',
                'type' => 'range'
            ]
        );
        $this->addColumn(
            'ExternalDocEntry',
            [
                'header' => __('Web Order'),
                'index' => 'ExternalDocEntry',
                'type' => 'range'
            ]
        );
        $this->addColumn(
            'CardCode',
            [
                'header' => __('Customer'),
                'index' => 'CardCode',
                'type' => 'text'
            ]
        );
        $this->addColumn(
            'CardName',
            [
                'header' => __('Name'),
                'index' => 'CardName',
                'type' => 'text'
            ]
        );
        $this->addColumn(
            'DocDate',
            [
                'header' => __('Create Date'),
                'index' => 'DocDate',
                'type' => 'date',
            ]
        );

        $this->addColumn(
            'DocDueDate',
            [
                'header' => __('Delivery Date'),
                'index' => 'DocDueDate',
                'type' => 'date',
            ]
        );

        if ($this->getModaEnabled()) {
            $this->addColumn(
                'SeasonCode',
                [
                    'header' => __('Season'),
                    'index' => 'SeasonCode',
                    'type' => 'options',
                    'options' => $this->getAttributeOptionsSeasons()
                ]
            );
        }

        $this->addColumn(
            'DocTotal',
            [
                'header' => __('Amount'),
                'index' => 'DocTotal',
                'type' => 'range',
                'renderer' => '\Mod\SapOnlineCrm\Block\Widget\Grid\Column\Renderer\Currency',
            ]
        );

        return parent::_prepareColumns();
    }

    protected function getAttributeOptionsOrderStatuses()
    {
        return [
            '' => ' ',
            10 => __('Not confirmed'),
            22 => __('Locked'),
            33 => __('Confirmed'),
            44 => __('Picking list issued'),
            66 => __('Prepared'),
            70 => __('Order sent'),
            77 => __('Invoiced'),
            90 => __('Canceled')
        ];
    }

}

There are more columns but they do not come out duplicated.

7
  • Can you post the whole code you have written? Jul 9, 2018 at 8:58
  • @SukumarGorai now I show it
    – chdzma
    Jul 9, 2018 at 9:12
  • @SukumarGorai Sorry, I was referring to the code, the column is still duplicated :(
    – chdzma
    Jul 9, 2018 at 9:15
  • Can you change this OrderStatusShad to OrderStatus? Jul 9, 2018 at 9:18
  • @SukumarGorai that was the problem: D, I thought I could completely overwrite the method. I will have to inform myself.
    – chdzma
    Jul 9, 2018 at 9:23

1 Answer 1

2

As if you changed the name then magento identifies it as separate attribute or field thats why its not working.

You need to use the below code:

if ($this->isOrder()) {
    $this->addColumn(
        'OrderStatus',
        [
            'header' => __('Order status'),
            'index' => 'OrderStatus',
            'type' => 'options',
            'options' => $this->getAttributeOptionsOrderStatuses()
        ]
    );

}

instead of yours

if ($this->isOrder()) {
    $this->addColumn(
        'OrderStatusShad',
        [
            'header' => __('Order status'),
            'index' => 'OrderStatusShad',
            'type' => 'options',
            'options' => $this->getAttributeOptionsOrderStatuses()
        ]
    );
}

Hope this helps!

Your Answer

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

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