Skip to content

Commit 5ec72e4

Browse files
committed
MAGETWO-70996: [GitHub] Customer Address "default billing address" Attribute Not Used in Checkout #8777
1 parent 212a533 commit 5ec72e4

File tree

12 files changed

+152
-23
lines changed

12 files changed

+152
-23
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<waitForPageLoad stepKey="waitForPageLoad10"/>
8888
<click selector="{{BraintreeConfigurationPaymentSection.paymentMethod}}" stepKey="SelectBraintreePaymentMethod1"/>
8989
<waitForPageLoad stepKey="waitForPageLoad11"/>
90+
<click selector="{{CheckoutPaymentSection.shippingAndBillingAddressSame}}" stepKey="CheckCheckBox"/>
9091
<click selector="{{CheckoutPaymentSection.shippingAndBillingAddressSame}}" stepKey="UncheckCheckBox"/>
9192

9293
<click selector="{{CheckoutShippingSection.updateAddress}}" stepKey="clickToUpdate"/>

app/code/Magento/Checkout/Test/Mftf/Section/CheckoutPaymentSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@
5454
<element name="addressBook" type="button" selector="//a[text()='Address Book']"/>
5555
<element name="noQuotes" type="text" selector=".no-quotes-block"/>
5656
<element name="paymentMethodByName" type="text" selector="//*[@id='checkout-payment-method-load']//*[contains(@class, 'payment-group')]//label[normalize-space(.)='{{var1}}']" parameterized="true"/>
57+
<element name="addressOptionByName" type="text" selector=" //option[text()='{{action}}']" parameterized="true"/>
5758
</section>
5859
</sections>

app/code/Magento/Checkout/Test/Mftf/Section/StorefrontCheckoutPaymentMethodSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
<element name="billingAddress" type="text" selector=".checkout-billing-address"/>
1313
<element name="checkPaymentMethodByName" type="radio" selector="//div[@id='checkout-payment-method-load']//div[@class='payment-method']//label//span[contains(., '{{methodName}}')]/../..//input" parameterized="true"/>
1414
<element name="billingAddressSameAsShipping" type="checkbox" selector=".payment-method._active [name='billing-address-same-as-shipping']"/>
15+
<element name="billingAddressSameAsShippingShared" type="checkbox" selector="#billing-address-same-as-shipping-shared"/>
1516
</section>
1617
</sections>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="DefaultBillingAddressShouldBeCheckedOnPaymentPageTest">
12+
<annotations>
13+
<features value="Checkout"/>
14+
<stories value="Checkout via the Storefront"/>
15+
<title value="The default billing address should be used on checkout"/>
16+
<description value="Default billing address should be preselected on payments page on checkout if it exist"/>
17+
<severity value="CRITICAL"/>
18+
<testCaseId value="MAGETWO-98892"/>
19+
<useCaseId value="MAGETWO-70996"/>
20+
<group value="checkout"/>
21+
</annotations>
22+
<before>
23+
<createData entity="_defaultCategory" stepKey="createCategory"/>
24+
<createData entity="SimpleProduct" stepKey="createProduct">
25+
<requiredEntity createDataKey="createCategory"/>
26+
</createData>
27+
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
28+
</before>
29+
<after>
30+
<!--Logout from customer account-->
31+
<actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="logoutCustomer"/>
32+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
33+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
34+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
35+
</after>
36+
<!--Go to Storefront as Customer-->
37+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="customerLogin">
38+
<argument name="Customer" value="$$createCustomer$$" />
39+
</actionGroup>
40+
<!-- Add simple product to cart and go to checkout-->
41+
<actionGroup ref="AddSimpleProductToCart" stepKey="addProductToCart">
42+
<argument name="product" value="$$createProduct$$"/>
43+
</actionGroup>
44+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart"/>
45+
<!-- Click "+ New Address" and Fill new address-->
46+
<click selector="{{CheckoutShippingSection.newAddressButton}}" stepKey="addAddress"/>
47+
<actionGroup ref="LoggedInCheckoutWithOneAddressFieldWithoutStateField" stepKey="changeAddress">
48+
<argument name="Address" value="UK_Not_Default_Address"/>
49+
<argument name="classPrefix" value="._show"/>
50+
</actionGroup>
51+
<!--Click "Save Addresses" -->
52+
<click selector="{{CheckoutShippingSection.saveAddress}}" stepKey="saveAddress"/>
53+
<waitForPageLoad stepKey="waitForAddressSaved"/>
54+
<dontSeeElement selector="{{StorefrontCheckoutAddressPopupSection.newAddressModalPopup}}" stepKey="dontSeeModalPopup"/>
55+
<!--Select Shipping Rate "Flat Rate" and click "Next" button-->
56+
<click selector="{{CheckoutShippingMethodsSection.checkShippingMethodByName('Flat Rate')}}" stepKey="selectFlatShippingMethod"/>
57+
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask2"/>
58+
<click selector="{{CheckoutShippingMethodsSection.next}}" stepKey="clickNext"/>
59+
<!--Verify that "My billing and shipping address are the same" is unchecked and billing address is preselected-->
60+
<dontSeeCheckboxIsChecked selector="{{CheckoutPaymentSection.billingAddressNotSameCheckbox}}" stepKey="shippingAndBillingAddressIsSameUnchecked"/>
61+
<see selector="{{CheckoutPaymentSection.billingAddress}}" userInput="{{US_Address_TX.street[0]}}" stepKey="assertBillingAddress"/>
62+
</test>
63+
</tests>

