1

enter image description hereIs there any way to add a custom attirbute in here? (See picture). I know the file is in

/vendor/magento/module-backend/view/adminhtml/templates/widget/grid/extended.phtml

But I have no idea how to add ?

1 Answer 1

1

Try following way:

SR/Stackexchange/etc/adminhtml/di.xml


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Catalog\Block\Adminhtml\Category\Tab\Product" type="SR\Stackexchange\Block\Catalog\Adminhtml\Category\Tab\Product"/>
</config>

SR/Stackexchange/Block/Catalog/Adminhtml/Category/Tab/Product.php


namespace SR\Stackexchange\Block\Catalog\Adminhtml\Category\Tab;

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

class Product extends \Magento\Catalog\Block\Adminhtml\Category\Tab\Product
{
    /**
     * @return Grid
     */
    protected function _prepareCollection()
    {
        $grid = parent::_prepareCollection();

        $collection = $this->getCollection();
        $collection->joinTable(
            'cataloginventory_stock_status',
            'product_id=entity_id',
            ["stock_status" => "stock_status"],
            null ,
            'left'
        )->addAttributeToSelect('stock_status');

        $this->setCollection($collection);
        if ($this->getCollection()->isLoaded()) {
            $this->getCollection()->clear();
        }
        return $grid;
    }

    /**
     * @return Extended
     */
    protected function _prepareColumns()
    {
        parent::_prepareColumns();

        $this->addColumn('stock_status', ['header' => __('Stock Status'), 'index' => 'stock_status']);

        return $this;
    }
}
1
  • I have follow your code but it is not working
    – Jinesh
    Dec 24, 2019 at 12:20

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.