In magento 2 I need to add columns (stock, status, brand) in this admin grid :
Sales > Order > Create new order > Select Product Grid
Do you know how to achieve this ?
Thank you
Override the Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid.php
and add the column in _prepareColumns function just like i have added the column of name custom. This file is responsible for Sales > Order > Create new order > Select Product Grid
.
/**
* Prepare collection to be displayed in the grid
*
* @return $this
*/
protected function _prepareCollection()
{
$attributes = $this->_catalogConfig->getProductAttributes();
$store = $this->getStore();
/* @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
$collection = $this->productCollectionProvider->getCollectionForStore($store);
$collection->addAttributeToSelect(
$attributes
);
$collection->addAttributeToFilter(
'type_id',
$this->_salesConfig->getAvailableProductTypes()
);
$this->setCollection($collection);
return parent::_prepareCollection();
}
/**
* Prepare columns
*
* @return $this
*/
protected function _prepareColumns()
{
$this->addColumn(
'entity_id',
[
'header' => __('ID'),
'sortable' => true,
'header_css_class' => 'col-id',
'column_css_class' => 'col-id',
'index' => 'entity_id'
]
);
$this->addColumn(
'name',
[
'header' => __('Product'),
'renderer' => \Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid\Renderer\Product::class,
'index' => 'name'
]
);
$this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku']);
$this->addColumn(
'price',
[
'header' => __('Price'),
'column_css_class' => 'price',
'type' => 'currency',
'currency_code' => $this->getStore()->getCurrentCurrencyCode(),
'rate' => $this->getStore()->getBaseCurrency()->getRate($this->getStore()->getCurrentCurrencyCode()),
'index' => 'price',
'renderer' => \Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid\Renderer\Price::class
]
);
$this->addColumn(
'in_products',
[
'header' => __('Select'),
'type' => 'checkbox',
'name' => 'in_products',
'values' => $this->_getSelectedProducts(),
'index' => 'entity_id',
'sortable' => false,
'header_css_class' => 'col-select',
'column_css_class' => 'col-select'
]
);
$this->addColumn(
'qty',
[
'filter' => false,
'sortable' => false,
'header' => __('Quantity'),
'renderer' => \Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid\Renderer\Qty::class,
'name' => 'qty',
'inline_css' => 'qty',
'type' => 'input',
'validate_class' => 'validate-number',
'index' => 'qty'
]
);
//extra column.
$this->addColumn(
'custom',
[
'header' => __('Custom'),
'index' => 'custom'
]
);
return parent::_prepareColumns();
}