@@ -23,11 +23,19 @@ module.exports = appSdk => {
23
23
}
24
24
25
25
const destinationZip = params . to ? params . to . zip . replace ( / \D / g, '' ) : ''
26
- const checkZipCode = rule => {
27
- // validate rule zip range
26
+ const checkZipCode = ( rule ) => {
28
27
if ( destinationZip && rule . zip_range ) {
29
28
const { min, max } = rule . zip_range
30
- return Boolean ( ( ! min || destinationZip >= min ) && ( ! max || destinationZip <= max ) )
29
+ if ( ! min && ! max ) {
30
+ return true
31
+ }
32
+ if ( ! max ) {
33
+ return destinationZip === min
34
+ }
35
+ if ( ! min ) {
36
+ return destinationZip === max
37
+ }
38
+ return destinationZip >= min && destinationZip <= max
31
39
}
32
40
return true
33
41
}
@@ -196,8 +204,15 @@ module.exports = appSdk => {
196
204
if ( validShippingRules . length ) {
197
205
// group by service code selecting lower price
198
206
const shippingRulesByCode = validShippingRules . reduce ( ( shippingRulesByCode , rule ) => {
207
+ const serviceCode = rule . service_code
199
208
if ( typeof rule . total_price !== 'number' ) {
200
- rule . total_price = 0
209
+ let service
210
+ if ( Array . isArray ( config . services ) ) {
211
+ service = config . services . find ( ( _service ) => {
212
+ return _service && _service . service_code === serviceCode
213
+ } )
214
+ }
215
+ rule . total_price = ( service && service . total_price ) || 0
201
216
}
202
217
if ( typeof rule . price !== 'number' ) {
203
218
rule . price = rule . total_price
@@ -208,7 +223,6 @@ module.exports = appSdk => {
208
223
if ( typeof rule . amount_tax === 'number' && ! isNaN ( rule . amount_tax ) ) {
209
224
rule . total_price += ( rule . amount_tax * amount / 100 )
210
225
}
211
- const serviceCode = rule . service_code
212
226
const currentShippingRule = shippingRulesByCode [ serviceCode ]
213
227
if ( ! currentShippingRule || currentShippingRule . total_price > rule . total_price ) {
214
228
shippingRulesByCode [ serviceCode ] = rule
@@ -236,8 +250,15 @@ module.exports = appSdk => {
236
250
service = config . services . find ( service => {
237
251
return service && service . service_code === serviceCode
238
252
} )
239
- if ( service && ! label ) {
240
- label = service . label
253
+ if ( service ) {
254
+ if ( ! label ) {
255
+ label = service . label
256
+ }
257
+ if ( ! rule . delivery_time || typeof rule . delivery_time . days !== 'number' ) {
258
+ rule . delivery_time = service . delivery_time
259
+ }
260
+ delete service . delivery_time
261
+ delete service . total_price
241
262
}
242
263
}
243
264
if ( ! label ) {
0 commit comments