@@ -532,28 +532,7 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
532
532
);
533
533
$ this ->quoteRepository ->save ($ quote );
534
534
} catch (\Exception $ e ) {
535
- try {
536
- if (!empty ($ this ->addressesToSync )) {
537
- foreach ($ this ->addressesToSync as $ addressId ) {
538
- $ this ->addressRepository ->deleteById ($ addressId );
539
- }
540
- }
541
- $ this ->eventManager ->dispatch (
542
- 'sales_model_service_quote_submit_failure ' ,
543
- [
544
- 'order ' => $ order ,
545
- 'quote ' => $ quote ,
546
- 'exception ' => $ e ,
547
- ]
548
- );
549
- } catch (\Exception $ consecutiveException ) {
550
- $ message = sprintf (
551
- "An exception occurred on 'sales_model_service_quote_submit_failure' event: %s " ,
552
- $ consecutiveException ->getMessage ()
553
- );
554
-
555
- throw new \Exception ($ message , 0 , $ e );
556
- }
535
+ $ this ->rollbackAddresses ($ quote , $ order , $ e );
557
536
throw $ e ;
558
537
}
559
538
return $ order ;
@@ -620,4 +599,41 @@ protected function _prepareCustomerQuote($quote)
620
599
$ shipping ->setIsDefaultBilling (true );
621
600
}
622
601
}
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
+ }
623
639
}
0 commit comments