We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    If you want to add custom column in product grid, then follow below step to create custom module to add custom column in grid.

    Step 1) app/code/Magemonkeys/SalesordercreategridCustomattr/registration.php

    <?php
    MagentoFrameworkComponentComponentRegistrar::register(
        MagentoFrameworkComponentComponentRegistrar::MODULE,
        'Magemonkeys_SalesordercreategridCustomattr',
        __DIR__
    );

    Step 2) app/code/Magemonkeys/SalesordercreategridCustomattr/etc/module.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Magemonkeys_SalesordercreategridCustomattr" setup_version="1.0.0">
        </module>
    </config>

    Step 3) app/code/Magemonkeys/SalesordercreategridCustomattr/etc/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="MagentoSalesBlockAdminhtmlOrderCreateSearchGrid" type="MagemonkeysSalesordercreategridCustomattrBlockAdminhtmlOrderCreateSearchGrid" />
    </config>

    Step 4) app/code/Magemonkeys/SalesordercreategridCustomattr/Block/Adminhtml/Order/Create/Search/Grid.php

    <?php
    namespace MagemonkeysSalesordercreategridCustomattrBlockAdminhtmlOrderCreateSearch;
    
    class Grid extends MagentoSalesBlockAdminhtmlOrderCreateSearchGrid
    {
        /**
         * @param MagentoBackendBlockTemplateContext $context
         * @param MagentoBackendHelperData $backendHelper
         * @param MagentoCatalogModelProductFactory $productFactory
         * @param MagentoCatalogModelConfig $catalogConfig
         * @param MagentoBackendModelSessionQuote $sessionQuote
         * @param MagentoSalesModelConfig $salesConfig
         * @param array $data
         */
        public function __construct(
            MagentoBackendBlockTemplateContext $context,
            MagentoBackendHelperData $backendHelper,
            MagentoCatalogModelProductFactory $productFactory,
            MagentoCatalogModelConfig $catalogConfig,
            MagentoBackendModelSessionQuote $sessionQuote,
            MagentoSalesModelConfig $salesConfig,
            array $data = []
        )
        {
            $this->_productFactory = $productFactory;
            $this->_catalogConfig = $catalogConfig;
            $this->_sessionQuote = $sessionQuote;
            $this->_salesConfig = $salesConfig;
            parent::__construct($context, $backendHelper, $productFactory, $catalogConfig, $sessionQuote, $salesConfig, $data);
        }
    
        /**
         * Prepare collection to be displayed in the grid
         *
         * @return $this
         */
        protected function _prepareCollection()
        {
            $attributes = $this->_catalogConfig->getProductAttributes();
            /* @var $collection MagentoCatalogModelResourceModelProductCollection */
            $collection = $this->_productFactory->create()->getCollection();
            $collection->setStore(
                $this->getStore()
            )->addAttributeToSelect(
                $attributes
            )->addAttributeToSelect(
                'sku'
            )->addStoreFilter()->addAttributeToFilter(
                'type_id',
                $this->_salesConfig->getAvailableProductTypes()
            )->addAttributeToSelect(
                'gift_message_available'
            );
    
            $collection->joinField(
                'qty_in_stock',
                'cataloginventory_stock_item',
                'qty',
                'product_id=entity_id',
                '{{table}}.stock_id=1 AND {{table}}.website_id=0',
                'left'
            );
    
            $this->setCollection($collection);
    
            $parent = get_parent_class($this);
            $parentclass = get_parent_class($parent);
            return $parentclass::_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' => MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererProduct::class,
                    'index' => 'name'
                ]
            );
            $this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku']);
            $this->addColumn('customsku', ['header' => __('Custom SKU'), 'index' => 'customsku']);
            $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' => MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererPrice::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' => MagentoSalesBlockAdminhtmlOrderCreateSearchGridRendererQty::class,
                    'name' => 'qty',
                    'inline_css' => 'qty',
                    'type' => 'input',
                    'validate_class' => 'validate-number',
                    'index' => 'qty'
                ]
            );
    
            $this->addColumn(
                'qty_in_stock',
                [
                    'header' => __('Stock'),
                    'type' => 'number',
                    'index' => 'qty_in_stock'
                ]
            );
    
            $parent = get_parent_class($this);
            $parentclass = get_parent_class($parent);
            return $parentclass::_prepareColumns();
        }
    }

    Step 5 : After place above code, please run below mentioned commands

    - php bin/magento setup:upgrade
    - php bin/magento setup:static-content:deploy
    - php bin/magento cache:clean

     

    That’s it…

    Now refresh your sales order, create grid page and see that your custom column will be reflecting there.

    Fill the below form if you need any Magento relate help/advise/consulting.

    With Only Agency that provides a 24/7 emergency support.

      Get a Free Quote