app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerCheckoutTest.xml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
<!-- Checkout select Check/Money Order payment -->
197197
<actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectCheckMoneyPayment2"/>
198198
<waitForElement stepKey="waitForPlaceOrderButton2" selector="{{CheckoutPaymentSection.placeOrder}}" time="30" />
199-
<see stepKey="seeBillingAddressIsCorrect2" selector="{{CheckoutPaymentSection.billingAddress}}" userInput="{{UK_Not_Default_Address.street[0]}}" />
199+
<see stepKey="seeBillingAddressIsCorrect2" selector="{{CheckoutPaymentSection.billingAddress}}" userInput="{{US_Address_NY.street[0]}}" />
200200
<click stepKey="clickPlaceOrderButton2" selector="{{CheckoutPaymentSection.placeOrder}}" />
201201
<waitForPageLoad stepKey="waitForOrderSuccessPage2"/>
202202
<see stepKey="seeSuccessMessage2" selector="{{CheckoutSuccessMainSection.success}}" userInput="Your order number is:" />
@@ -216,6 +216,7 @@
216216
<createData entity="ApiSimpleProduct" stepKey="createProduct">
217217
<requiredEntity createDataKey="createCategory"/>
218218
</createData>
219+
<magentoCLI stepKey="setShowBillingAddressOnCheckout" command="config:set checkout/options/display_billing_address_on 1" />
219220
<magentoCLI stepKey="allowSpecificValue" command="config:set payment/checkmo/allowspecific 1" />
220221
<magentoCLI stepKey="specificCountryValue" command="config:set payment/checkmo/specificcountry GB" />
221222
<createData entity="Simple_US_Customer" stepKey="simpleuscustomer"/>
@@ -226,6 +227,7 @@
226227
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
227228
<magentoCLI stepKey="allowSpecificValue" command="config:set payment/checkmo/allowspecific 0" />
228229
<magentoCLI stepKey="specificCountryValue" command="config:set payment/checkmo/specificcountry ''" />
230+
<magentoCLI stepKey="setShowBillingAddressOnCheckout" command="config:set checkout/options/display_billing_address_on 0" />
229231
</after>
230232
<!-- Login as Customer -->
231233
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="customerLogin">
@@ -253,16 +255,19 @@
253255
<dontsee selector="{{CheckoutPaymentSection.paymentMethodByName('Check / Money order')}}" stepKey="paymentMethodDoesNotAvailable"/>
254256

