Skip to content

Commit

Permalink
Merge pull request #4096 from magento-panda/MC-5681
Browse files Browse the repository at this point in the history
Fixed issues:
  - MC-5681: Implement handling of large number of addresses on Onepage Checkout
  • Loading branch information
igrybkov authored Apr 24, 2019
2 parents 18dc53f + 7d1e1bd commit 932acf9
Show file tree
Hide file tree
Showing 23 changed files with 620 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<actionGroup ref="LoggedInCheckoutFillNewBillingAddressActionGroup" stepKey="LoggedInCheckoutFillNewBillingAddressActionGroup1">
<argument name="Address" value="US_Address_NY"/>
</actionGroup>
<click selector="{{CheckoutPaymentSection.addressAction('Save Address')}}" stepKey="SaveAddress"/>
<click selector="{{CheckoutPaymentSection.addressAction('Ship here')}}" stepKey="SaveAddress"/>
<waitForPageLoad stepKey="waitForPageLoad9"/>
<click selector="{{CheckoutShippingSection.next}}" stepKey="clickNext1"/>
<waitForPageLoad stepKey="waitForPageLoad10"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
namespace Magento\Catalog\Controller\Adminhtml\Product;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\App\Action\HttpGetActionInterface;

/**
* Controller to search product for ui-select component
*/
class Search extends \Magento\Backend\App\Action
class Search extends \Magento\Backend\App\Action implements HttpGetActionInterface
{
/**
* Authorization level of a basic admin session
Expand Down Expand Up @@ -48,6 +49,8 @@ public function __construct(
}

/**
* Execute product search.
*
* @return \Magento\Framework\Controller\ResultInterface
*/
public function execute() : \Magento\Framework\Controller\ResultInterface
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ private function convertElementsToSelect($elements, $attributesToConvert)
if (!in_array($code, $codes)) {
continue;
}
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$options = call_user_func($attributesToConvert[$code]);
if (!is_array($options)) {
continue;
Expand Down Expand Up @@ -287,8 +288,14 @@ private function getBillingAddressComponent($paymentCode, $elements)
'provider' => 'checkoutProvider',
'deps' => 'checkoutProvider',
'dataScopePrefix' => 'billingAddress' . $paymentCode,
'billingAddressListProvider' => '${$.name}.billingAddressList',
'sortOrder' => 1,
'children' => [
'billingAddressList' => [
'component' => 'Magento_Checkout/js/view/billing-address/list',
'displayArea' => 'billing-address-list',
'template' => 'Magento_Checkout/billing-address/list'
],
'form-fields' => [
'component' => 'uiComponent',
'displayArea' => 'additional-fieldsets',
Expand Down
113 changes: 15 additions & 98 deletions app/code/Magento/Checkout/Model/DefaultConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Customer\Api\AddressMetadataInterface;
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
use Magento\Customer\Model\Address\CustomerAddressDataProvider;
use Magento\Customer\Model\Context as CustomerContext;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Customer\Model\Url as CustomerUrlManager;
Expand All @@ -34,6 +35,7 @@
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class DefaultConfigProvider implements ConfigProviderInterface
{
Expand Down Expand Up @@ -177,6 +179,11 @@ class DefaultConfigProvider implements ConfigProviderInterface
*/
private $addressMetadata;

/**
* @var CustomerAddressDataProvider
*/
private $customerAddressData;

/**
* @param CheckoutHelper $checkoutHelper
* @param Session $checkoutSession
Expand Down Expand Up @@ -206,6 +213,7 @@ class DefaultConfigProvider implements ConfigProviderInterface
* @param UrlInterface $urlBuilder
* @param AddressMetadataInterface $addressMetadata
* @param AttributeOptionManagementInterface $attributeOptionManager
* @param CustomerAddressDataProvider|null $customerAddressData
* @codeCoverageIgnore
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
Expand Down Expand Up @@ -237,7 +245,8 @@ public function __construct(
\Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement,
UrlInterface $urlBuilder,
AddressMetadataInterface $addressMetadata = null,
AttributeOptionManagementInterface $attributeOptionManager = null
AttributeOptionManagementInterface $attributeOptionManager = null,
CustomerAddressDataProvider $customerAddressData = null
) {
$this->checkoutHelper = $checkoutHelper;
$this->checkoutSession = $checkoutSession;
Expand Down Expand Up @@ -268,6 +277,8 @@ public function __construct(
$this->addressMetadata = $addressMetadata ?: ObjectManager::getInstance()->get(AddressMetadataInterface::class);
$this->attributeOptionManager = $attributeOptionManager ??
ObjectManager::getInstance()->get(AttributeOptionManagementInterface::class);
$this->customerAddressData = $customerAddressData ?:
ObjectManager::getInstance()->get(CustomerAddressDataProvider::class);
}

/**
Expand Down Expand Up @@ -359,57 +370,18 @@ private function isAutocompleteEnabled()
*
* @return array
*/
private function getCustomerData()
private function getCustomerData(): array
{
$customerData = [];
if ($this->isCustomerLoggedIn()) {
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
$customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
$customerData = $customer->__toArray();
foreach ($customer->getAddresses() as $key => $address) {
$customerData['addresses'][$key]['inline'] = $this->getCustomerAddressInline($address);
if ($address->getCustomAttributes()) {
$customerData['addresses'][$key]['custom_attributes'] = $this->filterNotVisibleAttributes(
$customerData['addresses'][$key]['custom_attributes']
);
}
}
$customerData['addresses'] = $this->customerAddressData->getAddressDataByCustomer($customer);
}
return $customerData;
}

/**
* Filter not visible on storefront custom attributes.
*
* @param array $attributes
* @return array
*/
private function filterNotVisibleAttributes(array $attributes)
{
$attributesMetadata = $this->addressMetadata->getAllAttributesMetadata();
foreach ($attributesMetadata as $attributeMetadata) {
if (!$attributeMetadata->isVisible()) {
unset($attributes[$attributeMetadata->getAttributeCode()]);
}
}

return $this->setLabelsToAttributes($attributes);
}

/**
* Set additional customer address data
*
* @param \Magento\Customer\Api\Data\AddressInterface $address
* @return string
*/
private function getCustomerAddressInline($address)
{
$builtOutputAddressData = $this->addressMapper->toFlatArray($address);
return $this->addressConfig
->getFormatByCode(\Magento\Customer\Model\Address\Config::DEFAULT_ADDRESS_FORMAT)
->getRenderer()
->renderArray($builtOutputAddressData);
}

/**
* Retrieve quote data
*
Expand Down Expand Up @@ -726,61 +698,6 @@ private function getPaymentMethods()
return $paymentMethods;
}

/**
* Set Labels to custom Attributes
*
* @param array $customAttributes
* @return array $customAttributes
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Exception\StateException
*/
private function setLabelsToAttributes(array $customAttributes) : array
{
if (!empty($customAttributes)) {
foreach ($customAttributes as $customAttributeCode => $customAttribute) {
$attributeOptionLabels = $this->getAttributeLabels($customAttribute, $customAttributeCode);
if (!empty($attributeOptionLabels)) {
$customAttributes[$customAttributeCode]['label'] = implode(', ', $attributeOptionLabels);
}
}
}

return $customAttributes;
}

/**
* Get Labels by CustomAttribute and CustomAttributeCode
*
* @param array $customAttribute
* @param string|integer $customAttributeCode
* @return array $attributeOptionLabels
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Exception\StateException
*/
private function getAttributeLabels(array $customAttribute, string $customAttributeCode) : array
{
$attributeOptionLabels = [];

if (!empty($customAttribute['value'])) {
$customAttributeValues = explode(',', $customAttribute['value']);
$attributeOptions = $this->attributeOptionManager->getItems(
\Magento\Customer\Model\Indexer\Address\AttributeProvider::ENTITY,
$customAttributeCode
);

if (!empty($attributeOptions)) {
foreach ($attributeOptions as $attributeOption) {
$attributeOptionValue = $attributeOption->getValue();
if (in_array($attributeOptionValue, $customAttributeValues)) {
$attributeOptionLabels[] = $attributeOption->getLabel() ?? $attributeOptionValue;
}
}
}
}

return $attributeOptionLabels;
}

/**
* Get notification messages for the quote items
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,21 @@
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskAfterPaymentMethodSelection"/>
</actionGroup>

<!-- Check selected shipping address information on shipping information step -->
<actionGroup name="CheckSelectedShippingAddressInCheckoutActionGroup">
<arguments>
<argument name="customerVar"/>
<argument name="customerAddressVar"/>
</arguments>
<waitForElement selector="{{CheckoutShippingSection.shippingTab}}" time="30" stepKey="waitForShippingSectionLoaded"/>
<see stepKey="VerifyFirstNameInSelectedAddress" selector="{{CheckoutShippingSection.selectedShippingAddress}}" userInput="{{customerVar.firstname}}" />
<see stepKey="VerifyLastNameInSelectedAddress" selector="{{CheckoutShippingSection.selectedShippingAddress}}" userInput="{{customerVar.lastname}}" />
<see stepKey="VerifyStreetInSelectedAddress" selector="{{CheckoutShippingSection.selectedShippingAddress}}" userInput="{{customerAddressVar.street[0]}}" />
<see stepKey="VerifyCityInSelectedAddress" selector="{{CheckoutShippingSection.selectedShippingAddress}}" userInput="{{customerAddressVar.city}}" />
<see stepKey="VerifyZipInSelectedAddress" selector="{{CheckoutShippingSection.selectedShippingAddress}}" userInput="{{customerAddressVar.postcode}}" />
<see stepKey="VerifyPhoneInSelectedAddress" selector="{{CheckoutShippingSection.selectedShippingAddress}}" userInput="{{customerAddressVar.telephone}}" />
</actionGroup>

<!-- Check billing address in checkout -->
<actionGroup name="CheckBillingAddressInCheckoutActionGroup">
<arguments>
Expand All @@ -257,6 +272,22 @@
<see userInput="{{customerAddressVar.telephone}}" selector="{{CheckoutPaymentSection.billingAddress}}" stepKey="assertBillingAddressTelephone"/>
</actionGroup>

<!-- Check billing address in checkout with billing address on payment page -->
<actionGroup name="CheckBillingAddressInCheckoutWithBillingAddressOnPaymentPageActionGroup">
<arguments>
<argument name="customerVar"/>
<argument name="customerAddressVar"/>
</arguments>
<waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" time="30" stepKey="waitForPaymentSectionLoaded"/>
<see userInput="{{customerVar.firstName}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsFirstName"/>
<see userInput="{{customerVar.lastName}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsLastName"/>
<see userInput="{{customerAddressVar.street[0]}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsStreet"/>
<see userInput="{{customerAddressVar.city}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsCity"/>
<see userInput="{{customerAddressVar.state}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsState"/>
<see userInput="{{customerAddressVar.postcode}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsPostcode"/>
<see userInput="{{customerAddressVar.telephone}}" selector="{{CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection.billingAddressDetails}}" stepKey="assertBillingAddressDetailsTelephone"/>
</actionGroup>

<!-- Checkout place order -->
<actionGroup name="CheckoutPlaceOrderActionGroup">
<arguments>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="FillNewShippingAddressModalActionGroup" extends="FillShippingAddressOneStreetActionGroup">
<arguments>
<argument name="address"/>
</arguments>
<selectOption stepKey="selectRegion" selector="{{CheckoutShippingSection.region}}"
userInput="{{address.state}}" after="fillCityName"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="CheckoutPaymentWithDisplayBillingAddressOnPaymentPageSection">
<element name="billingAddressDetails" type="text" selector="div.billing-address-details"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<item name="trigger" xsi:type="string">opc-new-shipping-address</item>
<item name="buttons" xsi:type="array">
<item name="save" xsi:type="array">
<item name="text" xsi:type="string" translate="true">Save Address</item>
<item name="text" xsi:type="string" translate="true">Ship here</item>
<item name="class" xsi:type="string">action primary action-save-address</item>
</item>
<item name="cancel" xsi:type="array">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ define([
'use strict';

return function (addressData) {
return addressConverter.formAddressDataToQuoteAddress(addressData);
var address = addressConverter.formAddressDataToQuoteAddress(addressData);

/**
* Returns new customer billing address type.
*
* @returns {String}
*/
address.getType = function () {
return 'new-customer-billing-address';
};

return address;
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ define([
newCustomerBillingAddressData = checkoutData.getNewCustomerBillingAddress();

if (selectedBillingAddress) {
if (selectedBillingAddress == 'new-customer-address' && newCustomerBillingAddressData) { //eslint-disable-line
if (selectedBillingAddress === 'new-customer-billing-address' && newCustomerBillingAddressData) {
selectBillingAddress(createBillingAddress(newCustomerBillingAddressData));
} else {
addressList.some(function (address) {
if (selectedBillingAddress == address.getKey()) { //eslint-disable-line eqeqeq
if (selectedBillingAddress === address.getKey()) {
selectBillingAddress(address);
}
});
Expand Down
Loading

0 comments on commit 932acf9

Please sign in to comment.