Skip to content

Commit 89fedbd

Browse files
committed
MC-40810: [Magento Cloud] Downloadable product link being delivered to email address associated with the PayPal account
- fixed - modified test
1 parent 4559910 commit 89fedbd

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

app/code/Magento/Paypal/Model/Express/Checkout.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,8 +1155,18 @@ private function setShippingOptions(PaypalCart $cart, Address $address = null)
11551155
protected function prepareGuestQuote()
11561156
{
11571157
$quote = $this->_quote;
1158+
$billingAddress = $quote->getBillingAddress();
1159+
1160+
/* Check if Guest customer provided an email address on checkout page, and in case
1161+
it was provided, use it as priority, if not, use email address returned from PayPal.
1162+
(Guest customer can place order two ways: - from checkout page, where guest is asked to provide
1163+
an email address that later can be used for account creation; - from mini shopping cart, directly
1164+
proceeding to PayPal without providing an email address */
1165+
$email = $billingAddress->getOrigData('email') !== null
1166+
? $billingAddress->getOrigData('email') : $billingAddress->getEmail();
1167+
11581168
$quote->setCustomerId(null)
1159-
->setCustomerEmail($quote->getBillingAddress()->getEmail())
1169+
->setCustomerEmail($email)
11601170
->setCustomerIsGuest(true)
11611171
->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID);
11621172
return $this;

dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,23 @@ public function testPrepareCustomerQuote()
190190
* @magentoDataFixture Magento/Paypal/_files/quote_express.php
191191
* @magentoAppIsolation enabled
192192
* @magentoDbIsolation enabled
193+
* @param string $accountEmail
194+
* @param string $expected
195+
* @dataProvider placeGuestQuoteDataProvider
193196
*/
194-
public function testPlaceGuestQuote()
197+
public function testPlaceGuestQuote($accountEmail, $expected)
195198
{
196199
/** @var Quote $quote */
197200
$quote = $this->getFixtureQuote();
198201
$quote->setCheckoutMethod(Onepage::METHOD_GUEST); // to dive into _prepareGuestQuote() on switch
199202
$quote->getShippingAddress()->setSameAsBilling(0);
200203
$quote->setReservedOrderId(null);
201204

205+
/* Simulate data returned from PayPal containing email as well
206+
as email entered at checkout step */
207+
$quote->getBillingAddress()->setEmail('[email protected]');
208+
$quote->getBillingAddress()->setOrigData('email', $accountEmail);
209+
202210
$checkout = $this->getCheckout($quote);
203211
$checkout->place('token');
204212

@@ -209,6 +217,7 @@ public function testPlaceGuestQuote()
209217
$quote->getCustomerGroupId()
210218
);
211219

220+
$this->assertEquals($expected, $quote->getCustomerEmail());
212221
$this->assertNotEmpty($quote->getBillingAddress());
213222
$this->assertNotEmpty($quote->getShippingAddress());
214223

@@ -217,6 +226,17 @@ public function testPlaceGuestQuote()
217226
$this->assertNotEmpty($order->getShippingAddress());
218227
}
219228

229+
/**
230+
* @return array
231+
*/
232+
public function placeGuestQuoteDataProvider(): array
233+
{
234+
return [
235+
'case with account email absent' => [null, '[email protected]'],
236+
'case with account email present' => ['[email protected]', '[email protected]'],
237+
];
238+
}
239+
220240
/**
221241
* Place the order as guest when `Automatic Assignment to Customer Group` is enabled.
222242
*

0 commit comments

Comments
 (0)