@@ -529,28 +529,7 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
529
529
);
530
530
$ this ->quoteRepository ->save ($ quote );
531
531
} catch (\Exception $ e ) {
532
- try {
533
- if (!empty ($ this ->addressesToSync )) {
534
- foreach ($ this ->addressesToSync as $ addressId ) {
535
- $ this ->addressRepository ->deleteById ($ addressId );
536
- }
537
- }
538
- $ this ->eventManager ->dispatch (
539
- 'sales_model_service_quote_submit_failure ' ,
540
- [
541
- 'order ' => $ order ,
542
- 'quote ' => $ quote ,
543
- 'exception ' => $ e ,
544
- ]
545
- );
546
- } catch (\Exception $ consecutiveException ) {
547
- $ message = sprintf (
548
- "An exception occurred on 'sales_model_service_quote_submit_failure' event: %s " ,
549
- $ consecutiveException ->getMessage ()
550
- );
551
-
552
- throw new \Exception ($ message , 0 , $ e );
553
- }
532
+ $ this ->rollbackAddresses ($ quote , $ order , $ e );
554
533
throw $ e ;
555
534
}
556
535
return $ order ;
@@ -617,4 +596,41 @@ protected function _prepareCustomerQuote($quote)
617
596
$ shipping ->setIsDefaultBilling (true );
618
597
}
619
598
}
599
+
600
+ /**
601
+ * Remove related to order and quote addresses and submit exception to further processing.
602
+ *
603
+ * @param Quote $quote
604
+ * @param \Magento\Sales\Api\Data\OrderInterface $order
605
+ * @param \Exception $e
606
+ * @throws \Exception
607
+ */
608
+ private function rollbackAddresses (
609
+ QuoteEntity $ quote ,
610
+ \Magento \Sales \Api \Data \OrderInterface $ order ,
611
+ \Exception $ e
612
+ ): void {
613
+ try {
614
+ if (!empty ($ this ->addressesToSync )) {
615
+ foreach ($ this ->addressesToSync as $ addressId ) {
616
+ $ this ->addressRepository ->deleteById ($ addressId );
617
+ }
618
+ }
619
+ $ this ->eventManager ->dispatch (
620
+ 'sales_model_service_quote_submit_failure ' ,
621
+ [
622
+ 'order ' => $ order ,
623
+ 'quote ' => $ quote ,
624
+ 'exception ' => $ e ,
625
+ ]
626
+ );
627
+ } catch (\Exception $ consecutiveException ) {
628
+ $ message = sprintf (
629
+ "An exception occurred on 'sales_model_service_quote_submit_failure' event: %s " ,
630
+ $ consecutiveException ->getMessage ()
631
+ );
632
+
633
+ throw new \Exception ($ message , 0 , $ e );
634
+ }
635
+ }
620
636
}
0 commit comments