Skip to content

Commit

Permalink
fix: properly handling max quotes config option
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Sep 27, 2024
1 parent 1ce433a commit 1ff77b6
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions functions/routes/ecom/modules/calculate-shipping.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.post = async ({ appSdk }, req, res) => {
// merge all app options configured by merchant
const appData = Object.assign({}, application.data, application.hidden_data)
const disableShipping = appData.disable_shipping
const maxCotation = appData.max_quote || 0
const maxQuotes = appData.max_quote

let shippingRules
if (Array.isArray(appData.shipping_rules) && appData.shipping_rules.length) {
Expand Down Expand Up @@ -241,6 +241,7 @@ exports.post = async ({ appSdk }, req, res) => {
const orderId = data.response.data.order.id
let lowestPriceShipping
result.forEach((freteClickService, index) => {
if (maxQuotes && index >= maxQuotes) return
const { carrier } = freteClickService
// parse to E-Com Plus shipping line object
const serviceCode = carrier && carrier.id
Expand Down Expand Up @@ -347,23 +348,13 @@ exports.post = async ({ appSdk }, req, res) => {
}

const serviceCodeName = shippingName.replaceAll(' ', '_').toLowerCase()
if (maxCotation && maxCotation > index) {
response.shipping_services.push({
label,
carrier: freteClickService.name,
service_name: serviceCodeName || shippingName,
service_code: serviceCode,
shipping_line: shippingLine
})
} else {
response.shipping_services.push({
label,
carrier: freteClickService.name,
service_name: serviceCodeName || shippingName,
service_code: serviceCode,
shipping_line: shippingLine
})
}
response.shipping_services.push({
label,
carrier: freteClickService.name,
service_name: serviceCodeName || shippingName,
service_code: serviceCode,
shipping_line: shippingLine
})
})

if (lowestPriceShipping) {
Expand Down

0 comments on commit 1ff77b6

Please sign in to comment.