Skip to content

Commit 3de1d60

Browse files
authored
Merge pull request #6711 from magento-l3/2.4-bugfixes-031921
[L3] Bugfixes
2 parents 12ebc0e + 9f6eefc commit 3de1d60

File tree

10 files changed

+833
-290
lines changed

10 files changed

+833
-290
lines changed

app/code/Magento/Checkout/Model/DefaultConfigProvider.php

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Checkout\Model\Session as CheckoutSession;
1212
use Magento\Customer\Api\AddressMetadataInterface;
1313
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
14+
use Magento\Customer\Api\Data\CustomerInterface;
1415
use Magento\Customer\Model\Address\CustomerAddressDataProvider;
1516
use Magento\Customer\Model\Context as CustomerContext;
1617
use Magento\Customer\Model\Session as CustomerSession;
@@ -311,14 +312,11 @@ public function getConfig()
311312
$output['isCustomerLoggedIn'] = $this->isCustomerLoggedIn();
312313
$output['selectedShippingMethod'] = $this->getSelectedShippingMethod();
313314
if ($email && !$this->isCustomerLoggedIn()) {
314-
$shippingAddressFromData = $this->getAddressFromData($quote->getShippingAddress());
315-
$billingAddressFromData = $this->getAddressFromData($quote->getBillingAddress());
316-
$output['shippingAddressFromData'] = $shippingAddressFromData;
317-
if ($shippingAddressFromData != $billingAddressFromData) {
318-
$output['billingAddressFromData'] = $billingAddressFromData;
319-
}
320315
$output['validatedEmailValue'] = $email;
321316
}
317+
if (!$this->isCustomerLoggedIn() || !$this->getCustomer()->getAddresses()) {
318+
$output = array_merge($output, $this->getQuoteAddressData());
319+
}
322320
$output['storeCode'] = $this->getStoreCode();
323321
$output['isGuestCheckoutAllowed'] = $this->isGuestCheckoutAllowed();
324322
$output['isCustomerLoginRequired'] = $this->isCustomerLoginRequired();
@@ -387,8 +385,7 @@ private function getCustomerData(): array
387385
{
388386
$customerData = [];
389387
if ($this->isCustomerLoggedIn()) {
390-
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
391-
$customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
388+
$customer = $this->getCustomer();
392389
$customerData = $customer->__toArray();
393390
$customerData['addresses'] = $this->customerAddressData->getAddressDataByCustomer($customer);
394391
}
@@ -731,4 +728,43 @@ private function getQuoteItemsMessages(array $quoteItemData): array
731728

732729
return $quoteItemsMessages;
733730
}
731+
732+
/**
733+
* Get quote address data for checkout
734+
*
735+
* @return array
736+
*/
737+
private function getQuoteAddressData(): array
738+
{
739+
$output = [];
740+
$quote = $this->checkoutSession->getQuote();
741+
$shippingAddressFromData = [];
742+
if ($quote->getShippingAddress()->getEmail()) {
743+
$shippingAddressFromData = $this->getAddressFromData($quote->getShippingAddress());
744+
if ($shippingAddressFromData) {
745+
$output['isShippingAddressFromDataValid'] = $quote->getShippingAddress()->validate() === true;
746+
$output['shippingAddressFromData'] = $shippingAddressFromData;
747+
}
748+
}
749+
750+
if ($quote->getBillingAddress()->getEmail()) {
751+
$billingAddressFromData = $this->getAddressFromData($quote->getBillingAddress());
752+
if ($billingAddressFromData && $shippingAddressFromData != $billingAddressFromData) {
753+
$output['isBillingAddressFromDataValid'] = $quote->getBillingAddress()->validate() === true;
754+
$output['billingAddressFromData'] = $billingAddressFromData;
755+
}
756+
}
757+
758+
return $output;
759+
}
760+
761+
/**
762+
* Get logged-in customer
763+
*
764+
* @return CustomerInterface
765+
*/
766+
private function getCustomer(): CustomerInterface
767+
{
768+
return $this->customerRepository->getById($this->customerSession->getCustomerId());
769+
}
734770
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AssertStorefrontGuestCheckoutShippingAddressFormPrefilledActionGroup">
12+
<annotations>
13+
<description>Verify that shipping address form is filled with provided customer and address information.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="customer" defaultValue="Simple_US_Customer" type="entity"/>
17+
<argument name="address" defaultValue="US_Address_TX" type="entity"/>
18+
</arguments>
19+
20+
<grabValueFrom selector="{{CheckoutShippingSection.email}}" stepKey="email"/>
21+
<grabValueFrom selector="{{CheckoutShippingSection.firstName}}" stepKey="firstname"/>
22+
<grabValueFrom selector="{{CheckoutShippingSection.lastName}}" stepKey="lastname"/>
23+
<grabValueFrom selector="{{CheckoutShippingSection.street}}" stepKey="street"/>
24+
<grabValueFrom selector="{{CheckoutShippingSection.city}}" stepKey="city"/>
25+
<grabValueFrom selector="{{CheckoutShippingSection.postcode}}" stepKey="postcode"/>
26+
<grabValueFrom selector="{{CheckoutShippingSection.telephone}}" stepKey="telephone"/>
27+
28+
<assertEquals stepKey="assertEmail">
29+
<actualResult type="variable">email</actualResult>
30+
<expectedResult type="string">{{customer.email}}</expectedResult>
31+
</assertEquals>
32+
<assertEquals stepKey="assertFirstName">
33+
<actualResult type="variable">firstname</actualResult>
34+
<expectedResult type="string">{{customer.firstName}}</expectedResult>
35+
</assertEquals>
36+
<assertEquals stepKey="assertLastName">
37+
<actualResult type="variable">lastname</actualResult>
38+
<expectedResult type="string">{{customer.lastName}}</expectedResult>
39+
</assertEquals>
40+
<assertEquals stepKey="assertStreet">
41+
<actualResult type="variable">street</actualResult>
42+
<expectedResult type="string">{{address.street[0]}}</expectedResult>
43+
</assertEquals>
44+
<assertEquals stepKey="assertCity">
45+
<actualResult type="variable">city</actualResult>
46+
<expectedResult type="string">{{address.city}}</expectedResult>
47+
</assertEquals>
48+
<seeOptionIsSelected selector="{{CheckoutShippingSection.region}}" userInput="{{address.state}}" stepKey="assertRegion"/>
49+
<seeOptionIsSelected selector="{{CheckoutShippingSection.country}}" userInput="{{address.country}}" stepKey="assertCountry"/>
50+
<assertEquals stepKey="assertPostcode">
51+
<actualResult type="variable">postcode</actualResult>
52+
<expectedResult type="string">{{address.postcode}}</expectedResult>
53+
</assertEquals>
54+
<assertEquals stepKey="assertTelephone">
55+
<actualResult type="variable">telephone</actualResult>
56+
<expectedResult type="string">{{address.telephone}}</expectedResult>
57+
</assertEquals>
58+
</actionGroup>
59+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="FillGuestCheckoutShippingAddressWithCountryAndStateActionGroup" extends="FillGuestCheckoutShippingAddressFormActionGroup">
12+
<selectOption selector="{{CheckoutShippingSection.country}}" userInput="{{customerAddress.country_id}}" after="SetCustomerCity" stepKey="selectCustomerCountry"/>
13+
<selectOption selector="{{CheckoutShippingSection.region}}" userInput="{{customerAddress.state}}" after="selectCustomerCountry" stepKey="SetCustomerState"/>
14+
</actionGroup>
15+
</actionGroups>

0 commit comments

Comments
 (0)