How to list only enabled product in backend order in magento 2?

by Dipika Walanjkar   Last Updated January 13, 2018 17:09 PM

In magento 2, from backend trying to place order but while selecting product from product grid it is including enable and disable product.

But i want to list only enabled product from grid.

For more deatils attaching screen-shot.

enter image description here



Answers 1


Over ride below block and add filter in collection:

Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid

    <?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Grid
 *
 * @author pramod
 */

namespace Custom\Sales\Block\Adminhtml\Order\Create\Search;

class Grid extends \Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid {

    /**
     * Constructor
     *
     * @return void
     */
    protected function _construct() {
        parent::_construct();
        $this->setId('sales_order_create_search_grid');
        $this->setRowClickCallback('order.productGridRowClick.bind(order)');
        $this->setCheckboxCheckCallback('order.productGridCheckboxCheck.bind(order)');
        $this->setRowInitCallback('order.productGridRowInit.bind(order)');
        $this->setDefaultSort('entity_id');
        $this->setUseAjax(true);
        if ($this->getRequest()->getParam('collapse')) {
            $this->setIsCollapsed(true);
        }
    }

    /**
     * Prepare collection to be displayed in the grid
     *
     * @return $this
     */
    protected function _prepareCollection() {
        $attributes = $this->_catalogConfig->getProductAttributes();
        /* @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
        $collection = $this->_productFactory->create()->getCollection();
        $collection->setStore(
                $this->getStore()
        )->addAttributeToSelect(
                $attributes
        )->addAttributeToSelect(
                'sku'
        )->addStoreFilter()->addAttributeToFilter(
                'type_id', $this->_salesConfig->getAvailableProductTypes()
        )->addAttributeToSelect(
                'gift_message_available'
        )->addAttributeToFilter('status', array('eq' => 1));
        $this->setCollection($collection);
        return $this->setCollection($collection);
    }

}
Pramod Kharade
Pramod Kharade
January 13, 2018 17:31 PM

Related Questions



Why my sales aren't showing in Magento 2 Admin Panel?

Updated December 28, 2017 14:09 PM


Billing and Shipping Company Column on Sales Order Grid

Updated December 09, 2017 00:09 AM