Skip to content

Commit c5d2e3d

Browse files
author
Michael Yu
committed
MAGETWO-69657: Credit Card Information disappear after user enters promotion code
- Remove requiring utils - Pull getGrandTotal out as a private function - Switch bracket notation back to dot notation and allow jscs ignore - Swap Underscore negate method for reject method for readability - Replace deep clone of allMethods with a shallow clone for space efficiency
1 parent 3a72654 commit c5d2e3d

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

app/code/Magento/Checkout/view/frontend/web/js/model/payment-service.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ define([
77
'underscore',
88
'Magento_Checkout/js/model/quote',
99
'Magento_Checkout/js/model/payment/method-list',
10-
'Magento_Checkout/js/action/select-payment-method',
11-
'mage/utils/objects'
12-
], function (_, quote, methodList, selectPaymentMethod, utils) {
10+
'Magento_Checkout/js/action/select-payment-method'
11+
], function (_, quote, methodList, selectPaymentMethod) {
1312
'use strict';
1413

1514
/**
@@ -18,8 +17,16 @@ define([
1817
* @returns boolean
1918
*/
2019
var isFreePaymentMethod = function (paymentMethod) {
21-
return paymentMethod.method === 'free';
22-
};
20+
return paymentMethod.method === 'free';
21+
},
22+
23+
/**
24+
* Grabs the grand total from quote
25+
* @returns number
26+
*/
27+
getGrandTotal = function () {
28+
return quote.totals().grand_total; // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
29+
};
2330

2431
return {
2532
isFreeAvailable: false,
@@ -37,7 +44,7 @@ define([
3744
freeMethod = _.find(methods, isFreePaymentMethod);
3845
this.isFreeAvailable = !!freeMethod;
3946

40-
if (freeMethod && quote.totals()['grand_total'] <= 0) {
47+
if (freeMethod && getGrandTotal() <= 0) {
4148
methods.splice(0, methods.length, freeMethod);
4249
selectPaymentMethod(freeMethod);
4350
}
@@ -77,15 +84,15 @@ define([
7784
* @returns {Array}
7885
*/
7986
getAvailablePaymentMethods: function () {
80-
var allMethods = utils.copy(methodList()),
81-
grandTotalOverZero = quote.totals()['grand_total'] > 0;
87+
var allMethods = methodList().slice(),
88+
grandTotalOverZero = getGrandTotal() > 0;
8289

8390
if (!this.isFreeAvailable) {
8491
return allMethods;
8592
}
8693

8794
if (grandTotalOverZero) {
88-
return _.filter(allMethods, _.negate(isFreePaymentMethod));
95+
return _.reject(allMethods, isFreePaymentMethod);
8996
}
9097

9198
return _.filter(allMethods, isFreePaymentMethod);

0 commit comments

Comments
 (0)