Skip to content

Commit 13fc5de

Browse files
MAGETWO-64544: When logged in customer edits a new shipping address during checkout they are unable to place the order #6488
1 parent b60a1ba commit 13fc5de

File tree

16 files changed

+456
-45
lines changed

16 files changed

+456
-45
lines changed

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

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,36 @@ define([
1515
'use strict';
1616

1717
var cacheKey = 'checkout-data',
18-
checkoutData,
19-
20-
/**
21-
* @return {*}
22-
*/
23-
getData = function () {
24-
return storage.get(cacheKey)();
25-
},
2618

2719
/**
2820
* @param {Object} data
2921
*/
3022
saveData = function (data) {
3123
storage.set(cacheKey, data);
32-
};
24+
},
3325

34-
if ($.isEmptyObject(getData())) {
35-
checkoutData = {
36-
'selectedShippingAddress': null,
37-
'shippingAddressFromData': null,
38-
'newCustomerShippingAddress': null,
39-
'selectedShippingRate': null,
40-
'selectedPaymentMethod': null,
41-
'selectedBillingAddress': null,
42-
'billingAddressFormData': null,
43-
'newCustomerBillingAddress': null
26+
/**
27+
* @return {*}
28+
*/
29+
getData = function () {
30+
var data = storage.get(cacheKey)();
31+
32+
if ($.isEmptyObject(data)) {
33+
data = {
34+
'selectedShippingAddress': null,
35+
'shippingAddressFromData': null,
36+
'newCustomerShippingAddress': null,
37+
'selectedShippingRate': null,
38+
'selectedPaymentMethod': null,
39+
'selectedBillingAddress': null,
40+
'billingAddressFormData': null,
41+
'newCustomerBillingAddress': null
42+
};
43+
saveData(data);
44+
}
45+
46+
return data;
4447
};
45-
saveData(checkoutData);
46-
}
4748

4849
return {
4950
/**

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
/**
66
* @api
77
*/
8-
define([], function () {
8+
define([
9+
'underscore'
10+
], function (_) {
911
'use strict';
1012

1113
/**
@@ -29,7 +31,7 @@ define([], function () {
2931
regionCode: addressData.region ? addressData.region['region_code'] : null,
3032
region: addressData.region ? addressData.region.region : null,
3133
customerId: addressData['customer_id'] || addressData.customerId,
32-
street: addressData.street,
34+
street: addressData.street ? _.compact(addressData.street) : addressData.street,
3335
company: addressData.company,
3436
telephone: addressData.telephone,
3537
fax: addressData.fax,

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

Lines changed: 23 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
*
@@ -170,6 +177,22 @@ public function getSelectedAddress()
170177
return $this->_rootElement->find($this->selectedAddress, Locator::SELECTOR_CSS)->getText();
171178
}
172179

180+
/**
181+
* Get address block.
182+
*
183+
* @param String $address
184+
*/
185+
public function editAddress($address)
186+
{
187+
$addresses = $this->_rootElement->getElements($this->shippingAddressBlock);
188+
foreach ($addresses as $addressBlock) {
189+
if (strpos($addressBlock->getText(), $address) === 0) {
190+
$addressBlock->find($this->editAddressButton)->click();
191+
break;
192+
}
193+
}
194+
}
195+
173196
/**
174197
* Select address.
175198
*

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 © 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-67837
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 © 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-67837">
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
@@ -146,11 +146,14 @@
146146
<data name="cart/data/shipping_amount" xsi:type="string">0.00</data>
147147
<data name="cart/data/grand_total" xsi:type="string">130.98</data>
148148
<data name="billingCheckboxState" xsi:type="string">Yes</data>
149+
<data name="editBillingInformation" xsi:type="boolean">false</data>
150+
<data name="refresh" xsi:type="boolean">true</data>
149151
<data name="payment/method" xsi:type="string">checkmo</data>
150152
<data name="configData" xsi:type="string">checkmo, freeshipping_minimum_order_amount_100</data>
151153
<constraint name="Magento\Checkout\Test\Constraint\AssertOrderSuccessPlacedMessage" />
152154
<constraint name="Magento\Checkout\Test\Constraint\AssertMinicartEmpty" />
153155
<constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal" />
156+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderAddresses" />
154157
</variation>
155158
<variation name="OnePageCheckoutTestVariation6" summary="Checkout as UK guest with virtual product using coupon for not logged in customers with Zero Subtotal Checkout payment method">
156159
<data name="issue" xsi:type="string">MAGETWO-64874: Eternal loader in shipping and tax block</data>

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Mtf\TestStep\TestStepInterface;
1212

1313
/**
14-
* Create customer custom attribute step.
14+
* Add new shipping address on checkout step.
1515
*/
1616
class AddNewShippingAddressStep implements TestStepInterface
1717
{
@@ -29,21 +29,30 @@ class AddNewShippingAddressStep implements TestStepInterface
2929
*/
3030
private $address;
3131

32+
/**
33+
* Save Shipping Address.
34+
*
35+
* @var boolean
36+
*/
37+
private $save;
38+
3239
/**
3340
* @constructor
3441
* @param CheckoutOnepage $checkoutOnepage
35-
* @param Address|null $address [optional]
42+
* @param Address|null $shippingAddress [optional]
43+
* @param boolean $save [optional]
3644
*/
37-
public function __construct(CheckoutOnepage $checkoutOnepage, Address $address = null)
45+
public function __construct(CheckoutOnepage $checkoutOnepage, Address $shippingAddress = null, $save = true)
3846
{
3947
$this->checkoutOnepage = $checkoutOnepage;
40-
$this->address = $address;
48+
$this->address = $shippingAddress;
49+
$this->save = $save;
4150
}
4251

4352
/**
44-
* Create customer account.
53+
* Add new shipping address.
4554
*
46-
* @return void
55+
* @return array
4756
*/
4857
public function run()
4958
{
@@ -52,6 +61,12 @@ public function run()
5261
if ($this->address) {
5362
$shippingBlock->getAddressModalBlock()->fill($this->address);
5463
}
55-
$shippingBlock->getAddressModalBlock()->save();
64+
if ($this->save) {
65+
$shippingBlock->getAddressModalBlock()->save();
66+
} else {
67+
$shippingBlock->getAddressModalBlock()->cancel();
68+
}
69+
70+
return ['shippingAddress' => $this->address];
5671
}
5772
}

0 commit comments

Comments
 (0)