Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Root exception not logged on QuoteManagement::submitQuote #21697

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 38 additions & 13 deletions app/code/Magento/Quote/Model/QuoteManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,19 +532,7 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
);
$this->quoteRepository->save($quote);
} catch (\Exception $e) {
if (!empty($this->addressesToSync)) {
foreach ($this->addressesToSync as $addressId) {
$this->addressRepository->deleteById($addressId);
}
}
$this->eventManager->dispatch(
'sales_model_service_quote_submit_failure',
[
'order' => $order,
'quote' => $quote,
'exception' => $e
]
);
$this->rollbackAddresses($quote, $order, $e);
throw $e;
}
return $order;
Expand Down Expand Up @@ -611,4 +599,41 @@ protected function _prepareCustomerQuote($quote)
$shipping->setIsDefaultBilling(true);
}
}

/**
* Remove related to order and quote addresses and submit exception to further processing.
*
* @param Quote $quote
* @param \Magento\Sales\Api\Data\OrderInterface $order
* @param \Exception $e
* @throws \Exception
*/
private function rollbackAddresses(
QuoteEntity $quote,
\Magento\Sales\Api\Data\OrderInterface $order,
\Exception $e
): void {
try {
if (!empty($this->addressesToSync)) {
foreach ($this->addressesToSync as $addressId) {
$this->addressRepository->deleteById($addressId);
}
}
$this->eventManager->dispatch(
'sales_model_service_quote_submit_failure',
[
'order' => $order,
'quote' => $quote,
'exception' => $e,
]
);
} catch (\Exception $consecutiveException) {
$message = sprintf(
"An exception occurred on 'sales_model_service_quote_submit_failure' event: %s",
$consecutiveException->getMessage()
);

throw new \Exception($message, 0, $e);
}
}
}