3

Note: Before marking the question as duplicate or off-topic, please read the question carefully.

Scenario: I have to show custom column in the admin grid of a custom extension. So I used override feature of Magento 2 and extended the original Grid class to customize it.

Below is sample code block for overriding the Grid.php class:

namespace Stream\OverrideStockMovement\Block;

use Magento\Backend\Block\Widget\Grid\Column;

class Grid extends \BoostMyShop\AdvancedStock\Block\StockMovement\Grid
{

It is working fine now.

There is a similar grid, which is showing in the edit form which is extending the same \BoostMyShop\AdvancedStock\Block\StockMovement\Grid class to show the same data for particular product.

Below is the sample code block for above class:

<?php

namespace BoostMyShop\AdvancedStock\Block\ErpProduct\Edit\Tab;
use Magento\Backend\Block\Widget\Grid\Column;

class StockMovement extends \BoostMyShop\AdvancedStock\Block\StockMovement\Grid implements \Magento\Backend\Block\Widget\Tab\TabInterface
{

Now, the problem is that, since the StockMovement class extending from \BoostMyShop\AdvancedStock\Block\StockMovement\Grid class, my changes in the Stream\OverrideStockMovement\Block\Grid class are not being extended in this file.

If I use:

class StockMovement extends 
\Stream\OverrideStockMovement\Block\Grid implements \Magento\Backend\Block\Widget\Tab\TabInterface

instead of

class StockMovement extends \BoostMyShop\AdvancedStock\Block\StockMovement\Grid implements \Magento\Backend\Block\Widget\Tab\TabInterface
    {

My custom column is displayed in the grid, but I don't want to make changes in the extension's file.

I want to override the class with my own module's class file, so that I can make sure future upgrades of the extension are working fine.

Edit: I can't create plugin to extend the functionality, because the function, which I want to modify is a protected function.

Please help me, how can I do this?

Any help will be appreciated.

Your Answer

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

Browse other questions tagged or ask your own question.