Skip to content

Commit dd4c0a3

Browse files
authored
ENGCOM-4520: Root exception not logged on QuoteManagement::submitQuote #21697
2 parents bcf3358 + 62f3955 commit dd4c0a3

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

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

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -532,19 +532,7 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
532532
);
533533
$this->quoteRepository->save($quote);
534534
} catch (\Exception $e) {
535-
if (!empty($this->addressesToSync)) {
536-
foreach ($this->addressesToSync as $addressId) {
537-
$this->addressRepository->deleteById($addressId);
538-
}
539-
}
540-
$this->eventManager->dispatch(
541-
'sales_model_service_quote_submit_failure',
542-
[
543-
'order' => $order,
544-
'quote' => $quote,
545-
'exception' => $e
546-
]
547-
);
535+
$this->rollbackAddresses($quote, $order, $e);
548536
throw $e;
549537
}
550538
return $order;
@@ -611,4 +599,41 @@ protected function _prepareCustomerQuote($quote)
611599
$shipping->setIsDefaultBilling(true);
612600
}
613601
}
602+
603+
/**
604+
* Remove related to order and quote addresses and submit exception to further processing.
605+
*
606+
* @param Quote $quote
607+
* @param \Magento\Sales\Api\Data\OrderInterface $order
608+
* @param \Exception $e
609+
* @throws \Exception
610+
*/
611+
private function rollbackAddresses(
612+
QuoteEntity $quote,
613+
\Magento\Sales\Api\Data\OrderInterface $order,
614+
\Exception $e
615+
): void {
616+
try {
617+
if (!empty($this->addressesToSync)) {
618+
foreach ($this->addressesToSync as $addressId) {
619+
$this->addressRepository->deleteById($addressId);
620+
}
621+
}
622+
$this->eventManager->dispatch(
623+
'sales_model_service_quote_submit_failure',
624+
[
625+
'order' => $order,
626+
'quote' => $quote,
627+
'exception' => $e,
628+
]
629+
);
630+
} catch (\Exception $consecutiveException) {
631+
$message = sprintf(
632+
"An exception occurred on 'sales_model_service_quote_submit_failure' event: %s",
633+
$consecutiveException->getMessage()
634+
);
635+
636+
throw new \Exception($message, 0, $e);
637+
}
638+
}
614639
}

0 commit comments

Comments
 (0)