Skip to content

Commit 932acf9

Browse files
authored
Merge pull request #4096 from magento-panda/MC-5681
Fixed issues: - MC-5681: Implement handling of large number of addresses on Onepage Checkout
2 parents 18dc53f + 7d1e1bd commit 932acf9

File tree

23 files changed

+620
-182
lines changed

23 files changed

+620
-182
lines changed

app/code/Magento/Braintree/Test/Mftf/Test/BraintreeCreditCardOnCheckoutTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<actionGroup ref="LoggedInCheckoutFillNewBillingAddressActionGroup" stepKey="LoggedInCheckoutFillNewBillingAddressActionGroup1">
8282
<argument name="Address" value="US_Address_NY"/>
8383
</actionGroup>
84-
<click selector="{{CheckoutPaymentSection.addressAction('Save Address')}}" stepKey="SaveAddress"/>
84+
<click selector="{{CheckoutPaymentSection.addressAction('Ship here')}}" stepKey="SaveAddress"/>
8585
<waitForPageLoad stepKey="waitForPageLoad9"/>
8686
<click selector="{{CheckoutShippingSection.next}}" stepKey="clickNext1"/>
8787
<waitForPageLoad stepKey="waitForPageLoad10"/>

app/code/Magento/Catalog/Controller/Adminhtml/Product/Search.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
namespace Magento\Catalog\Controller\Adminhtml\Product;
1010

1111
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Framework\App\Action\HttpGetActionInterface;
1213

