2
2
* Copyright © 2015 Magento. All rights reserved.
3
3
* See COPYING.txt for license details.
4
4
*/
5
- /*jshint browser:true jquery:true*/
6
- /*global alert*/
5
+ /*global define*/
7
6
define (
8
7
[ 'ko' , 'jquery' ] ,
9
8
function ( ko , $ ) {
9
+ "use strict" ;
10
10
var rates = ko . observable ( [ ] ) ;
11
11
return {
12
12
shippingRates : ko . observableArray ( [ ] ) ,
@@ -30,29 +30,34 @@ define(
30
30
return this . shippingRates ;
31
31
} ,
32
32
getTitleByCode : function ( methodCodeParts ) {
33
- var shippingMethodTitle = '' ;
34
- if ( methodCodeParts ) {
35
- $ . each ( rates ( ) , function ( key , entity ) {
36
- if ( entity [ 'carrier_code' ] == methodCodeParts [ 0 ]
37
- && entity [ 'method_code' ] == methodCodeParts [ 1 ] ) {
38
- shippingMethodTitle = entity [ 'carrier_title' ] + " - " + entity [ 'method_title' ] ;
39
- }
40
- } ) ;
33
+ var shippingMethodTitle = '' , shippingMethodCode , carrierCode , methodCode ;
34
+ if ( ! methodCodeParts ) {
35
+ return shippingMethodTitle ;
41
36
}
37
+ shippingMethodCode = methodCodeParts . slice ( 0 ) ;
38
+ carrierCode = shippingMethodCode . shift ( ) ;
39
+ methodCode = shippingMethodCode . join ( '_' ) ;
40
+ $ . each ( rates ( ) , function ( key , entity ) {
41
+ if ( entity [ 'carrier_code' ] === carrierCode && entity [ 'method_code' ] === methodCode ) {
42
+ shippingMethodTitle = entity [ 'carrier_title' ] + " - " + entity [ 'method_title' ] ;
43
+ }
44
+ } ) ;
42
45
return shippingMethodTitle ;
43
46
} ,
44
47
getRateByCode : function ( methodCodeParts ) {
45
- var shippingRates = [ ] ;
48
+ var shippingRates = [ ] ,
49
+ shippingMethodCode = methodCodeParts . slice ( 0 ) ,
50
+ carrierCode = shippingMethodCode . shift ( ) ,
51
+ methodCode = shippingMethodCode . join ( '_' ) ;
46
52
if ( methodCodeParts ) {
47
53
$ . each ( rates ( ) , function ( key , entity ) {
48
- if ( entity [ 'carrier_code' ] == methodCodeParts [ 0 ]
49
- && entity [ 'method_code' ] == methodCodeParts [ 1 ] ) {
54
+ if ( entity [ 'carrier_code' ] === carrierCode && entity [ 'method_code' ] === methodCode ) {
50
55
shippingRates . push ( entity ) ;
51
56
}
52
57
} ) ;
53
58
}
54
59
return shippingRates ;
55
60
}
56
- }
61
+ } ;
57
62
}
58
63
) ;
0 commit comments