Magento 2.1.7 how to not display out of stock products in reorder admin panel
-
29-01-2021 - |
解決
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.
所属していません magento.stackexchange