1314
/**
1415
* Controller to search product for ui-select component
1516
*/
16-
class Search extends \Magento\Backend\App\Action
17+
class Search extends \Magento\Backend\App\Action implements HttpGetActionInterface
1718
{
1819
/**
1920
* Authorization level of a basic admin session
@@ -48,6 +49,8 @@ public function __construct(
4849
}
4950

5051
/**
52+
* Execute product search.
53+
*
5154
* @return \Magento\Framework\Controller\ResultInterface
5255
*/
5356
public function execute() : \Magento\Framework\Controller\ResultInterface

app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ private function convertElementsToSelect($elements, $attributesToConvert)
122122
if (!in_array($code, $codes)) {
123123
continue;
124124
}
125+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
125126
$options = call_user_func($attributesToConvert[$code]);
126127
if (!is_array($options)) {
127128
continue;
@@ -287,8 +288,14 @@ private function getBillingAddressComponent($paymentCode, $elements)
287288
'provider' => 'checkoutProvider',
288289
'deps' => 'checkoutProvider',
289290
'dataScopePrefix' => 'billingAddress' . $paymentCode,
291+
'billingAddressListProvider' => '${$.name}.billingAddressList',
290292
'sortOrder' => 1,
291293
'children' => [
294+
'billingAddressList' => [
295+
'component' => 'Magento_Checkout/js/view/billing-address/list',
296+
'displayArea' => 'billing-address-list',
297+
'template' => 'Magento_Checkout/billing-address/list'
298+
],
292299
'form-fields' => [
293300
'component' => 'uiComponent',
294301
'displayArea' => 'additional-fieldsets',

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

Lines changed: 15 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Checkout\Model\Session as CheckoutSession;
1111
use Magento\Customer\Api\AddressMetadataInterface;
1212
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
13+
use Magento\Customer\Model\Address\CustomerAddressDataProvider;
1314
use Magento\Customer\Model\Context as CustomerContext;
1415
use Magento\Customer\Model\Session as CustomerSession;
1516
use Magento\Customer\Model\Url as CustomerUrlManager;
@@ -34,6 +35,7 @@
3435
*
3536
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3637
* @SuppressWarnings(PHPMD.TooManyFields)
38+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
3739
*/
3840
class DefaultConfigProvider implements ConfigProviderInterface
3941
{
@@ -177,6 +179,11 @@ class DefaultConfigProvider implements ConfigProviderInterface
177179
*/
178180
private $addressMetadata;
179181

182+
/**
183+
* @var CustomerAddressDataProvider
184+
*/
185+
private $customerAddressData;
186+
180187
/**
181188
* @param CheckoutHelper $checkoutHelper
182189
* @param Session $checkoutSession
@@ -206,6 +213,7 @@ class DefaultConfigProvider implements ConfigProviderInterface
206213
* @param UrlInterface $urlBuilder
207214
* @param AddressMetadataInterface $addressMetadata
208215
* @param AttributeOptionManagementInterface $attributeOptionManager
216+
* @param CustomerAddressDataProvider|null $customerAddressData
209217
* @codeCoverageIgnore
210218
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
211219
*/
@@ -237,7 +245,8 @@ public function __construct(
237245
\Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement,
238246
UrlInterface $urlBuilder,
239247
AddressMetadataInterface $addressMetadata = null,
240-
AttributeOptionManagementInterface $attributeOptionManager = null
248+
AttributeOptionManagementInterface $attributeOptionManager = null,
249+
CustomerAddressDataProvider $customerAddressData = null
241250
) {
242251
$this->checkoutHelper = $checkoutHelper;
243252
$this->checkoutSession = $checkoutSession;
@@ -268,6 +277,8 @@ public function __construct(
268277
$this->addressMetadata = $addressMetadata ?: ObjectManager::getInstance()->get(AddressMetadataInterface::class);
269278
$this->attributeOptionManager = $attributeOptionManager ??
270279
ObjectManager::getInstance()->get(AttributeOptionManagementInterface::class);
280+
$this->customerAddressData = $customerAddressData ?:
281+
ObjectManager::getInstance()->get(CustomerAddressDataProvider::class);
271282
}
272283

273284
/**
@@ -359,57 +370,18 @@ private function isAutocompleteEnabled()
359370
*
360371
* @return array
361372
*/
362-
private function getCustomerData()
373+
private function getCustomerData(): array
363374
{
364375
$customerData = [];
365376
if ($this->isCustomerLoggedIn()) {
377+
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
366378
$customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
367379
$customerData = $customer->__toArray();
368-
foreach ($customer->getAddresses() as $key => $address) {
369-
$customerData['addresses'][$key]['inline'] = $this->getCustomerAddressInline($address);
370-
if ($address->getCustomAttributes()) {
371-
$customerData['addresses'][$key]['custom_attributes'] = $this->filterNotVisibleAttributes(
372-
$customerData['addresses'][$key]['custom_attributes']
373-
);
374-
}
375-
}
380+
$customerData['addresses'] = $this->customerAddressData->getAddressDataByCustomer($customer);
376381
}
377382
return $customerData;
378383
}
379384

380-
/**
381-
* Filter not visible on storefront custom attributes.
382-
*
383-
* @param array $attributes
384-
* @return array
385-
*/
386-
private function filterNotVisibleAttributes(array $attributes)
387-
{
388-
$attributesMetadata = $this->addressMetadata->getAllAttributesMetadata();
389-
foreach ($attributesMetadata as $attributeMetadata) {
390-
if (!$attributeMetadata->isVisible()) {
391-
unset($attributes[$attributeMetadata->getAttributeCode()]);
392-
}
393-
}
394-
395-
return $this->setLabelsToAttributes($attributes);
396-
}
397-
398-
/**
399-
* Set additional customer address data
400-
*
401-
* @param \Magento\Customer\Api\Data\AddressInterface $address
402-
* @return string
403-
*/
404-
private function getCustomerAddressInline($address)
405-
{
406-
$builtOutputAddressData = $this->addressMapper->toFlatArray($address);
407-
return $this->addressConfig
408-
->getFormatByCode(\Magento\Customer\Model\Address\Config::DEFAULT_ADDRESS_FORMAT)
409-
->getRenderer()
410-
->renderArray($builtOutputAddressData);
411-
}
412-
413385
/**
414386
* Retrieve quote data
415387
*
@@ -726,61 +698,6 @@ private function getPaymentMethods()
726698
return $paymentMethods;
727699
}
728700

729-
/**
730-
* Set Labels to custom Attributes
731-
*
732-
* @param array $customAttributes
733-
* @return array $customAttributes
734-
* @throws \Magento\Framework\Exception\InputException
735-
* @throws \Magento\Framework\Exception\StateException
736-
*/
737-
private function setLabelsToAttributes(array $customAttributes) : array
738-
{
739-
if (!empty($customAttributes)) {
740-
foreach ($customAttributes as $customAttributeCode => $customAttribute) {
741-
$attributeOptionLabels = $this->getAttributeLabels($customAttribute, $customAttributeCode);
742-
if (!empty($attributeOptionLabels)) {
743-
$customAttributes[$customAttributeCode]['label'] = implode(', ', $attributeOptionLabels);
744-
}
745-
}
746-
}
747-
748-
return $customAttributes;
749-
}
750-
751-
/**
752-
* Get Labels by CustomAttribute and CustomAttributeCode
753-
*
754-
* @param array $customAttribute
755-
* @param string|integer $customAttributeCode
756-
* @return array $attributeOptionLabels
757-
* @throws \Magento\Framework\Exception\InputException
758-
* @throws \Magento\Framework\Exception\StateException
759-
*/
760-
private function getAttributeLabels(array $customAttribute, string $customAttributeCode) : array
761-
{
762-
$attributeOptionLabels = [];
763-
764-
if (!empty($customAttribute['value'])) {
765-
$customAttributeValues = explode(',', $customAttribute['value']);
766-
$attributeOptions = $this->attributeOptionManager->getItems(
767-
\Magento\Customer\Model\Indexer\Address\AttributeProvider::ENTITY,
768-
$customAttributeCode
769-
);
770-
771-
if (!empty($attributeOptions)) {
772-
foreach ($attributeOptions as $attributeOption) {
773-
$attributeOptionValue = $attributeOption->getValue();
774-
if (in_array($attributeOptionValue, $customAttributeValues)) {
775-
$attributeOptionLabels[] = $attributeOption->getLabel() ?? $attributeOptionValue;
776-
}
777-
}
778-
}
779-
}
780-
781-
return $attributeOptionLabels;
782-
}
783-
784701
/**
785702
* Get notification messages for the quote items
786703
*

app/code/Magento/Checkout/Test/Mftf/ActionGroup/CheckoutActionGroup.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,21 @@
241241
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskAfterPaymentMethodSelection"/>
242242
</actionGroup>
243243

244+
<!-- Check selected shipping address information on shipping information step -->
245+
<actionGroup name="CheckSelectedShippingAddressInCheckoutActionGroup">
246+
<arguments>
247+
<argument name="customerVar"/>
248+
<argument name="customerAddressVar"/>
249+
</arguments>
250+
<waitForElement selector="{{CheckoutShippingSection.shippingTab}}" time="30" stepKey="waitForShippingSectionLoaded"/>
251+
<see stepKey="VerifyFirstNameInSelectedAddress" selector="{{CheckoutShippingSection.selectedShippingAddress}}" userInput="{{customerVar.firstname}}" />
252+
<see stepKey="VerifyLastNameInSelectedAddress" selector="{{CheckoutShippingSection.selectedShippingAddress}}" userInput="{{customerVar.lastname}}" />
253+
<see stepKey="VerifyStreetInSelectedAddress" selector="{{CheckoutShippingSection.selectedShippingAddress}}" userInput="{{customerAddressVar.street[0]}}" />
254+
<see stepKey="VerifyCityInSelectedAddress" selector="{{CheckoutShippingSection.selectedShippingAddress}}" userInput="{{customerAddressVar.city}}" />
255+
<see stepKey="VerifyZipInSelectedAddress" selector="{{CheckoutShippingSection.selectedShippingAddress}}" userInput="{{customerAddressVar.postcode}}" />
256+
<see stepKey="VerifyPhoneInSelectedAddress" selector="{{CheckoutShippingSection.selectedShippingAddress}}" userInput="{{customerAddressVar.telephone}}" />
257+
</actionGroup>
258+
244259
<!-- Check billing address in checkout -->
245260
<actionGroup name="CheckBillingAddressInCheckoutActionGroup">
246261
<arguments>
@@ -257,6 +272,22 @@
257272
<see userInput="{{customerAddressVar.telephone}}" selector="{{CheckoutPaymentSection.billingAddress}}" stepKey="assertBillingAddressTelephone"/>
258273
</actionGroup>
259274

275+
<!-- Check billing address in checkout with billing address on payment page -->
276+
<actionGroup name="CheckBillingAddressInCheckoutWithBillingAddressOnPaymentPageActionGroup">
277+
<arguments>
278+
<argument name="customerVar"/>
279+
<argument name="customerAddressVar"/>
280+
</arguments>
281+
<waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" time="30" stepKey="waitForPaymentSectionLoaded"/>
282+
<see userInput="{{customerVar.firstName}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsFirstName"/>
283+
<see userInput="{{customerVar.lastName}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsLastName"/>
284+
<see userInput="{{customerAddressVar.street[0]}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsStreet"/>
285+
<see userInput="{{customerAddressVar.city}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsCity"/>
286+
<see userInput="{{customerAddressVar.state}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsState"/>
287+
<see userInput="{{customerAddressVar.postcode}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsPostcode"/>
288+
<see userInput="{{customerAddressVar.telephone}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsTelephone"/>
289+
</actionGroup>
290+
260291
<!-- Checkout place order -->
261292
<actionGroup name="CheckoutPlaceOrderActionGroup">
262293
<arguments>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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="FillNewShippingAddressModalActionGroup" extends="FillShippingAddressOneStreetActionGroup">
12+
<arguments>
13+
<argument name="address"/>
14+
</arguments>
15+
<selectOption stepKey="selectRegion" selector="{{CheckoutShippingSection.region}}"
16+
userInput="{{address.state}}" after="fillCityName"/>
17+
</actionGroup>
18+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection">
12+
<element name="billingAddressDetails" type="text" selector="div.billing-address-details"/>
13+
</section>
14+
</sections>

app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
<item name="trigger" xsi:type="string">opc-new-shipping-address</item>
106106
<item name="buttons" xsi:type="array">
107107
<item name="save" xsi:type="array">
108-
<item name="text" xsi:type="string" translate="true">Save Address</item>
108+
<item name="text" xsi:type="string" translate="true">Ship here</item>
109109
<item name="class" xsi:type="string">action primary action-save-address</item>
110110
</item>
111111
<item name="cancel" xsi:type="array">

app/code/Magento/Checkout/view/frontend/web/js/action/create-billing-address.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ define([
1212
'use strict';
1313

1414
return function (addressData) {
15-
return addressConverter.formAddressDataToQuoteAddress(addressData);
15+
var address = addressConverter.formAddressDataToQuoteAddress(addressData);
16+
17+
/**
18+
* Returns new customer billing address type.
19+
*
20+
* @returns {String}
21+
*/
22+
address.getType = function () {
23+
return 'new-customer-billing-address';
24+
};
25+
26+
return address;
1627
};
1728
});

app/code/Magento/Checkout/view/frontend/web/js/model/checkout-data-resolver.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ define([
216216
newCustomerBillingAddressData = checkoutData.getNewCustomerBillingAddress();
217217

218218
if (selectedBillingAddress) {
219-
if (selectedBillingAddress == 'new-customer-address' && newCustomerBillingAddressData) { //eslint-disable-line
219+
if (selectedBillingAddress === 'new-customer-billing-address' && newCustomerBillingAddressData) {
220220
selectBillingAddress(createBillingAddress(newCustomerBillingAddressData));
221221
} else {
222222
addressList.some(function (address) {
223-
if (selectedBillingAddress == address.getKey()) { //eslint-disable-line eqeqeq
223+
if (selectedBillingAddress === address.getKey()) {
224224
selectBillingAddress(address);
225225
}
226226
});

0 commit comments

Comments
 (0)