Skip to content

Commit c11fb1a

Browse files
committed
Merge remote-tracking branch 'l3/MC-38900' into BUGFIX-11-23
2 parents 726ba8a + 8347935 commit c11fb1a

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

app/code/Magento/Quote/Model/Quote/Address.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class Address extends AbstractAddress implements
139139
const ADDRESS_TYPE_BILLING = 'billing';
140140

141141
const ADDRESS_TYPE_SHIPPING = 'shipping';
142-
142+
143143
private const CACHED_ITEMS_ALL = 'cached_items_all';
144144

145145
/**
@@ -1653,7 +1653,7 @@ public function setCustomerId($customerId)
16531653
public function getEmail()
16541654
{
16551655
$email = $this->getData(self::KEY_EMAIL);
1656-
if (!$email && $this->getQuote()) {
1656+
if ($this->getQuote() && (!$email || $this->getQuote()->dataHasChangedFor('customer_email'))) {
16571657
$email = $this->getQuote()->getCustomerEmail();
16581658
$this->setEmail($email);
16591659
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetGuestEmailOnCartTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
namespace Magento\GraphQl\Quote\Guest;
99

1010
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
11+
use Magento\Quote\Model\Quote\Address;
12+
use Magento\Quote\Model\QuoteFactory;
13+
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
1114
use Magento\TestFramework\Helper\Bootstrap;
1215
use Magento\TestFramework\TestCase\GraphQlAbstract;
1316

@@ -21,10 +24,22 @@ class SetGuestEmailOnCartTest extends GraphQlAbstract
2124
*/
2225
private $getMaskedQuoteIdByReservedOrderId;
2326

27+
/**
28+
* @var QuoteFactory
29+
*/
30+
private $quoteFactory;
31+
32+
/**
33+
* @var QuoteResource
34+
*/
35+
private $quoteResource;
36+
2437
protected function setUp(): void
2538
{
2639
$objectManager = Bootstrap::getObjectManager();
2740
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
41+
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
42+
$this->quoteResource = $objectManager->get(QuoteResource::class);
2843
}
2944

3045
/**
@@ -43,6 +58,33 @@ public function testSetGuestEmailOnCart()
4358
$this->assertEquals($email, $response['setGuestEmailOnCart']['cart']['email']);
4459
}
4560

61+
/**
62+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
63+
*/
64+
public function testSetGuestEmailOnCartWithDifferentEmailAddress()
65+
{
66+
$reservedOrderId = 'test_quote';
67+
$secondEmail = 'attempt2@example.com';
68+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
69+
70+
$email = 'attempt1@example.com';
71+
$query = $this->getQuery($maskedQuoteId, $email);
72+
$this->graphQlMutation($query);
73+
74+
$query = $this->getQuery($maskedQuoteId, $secondEmail);
75+
$this->graphQlMutation($query);
76+
77+
$quote = $this->quoteFactory->create();
78+
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id');
79+
$addresses = $quote->getAddressesCollection();
80+
$this->assertEquals(2, $addresses->count());
81+
foreach ($addresses as $address) {
82+
if ($address->getAddressType() === Address::ADDRESS_TYPE_SHIPPING) {
83+
$this->assertEquals($secondEmail, $address->getEmail());
84+
}
85+
}
86+
}
87+
4688
/**
4789
* _security
4890
* @magentoApiDataFixture Magento/Customer/_files/customer.php

0 commit comments

Comments
 (0)