Skip to content

Commit 04f60d5

Browse files
committed
18752: make root cause visible for exception on submitQuote
Github Issue: #18752 If an exceptions happens in orderManagement->place($order) or an "sales_model_service_quote_submit_success" observer, the catch block itself fires an event that currently fails for guest checkouts in Magento\CatalogInventory\Model\ResourceModel\Stock->correctItemsQty(). This second exception hides the root exception and is logged to the exception log with the message "Rolled back transaction has not been completed correctly". This is not bound for this observer, but may occur in every other observer that is currently register or may be registered in the future. Therefore the failure event is wrapped in a try-catch itself and throws a combined exception that is logged in the exception.log.
1 parent 9480e2a commit 04f60d5

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

app/code/Magento/Quote/Model/QuoteManagement.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Exception\CouldNotSaveException;
1313
use Magento\Framework\Exception\LocalizedException;
1414
use Magento\Framework\Exception\StateException;
15+
use Magento\Framework\Phrase;
1516
use Magento\Quote\Api\Data\PaymentInterface;
1617
use Magento\Quote\Model\Quote\Address\ToOrder as ToOrderConverter;
1718
use Magento\Quote\Model\Quote\Address\ToOrderAddress as ToOrderAddressConverter;
@@ -532,19 +533,31 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
532533
);
533534
$this->quoteRepository->save($quote);
534535
} catch (\Exception $e) {
535-
if (!empty($this->addressesToSync)) {
536-
foreach ($this->addressesToSync as $addressId) {
537-
$this->addressRepository->deleteById($addressId);
536+
try {
537+
if (!empty($this->addressesToSync)) {
538+
foreach ($this->addressesToSync as $addressId) {
539+
$this->addressRepository->deleteById($addressId);
540+
}
538541
}
542+
$this->eventManager->dispatch(
543+
'sales_model_service_quote_submit_failure',
544+
[
545+
'order' => $order,
546+
'quote' => $quote,
547+
'exception' => $e,
548+
]
549+
);
550+
} catch (\Exception $consecutiveException) {
551+
$message = new Phrase(
552+
"An exception occurred on 'sales_model_service_quote_submit_failure' event: %1\n%2",
553+
[
554+
$consecutiveException->getMessage(),
555+
$consecutiveException->getTraceAsString()
556+
]
557+
);
558+
559+
throw new LocalizedException($message, $e);
539560
}
540-
$this->eventManager->dispatch(
541-
'sales_model_service_quote_submit_failure',
542-
[
543-
'order' => $order,
544-
'quote' => $quote,
545-
'exception' => $e
546-
]
547-
);
548561
throw $e;
549562
}
550563
return $order;

0 commit comments

Comments
 (0)