Skip to content

Commit 6f7cf07

Browse files
author
Stanislav Idolov
authored
ENGCOM-3219: #17744 Adding logic to get default billing address used on Cart and Checkout #18095
2 parents c993833 + 4187613 commit 6f7cf07

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,31 @@ define([
218218
* Apply resolved billing address to quote
219219
*/
220220
applyBillingAddress: function () {
221-
var shippingAddress;
221+
var shippingAddress,
222+
isBillingAddressInitialized;
222223

223224
if (quote.billingAddress()) {
224225
selectBillingAddress(quote.billingAddress());
225226

226227
return;
227228
}
229+
230+
if (quote.isVirtual()) {
231+
isBillingAddressInitialized = addressList.some(function (addrs) {
232+
if (addrs.isDefaultBilling()) {
233+
selectBillingAddress(addrs);
234+
235+
return true;
236+
}
237+
238+
return false;
239+
});
240+
}
241+
228242
shippingAddress = quote.shippingAddress();
229243

230-
if (shippingAddress &&
244+
if (!isBillingAddressInitialized &&
245+
shippingAddress &&
231246
shippingAddress.canUseForBilling() &&
232247
(shippingAddress.isDefaultShipping() || !quote.isVirtual())
233248
) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ define([
1919
billingAddress: ko.observable(),
2020
shippingAddress: ko.observable(),
2121
paymentMethod: ko.observable(),
22-
totals: ko.observable({})
22+
totals: ko.observable({}),
23+
24+
/** Stub */
25+
isVirtual: function () {
26+
return false;
27+
}
2328
},
2429
'Magento_Braintree/js/view/payment/validator-handler': jasmine.createSpyObj(
2530
'validator-handler',

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ define([
2424
paymentMethod: ko.observable(),
2525
totals: ko.observable({
2626
'base_grand_total': 0
27-
})
27+
}),
28+
29+
/** Stub */
30+
isVirtual: function () {
31+
return false;
32+
}
2833
},
2934
'Magento_Braintree/js/view/payment/adapter': {
3035
config: {},

dev/tests/js/jasmine/tests/app/code/Magento/Paypal/frontend/js/view/payment/method-renderer/paypal-express-abstract.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ define([
2828
billingAddress: ko.observable(),
2929
shippingAddress: ko.observable(),
3030
paymentMethod: ko.observable(),
31-
totals: ko.observable({})
31+
totals: ko.observable({}),
3232

33+
/** Stub */
34+
isVirtual: function () {
35+
return false;
36+
}
3337
},
3438
'Magento_Checkout/js/action/set-payment-information': setPaymentMock,
3539
'Magento_Checkout/js/model/payment/additional-validators': {

0 commit comments

Comments
 (0)