1

I think it would be necessary to place an order in admin page. I want to show the stock level at order creation (in backend) during product selection stage in the search grid (Sales_Order_Create_Search_Grid).

How can I go about doing this?

This is a solution for Magento1. https://stackoverflow.com/questions/17069097/magento-show-stock-levels-in-sales-order-create-search-grid

How can i handle with it on Magento2?

Thank you

2
  • I have the same request - any help`?
    – Simon
    Aug 27, 2018 at 14:53
  • Please add this as a comment, this is not an answer Aug 27, 2018 at 15:27

1 Answer 1

3

You need to create Vendor_Module and do the following: Override the Grid.php like below:

<?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\Sales\Block\Adminhtml\Order\Create\Search\Grid" type="Vendor\Module\Block\Adminhtml\Order\Create\Search\Grid" />
</config>

Add the below code to your Grid.php in the below location:

app/code/Vendor/Module/Block/Adminhtml/Order/Create/Search/Grid.php

Code for Grid.php:

<?php
namespace Vendor\Module\Block\Adminhtml\Order\Create\Search;

class Grid extends \Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid
{
    protected $_salesConfig;
    protected $_sessionQuote;
    protected $_catalogConfig;
    protected $_productFactory;

    protected function _prepareColumns()
    {
        $this->addColumn(
            'available_qty',
            [
                'filter' => false,
                'sortable' => false,
                'header' => __('Available Quantity'),
                'renderer' => \Vendor\Module\Block\Adminhtml\Order\Create\Search\Grid\Renderer\Availableqty::class,
                'name' => 'available_qty',
                'inline_css' => 'available_qty',
                'type' => 'input',
                'validate_class' => 'validate-number',
                'index' => 'available_qty',
                'sortOrder' => 500
            ]
        );

        return parent::_prepareColumns();
    }
}

Create one more class Availableqty.php under below location:

app/code/Vendor/Module/Block/Adminhtml/Order/Create/Search/Grid/Renderer/Availableqty.php

and add the below code:

<?php
namespace Vendor\Module\Block\Adminhtml\Order\Create\Search\Grid\Renderer;

class Availableqty extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Text
{
    private $stockItem;
    public function __construct(\Magento\CatalogInventory\Api\StockStateInterface $stockItem)
    {
        $this->stockItem = $stockItem;
    }
    public function render(\Magento\Framework\DataObject $row)
    {
        return $this->stockItem->getStockQty($row->getId(), $row->getStore()->getWebsiteId());
    }
}

Run setup:upgrade and di:compile and test.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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