Pergunta

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

Foi útil?

Solução

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

/vendor/magento/module-sales/Model/AdminOrder/Create.php

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(
        \Magento\Catalog\Model\Product::class
    )->setStoreId(
        $this->getSession()->getStoreId()
    )->load(
        $orderItem->getProductId()
    );


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

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

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

        $this->_eventManager->dispatch(
            'sales_convert_order_item_to_quote_item',
            ['order_item' => $orderItem, 'quote_item' => $item]
        );
        return $item;
    }

    return $this;
}

No need to change anything.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top