Question

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.

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top