19
19
use Magento \Sales \Model \Order ;
20
20
use Magento \Store \Model \StoreManagerInterface ;
21
21
use Psr \Log \LoggerInterface ;
22
+ use Magento \Quote \Model \Quote ;
22
23
23
24
/**
24
25
* Order create model
@@ -2004,8 +2005,31 @@ public function createOrder()
2004
2005
2005
2006
$ this ->_prepareQuoteItems ();
2006
2007
2008
+ $ orderData = $ this ->beforeSubmit ($ quote );
2009
+ $ order = $ this ->quoteManagement ->submit ($ quote , $ orderData );
2010
+ $ this ->afterSubmit ($ order );
2011
+
2012
+ if ($ this ->getSendConfirmation () && !$ order ->getEmailSent ()) {
2013
+ $ this ->emailSender ->send ($ order );
2014
+ }
2015
+
2016
+ $ this ->_eventManager ->dispatch ('checkout_submit_all_after ' , ['order ' => $ order , 'quote ' => $ quote ]);
2017
+
2018
+ $ this ->removeTransferredItems ();
2019
+
2020
+ return $ order ;
2021
+ }
2022
+
2023
+ /**
2024
+ * Prepare and retrieve order data before submitting a quote for order creation.
2025
+ *
2026
+ * @param Quote $quote
2027
+ * @return array
2028
+ */
2029
+ private function beforeSubmit (Quote $ quote )
2030
+ {
2007
2031
$ orderData = [];
2008
- if ($ this ->getSession ()->getReordered () || $ this ->getSession ()->getOrder ()->getId ()) { //
2032
+ if ($ this ->getSession ()->getReordered () || $ this ->getSession ()->getOrder ()->getId ()) {
2009
2033
$ oldOrder = $ this ->getSession ()->getOrder ();
2010
2034
$ oldOrder = $ oldOrder ->getId () ?
2011
2035
$ oldOrder : $ this ->orderRepositoryInterface ->get ($ this ->getSession ()->getReordered ());
@@ -2022,8 +2046,20 @@ public function createOrder()
2022
2046
];
2023
2047
$ quote ->setReservedOrderId ($ orderData ['increment_id ' ]);
2024
2048
}
2025
- $ order = $ this ->quoteManagement ->submit ($ quote , $ orderData );
2026
- if ($ this ->getSession ()->getReordered () || $ this ->getSession ()->getOrder ()->getId ()) { //
2049
+
2050
+ return $ orderData ;
2051
+ }
2052
+
2053
+ /**
2054
+ * Process old order after submission.
2055
+ *
2056
+ * @param Order $order
2057
+ * @return void
2058
+ * @throws \Exception
2059
+ */
2060
+ private function afterSubmit (Order $ order )
2061
+ {
2062
+ if ($ this ->getSession ()->getReordered () || $ this ->getSession ()->getOrder ()->getId ()) {
2027
2063
$ oldOrder = $ this ->getSession ()->getOrder ();
2028
2064
$ oldOrder = $ oldOrder ->getId () ?
2029
2065
$ oldOrder : $ this ->orderRepositoryInterface ->get ($ this ->getSession ()->getReordered ());
@@ -2035,16 +2071,6 @@ public function createOrder()
2035
2071
}
2036
2072
$ order ->save ();
2037
2073
}
2038
-
2039
- if ($ this ->getSendConfirmation () && !$ order ->getEmailSent ()) {
2040
- $ this ->emailSender ->send ($ order );
2041
- }
2042
-
2043
- $ this ->_eventManager ->dispatch ('checkout_submit_all_after ' , ['order ' => $ order , 'quote ' => $ quote ]);
2044
-
2045
- $ this ->removeTransferredItems ();
2046
-
2047
- return $ order ;
2048
2074
}
2049
2075
2050
2076
/**
0 commit comments