Skip to content

Commit c61cfe1

Browse files
committed
#37028: [Sales] Missing relation data when reorder
- fix Cyclomatic Complexity
1 parent 0021d70 commit c61cfe1

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Sales\Model\Order;
2020
use Magento\Store\Model\StoreManagerInterface;
2121
use Psr\Log\LoggerInterface;
22+
use Magento\Quote\Model\Quote;
2223

2324
/**
2425
* Order create model
@@ -2004,8 +2005,31 @@ public function createOrder()
20042005

20052006
$this->_prepareQuoteItems();
20062007

2008+
$orderData = $this->beforeSubmit($quote);
2009+
$order = $this->quoteManagement->submit($quote, $orderData);
2010+
$this->afterSubmit($order);
2011+
2012+
if ($this->getSendConfirmation() && !$order->getEmailSent()) {
2013+
$this->emailSender->send($order);
2014+
}
2015+
2016+
$this->_eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
2017+
2018+
$this->removeTransferredItems();
2019+
2020+
return $order;
2021+
}
2022+
2023+
/**
2024+
* Prepare and retrieve order data before submitting a quote for order creation.
2025+
*
2026+
* @param Quote $quote
2027+
* @return array
2028+
*/
2029+
private function beforeSubmit(Quote $quote)
2030+
{
20072031
$orderData = [];
2008-
if ($this->getSession()->getReordered() || $this->getSession()->getOrder()->getId()) { //
2032+
if ($this->getSession()->getReordered() || $this->getSession()->getOrder()->getId()) {
20092033
$oldOrder = $this->getSession()->getOrder();
20102034
$oldOrder = $oldOrder->getId() ?
20112035
$oldOrder : $this->orderRepositoryInterface->get($this->getSession()->getReordered());
@@ -2022,8 +2046,20 @@ public function createOrder()
20222046
];
20232047
$quote->setReservedOrderId($orderData['increment_id']);
20242048
}
2025-
$order = $this->quoteManagement->submit($quote, $orderData);
2026-
if ($this->getSession()->getReordered() || $this->getSession()->getOrder()->getId()) { //
2049+
2050+
return $orderData;
2051+
}
2052+
2053+
/**
2054+
* Process old order after submission.
2055+
*
2056+
* @param Order $order
2057+
* @return void
2058+
* @throws \Exception
2059+
*/
2060+
private function afterSubmit(Order $order)
2061+
{
2062+
if ($this->getSession()->getReordered() || $this->getSession()->getOrder()->getId()) {
20272063
$oldOrder = $this->getSession()->getOrder();
20282064
$oldOrder = $oldOrder->getId() ?
20292065
$oldOrder : $this->orderRepositoryInterface->get($this->getSession()->getReordered());
@@ -2035,16 +2071,6 @@ public function createOrder()
20352071
}
20362072
$order->save();
20372073
}
2038-
2039-
if ($this->getSendConfirmation() && !$order->getEmailSent()) {
2040-
$this->emailSender->send($order);
2041-
}
2042-
2043-
$this->_eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
2044-
2045-
$this->removeTransferredItems();
2046-
2047-
return $order;
20482074
}
20492075

20502076
/**

0 commit comments

Comments
 (0)