enter image description hereHow to not display out of stock products when we place reorder admin panel(Back-end) Please help me out.

1 Answer 1


You need to override the below file to your custom module:


and change the function initFromOrderItem like below:

public function initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $qty = null)
    if (!$orderItem->getId()) {
        return $this;

    $product = $this->_objectManager->create(

    $stockItem = $this->stockRegistry->getStockItem($orderItem->getProductId());
    if($stockItem->getData('is_in_stock') != 1){
        return $this;

    if ($product->getId()) {
        $buyRequest = $orderItem->getBuyRequest();
        if (is_numeric($qty)) {
        $item = $this->getQuote()->addProduct($product, $buyRequest);
        if (is_string($item)) {
            return $item;

        if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) {
                new \Magento\Framework\DataObject(
                        'product' => $item->getProduct(),
                        'code' => 'additional_options',
                        'value' => $this->serializer->serialize($additionalOptions)

            ['order_item' => $orderItem, 'quote_item' => $item]
        return $item;

    return $this;

No need to change anything.

  • Its not working for me Sukumar Gorai... Sep 28, 2018 at 12:41
  • When i search for product that is out of stock should not display.. Sukumar Gorai... Sep 28, 2018 at 12:48
  • This will not add out of products from that order. According to requirement this is correctly working. Try to change it in vendor folder and then test. Sep 28, 2018 at 12:48
  • I have followed as above you said but when i place reorder from admin panel product of out stock its successfully order placed Sukumar Gorai.. Sep 28, 2018 at 12:56
  • According to the answer it removes the product which is out of stock and added the products which are in stock. Clear the cache and test again. This will work from admin only. Sep 28, 2018 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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