Skip to content

Commit

Permalink
18752: make root cause visible for exception on submitQuote
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
david-fuehr committed Mar 8, 2019
1 parent 9480e2a commit 04f60d5
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions app/code/Magento/Quote/Model/QuoteManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\StateException;
use Magento\Framework\Phrase;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Quote\Model\Quote\Address\ToOrder as ToOrderConverter;
use Magento\Quote\Model\Quote\Address\ToOrderAddress as ToOrderAddressConverter;
Expand Down Expand Up @@ -532,19 +533,31 @@ 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);
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 = new Phrase(
"An exception occurred on 'sales_model_service_quote_submit_failure' event: %1\n%2",
[
$consecutiveException->getMessage(),
$consecutiveException->getTraceAsString()
]
);

throw new LocalizedException($message, $e);
}
$this->eventManager->dispatch(
'sales_model_service_quote_submit_failure',
[
'order' => $order,
'quote' => $quote,
'exception' => $e
]
);
throw $e;
}
return $order;
Expand Down

0 comments on commit 04f60d5

Please sign in to comment.