255257
<!-- Fill UK Address and verify that payment available and checkout successful -->
256-
<click selector="{{CheckoutHeaderSection.shippingMethodStep}}" stepKey="goToShipping" />
257-
<click selector="{{CheckoutShippingSection.newAddressButton}}" stepKey="fillNewAddress" />
258-
<actionGroup ref="LoggedInUserCheckoutAddNewShippingSectionWithoutRegionActionGroup" stepKey="customerCheckoutFillingShippingSectionUK">
259-
<argument name="customerVar" value="CustomerEntityOne" />
260-
<argument name="customerAddressVar" value="UK_Not_Default_Address" />
258+
<click selector="{{StorefrontCheckoutPaymentMethodSection.billingAddressSameAsShippingShared}}" stepKey="UncheckCheckCheckBox"/>
259+
<click selector="{{CheckoutShippingSection.addressDropdown}}" stepKey="clickOnAddressDropDown"/>
260+
<click selector="{{CheckoutPaymentSection.addressOptionByName('New Address')}}" stepKey="clickOnNewAddress"/>
261+
<waitForPageLoad stepKey="waitNewAddressBillingForm"/>
262+
<actionGroup ref="LoggedInCheckoutFillNewBillingAddressActionGroup" stepKey="changeAddress">
263+
<argument name="Address" value="updateCustomerUKAddress"/>
264+
<argument name="classPrefix" value="[aria-hidden=false]"/>
261265
</actionGroup>
266+
<click selector="{{CheckoutPaymentSection.addressAction('Update')}}" stepKey="clickUpdateBillingAddressButton" />
262267
<actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="customerSelectCheckMoneyOrderPayment" />
263268
<actionGroup ref="CheckoutPlaceOrderActionGroup" stepKey="customerPlaceorder">
264269
<argument name="orderNumberMessage" value="CONST.successCheckoutOrderNumberMessage" />
265270
<argument name="emailYouMessage" value="CONST.successCheckoutEmailYouMessage" />
266271
</actionGroup>
267272
</test>
268-
</tests>
273+
</tests>

app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerPlaceOrderWithNewAddressesThatWasEditedTest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<click selector="{{CheckoutShippingMethodsSection.next}}" stepKey="clickNext"/>
7272

