From 5b28cca597e42f6d65d2c13119d9657c5ed758de Mon Sep 17 00:00:00 2001
From: Pavel Mishchenko
Date: Mon, 24 Jan 2022 17:50:19 +0200
Subject: [PATCH 1/2] Fix shipping email replacing with billing email.
---
app/code/Magento/Quote/Model/Quote/Address.php | 2 +-
app/code/Magento/Quote/Model/QuoteManagement.php | 4 ++--
app/code/Magento/Sales/Model/Order.php | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/app/code/Magento/Quote/Model/Quote/Address.php b/app/code/Magento/Quote/Model/Quote/Address.php
index 88d91d8efc589..fbb4cb1d8caf6 100644
--- a/app/code/Magento/Quote/Model/Quote/Address.php
+++ b/app/code/Magento/Quote/Model/Quote/Address.php
@@ -1663,7 +1663,7 @@ public function setCustomerId($customerId)
public function getEmail()
{
$email = $this->getData(self::KEY_EMAIL);
- if ($this->getQuote() && (!$email || $this->getQuote()->dataHasChangedFor('customer_email'))) {
+ if ($this->getQuote() && !$email) {
$email = $this->getQuote()->getCustomerEmail();
$this->setEmail($email);
}
diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php
index 51b68411d4080..4ec75ba4b0342 100644
--- a/app/code/Magento/Quote/Model/QuoteManagement.php
+++ b/app/code/Magento/Quote/Model/QuoteManagement.php
@@ -552,7 +552,7 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
$quote->getShippingAddress(),
[
'address_type' => 'shipping',
- 'email' => $quote->getCustomerEmail()
+ 'email' => $quote->getShippingAddress()->getEmail() ?: $quote->getCustomerEmail()
]
);
$shippingAddress->setData('quote_address_id', $quote->getShippingAddress()->getId());
@@ -564,7 +564,7 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
$quote->getBillingAddress(),
[
'address_type' => 'billing',
- 'email' => $quote->getCustomerEmail()
+ 'email' => $quote->getBillingAddress()->getEmail() ?: $quote->getCustomerEmail()
]
);
$billingAddress->setData('quote_address_id', $quote->getBillingAddress()->getId());
diff --git a/app/code/Magento/Sales/Model/Order.php b/app/code/Magento/Sales/Model/Order.php
index f272a4638a170..77b667234bcd6 100644
--- a/app/code/Magento/Sales/Model/Order.php
+++ b/app/code/Magento/Sales/Model/Order.php
@@ -1059,7 +1059,7 @@ public function setShippingAddress(\Magento\Sales\Api\Data\OrderAddressInterface
}
if (!empty($address)) {
- $address->setEmail($this->getCustomerEmail());
+ $address->getEmail() ?: $address->setEmail($this->getCustomerEmail());
$this->addAddress($address->setAddressType('shipping'));
}
return $this;
From 44e27f878a1698afa4d191cd9890008ffec3d0a5 Mon Sep 17 00:00:00 2001
From: Pavel Mishchenko
Date: Mon, 24 Jan 2022 22:13:29 +0200
Subject: [PATCH 2/2] fix WebAPI tests
---
.../testsuite/Magento/Sales/_files/order.php | 5 +++--
.../Sales/_files/shipping_address_data.php | 19 +++++++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
create mode 100644 dev/tests/integration/testsuite/Magento/Sales/_files/shipping_address_data.php
diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/order.php b/dev/tests/integration/testsuite/Magento/Sales/_files/order.php
index 924562781e16b..d4de6b20b9fd3 100644
--- a/dev/tests/integration/testsuite/Magento/Sales/_files/order.php
+++ b/dev/tests/integration/testsuite/Magento/Sales/_files/order.php
@@ -18,6 +18,7 @@
/** @var \Magento\Catalog\Model\Product $product */
$addressData = include __DIR__ . '/address_data.php';
+$shippingAddressData = include __DIR__ . '/shipping_address_data.php';
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var ProductRepositoryInterface $productRepository */
@@ -26,8 +27,8 @@
$billingAddress = $objectManager->create(OrderAddress::class, ['data' => $addressData]);
$billingAddress->setAddressType('billing');
-$shippingAddress = clone $billingAddress;
-$shippingAddress->setId(null)->setAddressType('shipping');
+$shippingAddress = $objectManager->create(OrderAddress::class, ['data' => $shippingAddressData]);
+$shippingAddress->setAddressType('shipping');
/** @var Payment $payment */
$payment = $objectManager->create(Payment::class);
diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/shipping_address_data.php b/dev/tests/integration/testsuite/Magento/Sales/_files/shipping_address_data.php
new file mode 100644
index 0000000000000..f8f6bf264d1d1
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/Sales/_files/shipping_address_data.php
@@ -0,0 +1,19 @@
+ 'CA',
+ 'region_id' => '12',
+ 'postcode' => '11111',
+ 'company' => 'Test Company',
+ 'lastname' => 'lastname',
+ 'firstname' => 'firstname',
+ 'street' => 'street',
+ 'city' => 'Los Angeles',
+ 'email' => 'customer@null.com',
+ 'telephone' => '11111111',
+ 'country_id' => 'US'
+];