88use Magento \Customer \Api \Data \CustomerInterface as CustomerDataObject ;
99use Magento \Customer \Model \AccountManagement ;
1010use Magento \Paypal \Model \Config as PaypalConfig ;
11- use Magento \Paypal \Model \Express \Checkout \Quote as PaypalQuote ;
1211use Magento \Sales \Model \Order \Email \Sender \OrderSender ;
1312use Magento \Quote \Model \Quote \Address ;
1413use Magento \Framework \DataObject ;
@@ -254,11 +253,6 @@ class Checkout
254253 */
255254 protected $ orderSender ;
256255
257- /**
258- * @var PaypalQuote
259- */
260- protected $ paypalQuote ;
261-
262256 /**
263257 * @var \Magento\Quote\Api\CartRepositoryInterface
264258 */
@@ -296,7 +290,6 @@ class Checkout
296290 * @param \Magento\Framework\Message\ManagerInterface $messageManager
297291 * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
298292 * @param AccountManagement $accountManagement
299- * @param PaypalQuote $paypalQuote
300293 * @param OrderSender $orderSender
301294 * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
302295 * @param \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector
@@ -326,7 +319,6 @@ public function __construct(
326319 \Magento \Framework \Message \ManagerInterface $ messageManager ,
327320 \Magento \Customer \Api \CustomerRepositoryInterface $ customerRepository ,
328321 AccountManagement $ accountManagement ,
329- PaypalQuote $ paypalQuote ,
330322 OrderSender $ orderSender ,
331323 \Magento \Quote \Api \CartRepositoryInterface $ quoteRepository ,
332324 \Magento \Quote \Model \Quote \TotalsCollector $ totalsCollector ,
@@ -353,7 +345,6 @@ public function __construct(
353345 $ this ->_messageManager = $ messageManager ;
354346 $ this ->orderSender = $ orderSender ;
355347 $ this ->_accountManagement = $ accountManagement ;
356- $ this ->paypalQuote = $ paypalQuote ;
357348 $ this ->quoteRepository = $ quoteRepository ;
358349 $ this ->totalsCollector = $ totalsCollector ;
359350 $ this ->_customerSession = isset ($ params ['session ' ])
@@ -620,7 +611,7 @@ public function returnFromPaypal($token)
620611 ->callGetExpressCheckoutDetails ();
621612 $ quote = $ this ->_quote ;
622613
623- $ this ->_ignoreAddressValidation ();
614+ $ this ->ignoreAddressValidation ();
624615
625616 // import shipping address
626617 $ exportedShippingAddress = $ this ->_api ->getExportedShippingAddress ();
@@ -708,7 +699,7 @@ public function prepareOrderReview($token = null)
708699 $ this ->_quote ->setMayEditShippingMethod (
709700 '' == $ this ->_quote ->getPayment ()->getAdditionalInformation (self ::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD )
710701 );
711- $ this ->_ignoreAddressValidation ();
702+ $ this ->ignoreAddressValidation ();
712703 $ this ->_quote ->collectTotals ();
713704 $ this ->quoteRepository ->save ($ this ->_quote );
714705 }
@@ -763,7 +754,7 @@ public function updateShippingMethod($methodCode)
763754 $ shippingAddress = $ this ->_quote ->getShippingAddress ();
764755 if (!$ this ->_quote ->getIsVirtual () && $ shippingAddress ) {
765756 if ($ methodCode != $ shippingAddress ->getShippingMethod ()) {
766- $ this ->_ignoreAddressValidation ();
757+ $ this ->ignoreAddressValidation ();
767758 $ shippingAddress ->setShippingMethod ($ methodCode )->setCollectShippingRates (true );
768759 $ this ->_quote ->collectTotals ();
769760 $ this ->quoteRepository ->save ($ this ->_quote );
@@ -786,31 +777,14 @@ public function place($token, $shippingMethodCode = null)
786777 $ this ->updateShippingMethod ($ shippingMethodCode );
787778 }
788779
789- $ isNewCustomer = false ;
790- switch ($ this ->getCheckoutMethod ()) {
791- case \Magento \Checkout \Model \Type \Onepage::METHOD_GUEST :
792- $ this ->_prepareGuestQuote ();
793- break ;
794- case \Magento \Checkout \Model \Type \Onepage::METHOD_REGISTER :
795- $ this ->_prepareNewCustomerQuote ();
796- $ isNewCustomer = true ;
797- break ;
798- default :
799- $ this ->_prepareCustomerQuote ();
800- break ;
780+ if ($ this ->getCheckoutMethod () == \Magento \Checkout \Model \Type \Onepage::METHOD_GUEST ) {
781+ $ this ->prepareGuestQuote ();
801782 }
802783
803- $ this ->_ignoreAddressValidation ();
784+ $ this ->ignoreAddressValidation ();
804785 $ this ->_quote ->collectTotals ();
805786 $ order = $ this ->quoteManagement ->submit ($ this ->_quote );
806787
807- if ($ isNewCustomer ) {
808- try {
809- $ this ->_involveNewCustomer ();
810- } catch (\Exception $ e ) {
811- $ this ->_logger ->critical ($ e );
812- }
813- }
814788 if (!$ order ) {
815789 return ;
816790 }
@@ -843,7 +817,7 @@ public function place($token, $shippingMethodCode = null)
843817 *
844818 * @return void
845819 */
846- private function _ignoreAddressValidation ()
820+ private function ignoreAddressValidation ()
847821 {
848822 $ this ->_quote ->getBillingAddress ()->setShouldIgnoreValidation (true );
849823 if (!$ this ->_quote ->getIsVirtual ()) {
@@ -1109,62 +1083,6 @@ protected function _matchShippingMethodCode(Address $address, $selectedCode)
11091083 return '' ;
11101084 }
11111085
1112- /**
1113- * Prepare quote for guest checkout order submit
1114- *
1115- * @return $this
1116- */
1117- protected function _prepareGuestQuote ()
1118- {
1119- $ quote = $ this ->_quote ;
1120- $ quote ->setCustomerId (null )
1121- ->setCustomerEmail ($ quote ->getBillingAddress ()->getEmail ())
1122- ->setCustomerIsGuest (true )
1123- ->setCustomerGroupId (\Magento \Customer \Model \Group::NOT_LOGGED_IN_ID );
1124- return $ this ;
1125- }
1126-
1127- /**
1128- * Prepare quote for customer registration and customer order submit
1129- * and restore magento customer data from quote
1130- *
1131- * @return void
1132- */
1133- protected function _prepareNewCustomerQuote ()
1134- {
1135- $ this ->paypalQuote ->prepareQuoteForNewCustomer ($ this ->_quote );
1136- }
1137-
1138- /**
1139- * Prepare quote for customer order submit
1140- *
1141- * @return void
1142- */
1143- protected function _prepareCustomerQuote ()
1144- {
1145- $ this ->paypalQuote ->prepareRegisteredCustomerQuote ($ this ->_quote , $ this ->_customerSession ->getCustomerId ());
1146- }
1147-
1148- /**
1149- * Involve new customer to system
1150- *
1151- * @return $this
1152- */
1153- protected function _involveNewCustomer ()
1154- {
1155- $ customer = $ this ->_quote ->getCustomer ();
1156- $ confirmationStatus = $ this ->_accountManagement ->getConfirmationStatus ($ customer ->getId ());
1157- if ($ confirmationStatus === AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED ) {
1158- $ this ->_messageManager ->addSuccess (
1159- __ ('Thank you for registering with Main Website Store. ' )
1160- );
1161- } else {
1162- $ this ->getCustomerSession ()->regenerateId ();
1163- $ this ->getCustomerSession ()->loginById ($ customer ->getId ());
1164- }
1165- return $ this ;
1166- }
1167-
11681086 /**
11691087 * Create payment redirect url
11701088 * @param bool|null $button
@@ -1218,4 +1136,19 @@ private function setShippingOptions(PaypalCart $cart, Address $address = null)
12181136 }
12191137 }
12201138 }
1139+
1140+ /**
1141+ * Prepare quote for guest checkout order submit
1142+ *
1143+ * @return $this
1144+ */
1145+ protected function prepareGuestQuote ()
1146+ {
1147+ $ quote = $ this ->_quote ;
1148+ $ quote ->setCustomerId (null )
1149+ ->setCustomerEmail ($ quote ->getBillingAddress ()->getEmail ())
1150+ ->setCustomerIsGuest (true )
1151+ ->setCustomerGroupId (\Magento \Customer \Model \Group::NOT_LOGGED_IN_ID );
1152+ return $ this ;
1153+ }
12211154}
0 commit comments