7373
<!--Refresh Page and Place Order-->
74+
<actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectCheckMoneyPayment"/>
7475
<reloadPage stepKey="reloadPage"/>
7576
<waitForElement selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="waitForPlaceOrderButton"/>
7677
<click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrder"/>
@@ -89,7 +90,7 @@
8990
<amOnPage url="{{StorefrontCustomerOrderViewPage.url({$grabOrderNumber})}}" stepKey="goToOrderReviewPage"/>
9091
<see userInput="{{UK_Not_Default_Address.street[0]}} {{UK_Not_Default_Address.city}}, {{UK_Not_Default_Address.postcode}}"
9192
selector="{{StorefrontCustomerOrderViewSection.shippingAddress}}" stepKey="checkShippingAddress"/>
92-
<see userInput="{{UK_Not_Default_Address.street[0]}} {{UK_Not_Default_Address.city}}, {{UK_Not_Default_Address.postcode}}"
93+
<see userInput="{{US_Address_TX_Default_Billing.street[0]}}"
9394
selector="{{StorefrontCustomerOrderViewSection.billingAddress}}" stepKey="checkBillingAddress"/>
9495
</test>
9596
</tests>

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,12 @@ define([
243243
return;
244244
}
245245

246-
if (quote.isVirtual()) {
247-
isBillingAddressInitialized = addressList.some(function (addrs) {
246+
if (quote.isVirtual() || !quote.billingAddress()) {
247+
addressList.some(function (addrs) {
248248
if (addrs.isDefaultBilling()) {
249249
selectBillingAddress(addrs);
250-
251-
return true;
250+
isBillingAddressInitialized = true;
252251
}
253-
254-
return false;
255252
});
256253
}
257254

dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutTest.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
<data name="shippingAddressCustomer" xsi:type="array">
1616
<item name="added" xsi:type="number">1</item>
1717
</data>
18-
<data name="billingAddressCustomer" xsi:type="array">
19-
<item name="added" xsi:type="number">1</item>
20-
</data>
2118
<data name="prices" xsi:type="array">
2219
<item name="grandTotal" xsi:type="string">565.00</item>
2320
</data>
2421
<data name="shipping/shipping_service" xsi:type="string">Flat Rate</data>
22+
<data name="editBillingInformation" xsi:type="boolean">false</data>
2523
<data name="shipping/shipping_method" xsi:type="string">Fixed</data>
2624
<data name="payment/method" xsi:type="string">checkmo</data>
2725
<data name="configData" xsi:type="string">checkmo</data>
@@ -43,6 +41,7 @@
4341
<item name="grandTotal" xsi:type="string">565.00</item>
4442
</data>
4543
<data name="shipping/shipping_service" xsi:type="string">Flat Rate</data>
44+
<data name="editBillingInformation" xsi:type="boolean">false</data>
4645
<data name="shipping/shipping_method" xsi:type="string">Fixed</data>
4746
<data name="payment/method" xsi:type="string">checkmo</data>
4847
<data name="configData" xsi:type="string">checkmo</data>
@@ -61,7 +60,7 @@
6160
<data name="shippingAddress/dataset" xsi:type="string">UK_address_without_email</data>
6261
<data name="shipping/shipping_service" xsi:type="string">Flat Rate</data>
6362
<data name="shipping/shipping_method" xsi:type="string">Fixed</data>
64-
<data name="billingCheckboxState" xsi:type="string">Yes</data>
63+
<data name="editBillingInformation" xsi:type="boolean">false</data>
6564
<data name="billingAddress/dataset" xsi:type="string">US_address_1_without_email</data>
6665
<data name="payment/method" xsi:type="string">checkmo</data>
6766
<data name="configData" xsi:type="string">checkmo</data>

dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/FillBillingInformationStep.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,15 @@ public function run()
126126
if ($this->billingCheckboxState) {
127127
$this->assertBillingAddressCheckbox->processAssert($this->checkoutOnepage, $this->billingCheckboxState);
128128
}
129-
if ($this->billingCheckboxState === 'Yes' && !$this->editBillingInformation) {
130-
return [
131-
'billingAddress' => $this->shippingAddress
132-
];
129+
130+
if (!$this->editBillingInformation) {
131+
$billingAddress = $this->billingCheckboxState === 'Yes'
132+
? $this->shippingAddress
133+
: $this->getDefaultBillingAddress();
134+
135+
return ['billingAddress' => $billingAddress];
133136
}
137+
134138
if ($this->billingAddress) {
135139
$selectedPaymentMethod = $this->checkoutOnepage->getPaymentBlock()->getSelectedPaymentMethodBlock();
136140
if ($this->shippingAddress) {
@@ -139,9 +143,11 @@ public function run()
139143
$selectedPaymentMethod->getBillingBlock()->fillBilling($this->billingAddress);
140144
$billingAddress = $this->billingAddress;
141145
}
146+
142147
if (isset($this->billingAddressCustomer['added'])) {
143148
$addressIndex = $this->billingAddressCustomer['added'];
144-
$billingAddress = $this->customer->getDataFieldConfig('address')['source']->getAddresses()[$addressIndex];
149+
$billingAddress = $this->customer->getDataFieldConfig('address')['source']
150+
->getAddresses()[$addressIndex];
145151
$address = $this->objectManager->create(
146152
\Magento\Customer\Test\Block\Address\Renderer::class,
147153
['address' => $billingAddress, 'type' => 'html_for_select_element']
@@ -156,4 +162,23 @@ public function run()
156162
'billingAddress' => $billingAddress
157163
];
158164
}
165+
166+
/**
167+
* Get default billing address
168+
*
169+
* @return Address|null
170+
*/
171+
private function getDefaultBillingAddress()
172+
{
173+
$addresses = $this->customer->getDataFieldConfig('address')['source']->getAddresses();
174+
$defaultAddress = null;
175+
foreach ($addresses as $address) {
176+
if ($address->getDefaultBilling() === 'Yes') {
177+
$defaultAddress = $address;
178+
break;
179+
}
180+
}
181+
182+
return $defaultAddress;
183+
}
159184
}

dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/cc-form.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ define([
1515
describe('Magento_Braintree/js/view/payment/method-renderer/cc-form', function () {
1616
var injector = new Squire(),
1717
mocks = {
18+
'Magento_Checkout/js/model/checkout-data-resolver': {
19+
20+
/** Stub */
21+
applyBillingAddress: function () {
22+
return true;
23+
},
24+
25+
/** Stub */
26+
resolveBillingAddress: function () {
27+
return true;
28+
}
29+
},
1830
'Magento_Checkout/js/model/quote': {
1931
billingAddress: ko.observable(),
2032
shippingAddress: ko.observable(),

0 commit comments

Comments
 (0)