Skip to content

Commit 57a7aab

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-65656' into 2.1.8-develop-pr24
# Conflicts: # dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/FillShippingAddressStep.php # dev/tests/functional/tests/app/Magento/Checkout/Test/etc/testcase.xml
2 parents 76611ae + 8751b91 commit 57a7aab

File tree

23 files changed

+796
-74
lines changed

23 files changed

+796
-74
lines changed

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,32 @@ define([
1515

1616
var cacheKey = 'checkout-data';
1717

18-
var getData = function () {
19-
return storage.get(cacheKey)();
20-
};
21-
2218
var saveData = function (checkoutData) {
2319
storage.set(cacheKey, checkoutData);
24-
};
20+
},
21+
22+
/**
23+
* @return {*}
24+
*/
25+
getData = function () {
26+
var data = storage.get(cacheKey)();
27+
28+
if ($.isEmptyObject(data)) {
29+
data = {
30+
'selectedShippingAddress': null,
31+
'shippingAddressFromData': null,
32+
'newCustomerShippingAddress': null,
33+
'selectedShippingRate': null,
34+
'selectedPaymentMethod': null,
35+
'selectedBillingAddress': null,
36+
'billingAddressFormData': null,
37+
'newCustomerBillingAddress': null
38+
};
39+
saveData(data);
40+
}
2541

26-
if ($.isEmptyObject(getData())) {
27-
var checkoutData = {
28-
'selectedShippingAddress': null,
29-
'shippingAddressFromData' : null,
30-
'newCustomerShippingAddress' : null,
31-
'selectedShippingRate' : null,
32-
'selectedPaymentMethod' : null,
33-
'selectedBillingAddress' : null,
34-
'billingAddressFormData' : null,
35-
'newCustomerBillingAddress' : null
36-
};
37-
saveData(checkoutData);
38-
}
42+
return data;
43+
};
3944

4045
return {
4146
setSelectedShippingAddress: function (data) {

app/code/Magento/Checkout/view/frontend/web/js/model/cart/cache.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,28 @@ define([
2626
},
2727

2828
/**
29-
* Get data from local storage.
29+
* Set data to local storage.
3030
*
31-
* @param {String} [key]
32-
* @returns {*}
31+
* @param {Object} checkoutData
3332
*/
34-
getData = function (key) {
35-
return key ? storage.get(cacheKey)()[key] : storage.get(cacheKey)();
33+
setData = function (checkoutData) {
34+
storage.set(cacheKey, checkoutData);
3635
},
3736

3837
/**
39-
* Set data to local storage.
38+
* Get data from local storage.
4039
*
41-
* @param {Object} checkoutData
40+
* @param {String} [key]
41+
* @returns {*}
4242
*/
43-
setData = function (checkoutData) {
44-
storage.set(cacheKey, checkoutData);
43+
getData = function (key) {
44+
var data = key ? storage.get(cacheKey)()[key] : storage.get(cacheKey)();
45+
46+
if (_.isEmpty(storage.get(cacheKey)())) {
47+
setData(utils.copy(cartData));
48+
}
49+
50+
return data;
4551
},
4652

4753
/**
@@ -59,10 +65,6 @@ define([
5965
return prefix + name.charAt(0).toUpperCase() + name.slice(1) + suffix;
6066
};
6167

62-
if (_.isEmpty(getData())) {
63-
setData(utils.copy(cartData));
64-
}
65-
6668
/**
6769
* Provides get/set/isChanged/clear methods for work with cart data.
6870
* Can be customized via mixin functionality.

app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
*/
55
/*jshint browser:true jquery:true*/
66
/*global alert*/
7-
define([], function () {
7+
define([
8+
'underscore'
9+
], function (_) {
10+
'use strict';
11+
812
/**
913
* @param {Object} addressData
1014
* Returns new address object
@@ -26,7 +30,7 @@ define([], function () {
2630
regionCode: (addressData.region) ? addressData.region.region_code : null,
2731
region: (addressData.region) ? addressData.region.region : null,
2832
customerId: addressData.customer_id || addressData.customerId,
29-
street: addressData.street,
33+
street: addressData.street ? _.compact(addressData.street) : addressData.street,
3034
company: addressData.company,
3135
telephone: addressData.telephone,
3236
fax: addressData.fax,

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ define(
1313
'./postcode-validator',
1414
'mage/translate',
1515
'uiRegistry',
16-
'Magento_Checkout/js/model/quote'
16+
'Magento_Checkout/js/model/quote',
17+
'Magento_Checkout/js/model/shipping-address/form-popup-state'
1718
],
1819
function (
1920
$,
@@ -24,7 +25,8 @@ define(
2425
postcodeValidator,
2526
$t,
2627
uiRegistry,
27-
quote
28+
quote,
29+
formPopUpState
2830
) {
2931
'use strict';
3032

@@ -127,12 +129,14 @@ define(
127129
});
128130
} else {
129131
element.on('value', function () {
130-
clearTimeout(self.validateAddressTimeout);
131-
self.validateAddressTimeout = setTimeout(function () {
132-
if (self.postcodeValidation()) {
133-
self.validateFields();
134-
}
135-
}, delay);
132+
if (!formPopUpState.isVisible()) {
133+
clearTimeout(self.validateAddressTimeout);
134+
self.validateAddressTimeout = setTimeout(function () {
135+
if (self.postcodeValidation()) {
136+
self.validateFields();
137+
}
138+
}, delay);
139+
}
136140
});
137141
observedElements.push(element);
138142
}

app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ define(
113113
if (shippingAddressData) {
114114
checkoutProvider.set(
115115
'shippingAddress',
116-
$.extend({}, checkoutProvider.get('shippingAddress'), shippingAddressData)
116+
$.extend(true, {}, checkoutProvider.get('shippingAddress'), shippingAddressData)
117117
);
118118
}
119119
checkoutProvider.on('shippingAddress', function (shippingAddressData) {
@@ -150,20 +150,39 @@ define(
150150
{
151151
text: buttons.cancel.text ? buttons.cancel.text : $t('Cancel'),
152152
class: buttons.cancel.class ? buttons.cancel.class : 'action secondary action-hide-popup',
153-
click: function () {
154-
this.closeModal();
155-
}
153+
154+
/** @inheritdoc */
155+
click: this.onClosePopUp.bind(this)
156156
}
157157
];
158158
this.popUpForm.options.closed = function () {
159159
self.isFormPopUpVisible(false);
160160
};
161+
162+
this.popUpForm.options.modalCloseBtnHandler = this.onClosePopUp.bind(this);
163+
this.popUpForm.options.keyEventHandlers = {
164+
escapeKey: this.onClosePopUp.bind(this)
165+
};
166+
167+
/** @inheritdoc */
168+
this.popUpForm.options.opened = function () {
169+
// Store temporary address for revert action in case when user click cancel action
170+
self.temporaryAddress = $.extend(true, {}, checkoutData.getShippingAddressFromData());
171+
};
161172
popUp = modal(this.popUpForm.options, $(this.popUpForm.element));
162173
}
163174

164175
return popUp;
165176
},
166177

178+
/**
179+
* Revert address and close modal.
180+
*/
181+
onClosePopUp: function () {
182+
checkoutData.setShippingAddressFromData($.extend(true, {}, this.temporaryAddress));
183+
this.getPopUp().closeModal();
184+
},
185+
167186
/**
168187
* Show address form popup
169188
*/
@@ -190,7 +209,7 @@ define(
190209
newShippingAddress = createShippingAddress(addressData);
191210
selectShippingAddress(newShippingAddress);
192211
checkoutData.setSelectedShippingAddress(newShippingAddress.getKey());
193-
checkoutData.setNewCustomerShippingAddress(addressData);
212+
checkoutData.setNewCustomerShippingAddress($.extend(true, {}, addressData));
194213
this.getPopUp().closeModal();
195214
this.isNewAddressAdded(true);
196215
}

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ class Shipping extends Form
2222
*/
2323
private $newAddressButton = '[data-bind*="isNewAddressAdded"]';
2424

25+
/**
26+
* CSS Selector for "Edit" button.
27+
*
28+
* @var string
29+
*/
30+
private $editAddressButton = '.edit-address-link';
31+
2532
/**
2633
* Wait element.
2734
*
@@ -106,6 +113,23 @@ public function getSelectedAddress()
106113
return $this->_rootElement->find($this->selectedAddress)->getText();
107114
}
108115

116+
/**
117+
* Get address block.
118+
*
119+
* @param String $address
120+
* @return void
121+
*/
122+
public function editAddress($address)
123+
{
124+
$addresses = $this->_rootElement->getElements($this->shippingAddressBlock);
125+
foreach ($addresses as $addressBlock) {
126+
if (strpos($addressBlock->getText(), $address) === 0) {
127+
$addressBlock->find($this->editAddressButton)->click();
128+
break;
129+
}
130+
}
131+
}
132+
109133
/**
110134
* Select address.
111135
*

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Shipping/AddressModal.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ class AddressModal extends Form
2020
*/
2121
private $saveButton = '.action-save-address';
2222

23+
/**
24+
* CSS Selector for Cancel button.
25+
*
26+
* @var string
27+
*/
28+
private $cancelButton = '.action-hide-popup';
29+
2330
/**
2431
* Selector for field's error message.
2532
*
@@ -51,6 +58,16 @@ public function save()
5158
$this->_rootElement->find($this->saveButton)->click();
5259
}
5360

61+
/**
62+
* Click on 'Cancel' button.
63+
*
64+
* @return void
65+
*/
66+
public function cancel()
67+
{
68+
$this->_rootElement->find($this->cancelButton)->click();
69+
}
70+
5471
/**
5572
* Get Error messages for attributes.
5673
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Checkout\Test\TestCase;
8+
9+
use Magento\Mtf\TestCase\Scenario;
10+
11+
/**
12+
* Preconditions:
13+
*
14+
* 1. Simple product is created.
15+
* 2. Customer with default billing/shipping address is created.
16+
*
17+
* Steps:
18+
* 1. Go to Frontend as Customer.
19+
* 2. Add product in cart and proceed to checkout.
20+
* 3. Click *New Address* button on 1st checkout step.
21+
* 4. Fill in required fields and click *Save address* button.
22+
* 5. Select Shipping Rate.
23+
* 6. Click *Edit* button for the new address.
24+
* 7. Remove values from required fields and click *Cancel* button.
25+
* 8. Go to *Next*.
26+
* 9. Select payment solution.
27+
* 10. Refresh page.
28+
* 11. Click Place order.
29+
* 12. Perform all assertions.
30+
*
31+
* @group Checkout
32+
* @ZephyrId MAGETWO-71053
33+
*/
34+
class EditShippingAddressOnePageCheckoutTest extends Scenario
35+
{
36+
/**
37+
* Edit Shipping Address on Checkout Page.
38+
*
39+
* @return void
40+
*/
41+
public function test()
42+
{
43+
$this->executeScenario();
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\Checkout\Test\TestCase\EditShippingAddressOnePageCheckoutTest" summary="Customer can place order with new addresses that was edited during checkout with several conditions" ticketId="MAGETWO-71053">
10+
<variation name="EditShippingAddressOnePageCheckoutTestVariation1">
11+
<data name="tag" xsi:type="string">severity:S1</data>
12+
<data name="customer/dataset" xsi:type="string">johndoe_with_addresses</data>
13+
<data name="shippingAddress/dataset" xsi:type="string">UK_address_without_email</data>
14+
<data name="editShippingAddress/dataset" xsi:type="string">empty_UK_address_without_email</data>
15+
<data name="shipping/shipping_service" xsi:type="string">Flat Rate</data>
16+
<data name="shipping/shipping_method" xsi:type="string">Fixed</data>
17+
<data name="billingCheckboxState" xsi:type="string">Yes</data>
18+
<data name="products" xsi:type="array">
19+
<item name="0" xsi:type="string">catalogProductSimple::default</item>
20+
</data>
21+
<data name="payment/method" xsi:type="string">checkmo</data>
22+
<data name="editBillingInformation" xsi:type="boolean">false</data>
23+
<data name="editSave" xsi:type="boolean">false</data>
24+
<data name="refresh" xsi:type="boolean">true</data>
25+
<constraint name="Magento\Checkout\Test\Constraint\AssertOrderSuccessPlacedMessage" />
26+
<constraint name="Magento\Customer\Test\Constraint\AssertAdditionalAddressCreatedFrontend" />
27+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderAddresses" />
28+
</variation>
29+
</testCase>
30+
</config>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,14 @@
105105
<data name="cart/data/shipping_amount" xsi:type="string">0.00</data>
106106
<data name="cart/data/grand_total" xsi:type="string">130.98</data>
107107
<data name="billingCheckboxState" xsi:type="string">Yes</data>
108+
<data name="editBillingInformation" xsi:type="boolean">false</data>
109+
<data name="refresh" xsi:type="boolean">true</data>
108110
<data name="payment/method" xsi:type="string">checkmo</data>
109111
<data name="configData" xsi:type="string">checkmo, freeshipping_minimum_order_amount_100</data>
110112
<constraint name="Magento\Checkout\Test\Constraint\AssertOrderSuccessPlacedMessage"/>
111113
<constraint name="Magento\Checkout\Test\Constraint\AssertMinicartEmpty" />
112114
<constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal"/>
115+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderAddresses" />
113116
</variation>
114117
</testCase>
115118
</config>

0 commit comments

Comments
 (0)