我想在 Magento 2 的产品网格中添加一个新列。我di.xml
在模块etc
文件夹中使用以下代码创建了文件:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Block\Adminhtml\Product\Grid" type="Package\Module\Block\Grid" />
</config>
在Grid
块中,我有以下代码:
namespace Package\Module\Block;
use Magento\Store\Model\Store;
class Grid extends \Magento\Catalog\Block\Adminhtml\Product\Grid
{
protected function _prepareColumns()
{
$this->addColumn(
'newfield',
[
'header' => __('Test Name'),
'index' => 'name',
'class' => 'xxx'
]
);
return parent::_prepareColumns();
}
}
有人可以为此指导我。