Skip to content

Commit 9bb82a1

Browse files
author
Stanislav Idolov
committed
MAGETWO-39446: "Place Order" button should be disabled until billing address is set
1 parent e533ff3 commit 9bb82a1

File tree

8 files changed

+51
-7
lines changed

8 files changed

+51
-7
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ define(
1818
function (ko, Component, customer, addressList, quote, createBillingAddress, selectBillingAddress, $t) {
1919
"use strict";
2020

21-
var newAddressOption = {
21+
var lastSelectedBillingAddress = null,
22+
newAddressOption = {
2223
getAddressInline: function() {
2324
return $t('New Address');
2425
},
@@ -71,6 +72,8 @@ define(
7172
selectBillingAddress(quote.shippingAddress());
7273
this.isAddressDetailsVisible(true);
7374
} else {
75+
lastSelectedBillingAddress = quote.billingAddress();
76+
quote.billingAddress(null);
7477
this.isAddressDetailsVisible(false);
7578
}
7679
return true;
@@ -97,10 +100,13 @@ define(
97100
},
98101

99102
editAddress: function () {
103+
lastSelectedBillingAddress = quote.billingAddress();
104+
quote.billingAddress(null);
100105
this.isAddressDetailsVisible(false);
101106
},
102107

103108
cancelAddressEdit: function () {
109+
this.restoreBillingAddress();
104110
if (quote.billingAddress()) {
105111
// restore 'Same As Shipping' checkbox state
106112
this.isAddressSameAsShipping(
@@ -110,6 +116,12 @@ define(
110116
}
111117
},
112118

119+
restoreBillingAddress: function() {
120+
if (lastSelectedBillingAddress != null) {
121+
selectBillingAddress(lastSelectedBillingAddress);
122+
}
123+
},
124+
113125
onAddressChange: function (address) {
114126
this.isAddressFormVisible(address == newAddressOption);
115127
}

app/code/Magento/Checkout/view/frontend/web/js/view/payment/default.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ define(
1717
'use strict';
1818
return Component.extend({
1919
redirectAfterPlaceOrder: true,
20+
isPlaceOrderActionAllowed: ko.observable(true),
2021
/**
2122
* Initialize view.
2223
*
2324
* @returns {Component} Chainable.
2425
*/
2526
initialize: function () {
2627
this._super().initChildren();
28+
29+
quote.billingAddress.subscribe(function(address) {
30+
this.isPlaceOrderActionAllowed((address !== null));
31+
}, this);
32+
2733
return this;
2834
},
2935

app/code/Magento/OfflinePayments/view/frontend/web/template/payment/banktransfer.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
<div class="primary">
3030
<button class="action primary checkout"
3131
type="submit"
32-
data-bind="click: placeOrder, attr: {'title': $t('Place Order')}, enable: (getCode() == isChecked())"
32+
data-bind="
33+
click: placeOrder,
34+
attr: {'title': $t('Place Order')},
35+
enable: (getCode() == isChecked()),
36+
css: {disabled: !isPlaceOrderActionAllowed()}
37+
"
3338
disabled>
3439
<span data-bind="text: $t('Place Order')"></span>
3540
</button>

app/code/Magento/OfflinePayments/view/frontend/web/template/payment/cashondelivery.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
<div class="primary">
3030
<button class="action primary checkout"
3131
type="submit"
32-
data-bind="click: placeOrder, attr: {title: $t('Place Order')}, enable: (getCode() == isChecked())"
32+
data-bind="
33+
click: placeOrder,
34+
attr: {title: $t('Place Order')},
35+
enable: (getCode() == isChecked()),
36+
css: {disabled: !isPlaceOrderActionAllowed()}
37+
"
3338
disabled>
3439
<span data-bind="text: $t('Place Order')"></span>
3540
</button>

app/code/Magento/OfflinePayments/view/frontend/web/template/payment/checkmo.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@
4141
<div class="primary">
4242
<button class="action primary checkout"
4343
type="submit"
44-
data-bind="click: placeOrder, attr: {title: $t('Place Order')}, enable: (getCode() == isChecked())"
44+
data-bind="
45+
click: placeOrder,
46+
attr: {title: $t('Place Order')},
47+
css: {disabled: !isPlaceOrderActionAllowed()},
48+
enable: (getCode() == isChecked())
49+
"
4550
disabled>
4651
<span data-bind="text: $t('Place Order')"></span>
4752
</button>

app/code/Magento/OfflinePayments/view/frontend/web/template/payment/purchaseorder-form.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@
4949
<div class="primary">
5050
<button class="action primary checkout"
5151
type="submit"
52-
data-bind="click: placeOrder, attr: {title: $t('Place Order')}, enable: (getCode() == isChecked())"
52+
data-bind="
53+
click: placeOrder,
54+
attr: {title: $t('Place Order')},
55+
enable: (getCode() == isChecked()),
56+
css: {disabled: !isPlaceOrderActionAllowed()}
57+
"
5358
data-role="review-save">
5459
<span data-bind="text: $t('Place Order')"></span>
5560
</button>

app/code/Magento/Payment/view/frontend/web/template/payment/free.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
<div class="primary">
2828
<button class="action primary checkout"
2929
type="submit"
30-
data-bind="click: placeOrder, attr: {title: $t('Place Order')}">
30+
data-bind="
31+
click: placeOrder,
32+
attr: {title: $t('Place Order')},
33+
css: {disabled: !isPlaceOrderActionAllowed()}
34+
">
3135
<span data-bind="text: $t('Place Order')"></span>
3236
</button>
3337
</div>

app/code/Magento/Payment/view/frontend/web/template/payment/iframe.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
<div class="primary">
3131
<button data-role="review-save" type="submit"
3232
data-bind="attr: {title: $t('Place order')}"
33-
class="button action primary checkout"><span data-bind="text: $t('Place order')"></span></button>
33+
class="button action primary checkout">
34+
<span data-bind="text: $t('Place order')"></span>
35+
</button>
3436
<button type="submit" id="originalPlaceOrder" class="hidden"
3537
data-bind="click: originalPlaceOrder($parents[1])"></button>
3638
</div>

0 commit comments

Comments
 (0)