0

I would like to add an extra column based on a product attribute <my_attribute_code> in the product grid that appears when editing a category in the section "Products In Category" ideally before the SKU Column

enter image description here

Is it possible?

1

Try following way to add a column. I have added a product creation time column as an example:

app/code/SR/MagentoCommunity/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\MagentoCommunity\Block\Adminhtml\Category\Tab\Product"/>
</config>

app/code/SR/MagentoCommunity/Block/Adminhtml/Category/Tab/Product.php

<?php
namespace SR\MagentoCommunity\Block\Adminhtml\Category\Tab;

class Product extends \Magento\Catalog\Block\Adminhtml\Category\Tab\Product
{
    /**
     * Set collection object
     *
     * @param \Magento\Framework\Data\Collection $collection
     * @return void
     */
    public function setCollection($collection)
    {
        $collection->addAttributeToSelect('created_at');
        parent::setCollection($collection);
    }

    /**
     * @return $this
     */
    protected function _prepareColumns()
    {
        parent::_prepareColumns();
        $this->addColumnAfter('created_at', array(
            'header' => __('Created At'),
            'index' => 'created_at',
        ), 'sku');

        $this->sortColumnsByOrder();
        return $this;
    }
}
  • Thanks I'll try that and test :) – gabtzi May 22 at 12:24
  • It worked great. I was able to add my attribute like this :) Thank you very much – gabtzi May 22 at 12:46

Your Answer

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

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