Skip to content

Commit

Permalink
feat: new optional carrier name and doc config per service
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Sep 8, 2023
1 parent c213bd3 commit 550c925
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
38 changes: 38 additions & 0 deletions functions/ecom.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,44 @@ const app = {
}
},
hide: false
},
carriers: {
schema: {
title: 'Informações das transportadoras',
description: 'Dados adicionais das transportadoras por serviço',
type: 'array',
maxItems: 3,
items: {
title: 'Transportadora',
type: 'object',
minProperties: 1,
properties: {
service: {
type: 'string',
enum: [
'',
'Econômico',
'Rápido',
'Todos'
],
default: '',
title: 'Tipo do serviço'
},
carrier: {
type: 'string',
maxLength: 200,
title: 'Nome da transportadora',
},
carrier_doc_number: {
type: 'string',
maxLength: 19,
pattern: '^[0-9]+$',
title: 'CNPJ da transportadora',
}
}
}
},
hide: true
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions functions/routes/ecom/modules/calculate-shipping.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ exports.post = ({ appSdk }, req, res) => {
totalPrice = 0
}
const discount = shipping.price - totalPrice
response.shipping_services.push({
const shippingLine = {
label: shipping.name,
carrier: shipping.name,
service_name: 'Mandae',
Expand All @@ -241,7 +241,17 @@ exports.post = ({ appSdk }, req, res) => {
}
},
flags: ['mandae-ws']
})
}
if (Array.isArray(appData.carriers)) {
const carrier = appData.carriers.find(({ service }) => {
return service === shipping.name || !service || service === 'Todos'
})
if (carrier) {
shippingLine.carrier = carrier.carrier
shippingLine.carrier_doc_number = carrier.carrier_doc_number
}
}
response.shipping_services.push(shippingLine)
}
}
res.send(response)
Expand Down

0 comments on commit 550c925

Please sign in to comment.