Skip to content

Commit 87b2efa

Browse files
committed
Fixed undefined error
1 parent 1ed9cc5 commit 87b2efa

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

view/frontend/web/js/model/checkout-data-resolver.js

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ define([
1818
var resolveShippingRates = wrapper.wrap(
1919
checkoutDataResolver.resolveShippingRates,
2020
function (originalResolveShippingRates, ratesData) {
21-
if (!checkoutData.getSelectedShippingRate()
22-
&& !_.isUndefined(config.hsDefaultShippingPayment.shipping)
23-
&& _.size(ratesData) > 1
24-
) {
21+
if (!checkoutData.getSelectedShippingRate() && _.size(ratesData) > 1) {
2522
var method = this.getMethod('shipping', ratesData);
2623
if (!_.isUndefined(method)) {
2724
selectShippingMethodAction(method);
@@ -40,10 +37,7 @@ define([
4037
checkoutDataResolver.resolvePaymentMethod,
4138
function (originalResolvePaymentMethod) {
4239
var availablePaymentMethods = paymentService.getAvailablePaymentMethods();
43-
if (!checkoutData.getSelectedPaymentMethod()
44-
&& !_.isUndefined(config.hsDefaultShippingPayment.payment)
45-
&& _.size(availablePaymentMethods) > 1
46-
) {
40+
if (!checkoutData.getSelectedPaymentMethod() && _.size(availablePaymentMethods) > 1) {
4741
var method = this.getMethod('payment', availablePaymentMethods);
4842
if (!_.isUndefined(method)) {
4943
selectPaymentMethodAction(method);
@@ -65,7 +59,7 @@ define([
6559
* @return {Object|undefined}
6660
*/
6761
getMethod: function (type, availableMethods) {
68-
var autoselectMethod = this.getAutoselectMethod(type),
62+
var autoselectMethod = this.getMethodBySelectionType(type, 'autoselect'),
6963
self = this;
7064
var matchedMethod;
7165
if (!_.isUndefined(autoselectMethod)) {
@@ -75,7 +69,7 @@ define([
7569
}
7670

7771
if (!matchedMethod) {
78-
var fallbackMethod = this.getFallbackMethod(type);
72+
var fallbackMethod = this.getMethodBySelectionType(type, 'fallback');
7973
if (fallbackMethod === 'first') {
8074
matchedMethod = availableMethods[0];
8175
} else if (fallbackMethod === 'last') {
@@ -96,20 +90,14 @@ define([
9690
* @param {String} type
9791
* @return {String}
9892
*/
99-
getAutoselectMethod: function (type) {
100-
return config.hsDefaultShippingPayment[type].autoselect;
101-
},
102-
103-
/**
104-
* Get fallback method by type
105-
*
106-
* @param {String} type
107-
* @return {String}
108-
*/
109-
getFallbackMethod: function (type) {
110-
return config.hsDefaultShippingPayment[type].fallback;
93+
getMethodBySelectionType: function (methodType, selectionType) {
94+
if (!_.isUndefined(config.hsDefaultShippingPayment)
95+
&& !_.isUndefined(config.hsDefaultShippingPayment[methodType])
96+
) {
97+
return config.hsDefaultShippingPayment[methodType][selectionType];
98+
}
11199
},
112-
100+
113101
/**
114102
* Get method code
115103
*

0 commit comments

Comments
 (0)