@@ -23,11 +23,19 @@ module.exports = appSdk => {
2323 }
2424
2525 const destinationZip = params . to ? params . to . zip . replace ( / \D / g, '' ) : ''
26- const checkZipCode = rule => {
27- // validate rule zip range
26+ const checkZipCode = ( rule ) => {
2827 if ( destinationZip && rule . zip_range ) {
2928 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
3139 }
3240 return true
3341 }
@@ -196,8 +204,15 @@ module.exports = appSdk => {
196204 if ( validShippingRules . length ) {
197205 // group by service code selecting lower price
198206 const shippingRulesByCode = validShippingRules . reduce ( ( shippingRulesByCode , rule ) => {
207+ const serviceCode = rule . service_code
199208 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
201216 }
202217 if ( typeof rule . price !== 'number' ) {
203218 rule . price = rule . total_price
@@ -208,7 +223,6 @@ module.exports = appSdk => {
208223 if ( typeof rule . amount_tax === 'number' && ! isNaN ( rule . amount_tax ) ) {
209224 rule . total_price += ( rule . amount_tax * amount / 100 )
210225 }
211- const serviceCode = rule . service_code
212226 const currentShippingRule = shippingRulesByCode [ serviceCode ]
213227 if ( ! currentShippingRule || currentShippingRule . total_price > rule . total_price ) {
214228 shippingRulesByCode [ serviceCode ] = rule
@@ -236,8 +250,15 @@ module.exports = appSdk => {
236250 service = config . services . find ( service => {
237251 return service && service . service_code === serviceCode
238252 } )
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
241262 }
242263 }
243264 if ( ! label ) {
0 commit comments