diff --git a/vendor/magento/module-paypal/Model/Express/Checkout.php b/vendor/magento/module-paypal/Model/Express/Checkout.php index 389f20c757a..5099f0ccb35 100644 --- a/vendor/magento/module-paypal/Model/Express/Checkout.php +++ b/vendor/magento/module-paypal/Model/Express/Checkout.php @@ -1155,8 +1155,18 @@ class Checkout protected function prepareGuestQuote() { $quote = $this->_quote; + $billingAddress = $quote->getBillingAddress(); + + /* Check if Guest customer provided an email address on checkout page, and in case + it was provided, use it as priority, if not, use email address returned from PayPal. + (Guest customer can place order two ways: - from checkout page, where guest is asked to provide + an email address that later can be used for account creation; - from mini shopping cart, directly + proceeding to PayPal without providing an email address */ + $email = $billingAddress->getOrigData('email') !== null + ? $billingAddress->getOrigData('email') : $billingAddress->getEmail(); + $quote->setCustomerId(null) - ->setCustomerEmail($quote->getBillingAddress()->getEmail()) + ->setCustomerEmail($email) ->setCustomerIsGuest(true) ->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID); return $this;