Skip to content

Commit c61265a

Browse files
committed
feat(multi-cd): handle multiple doc numbers for each branch by cd
1 parent 9a9e908 commit c61265a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

functions/ecom.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ const app = {
271271
title: 'Datafrete token',
272272
description: 'Token para REST API do Datafrete na filial do respectivo CD'
273273
},
274+
datafrete_doc: {
275+
type: 'string',
276+
maxLength: 255,
277+
title: 'Documento da filial',
278+
description: 'CNPJ da filial associado à sua conta Datafrete'
279+
},
274280
zip: {
275281
type: 'string',
276282
maxLength: 9,

functions/routes/ecom/modules/calculate-shipping.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ exports.post = ({ appSdk }, req, res) => {
1717
// merge all app options configured by merchant
1818
const appData = Object.assign({}, application.data, application.hidden_data)
1919

20+
let docNumber = appData.datafrete_doc
2021
let token = appData.datafrete_token
21-
if (!appData.datafrete_doc || !token) {
22+
if (!docNumber || !token) {
2223
// must have configured Datafrete doc number and token
2324
return res.status(409).send({
2425
error: 'CALCULATE_AUTH_ERR',
@@ -59,6 +60,9 @@ exports.post = ({ appSdk }, req, res) => {
5960
continue
6061
}
6162
originZip = warehouse.zip
63+
if (warehouse.datafrete_doc) {
64+
docNumber = warehouse.datafrete_doc
65+
}
6266
if (warehouse.datafrete_token) {
6367
token = warehouse.datafrete_token
6468
}
@@ -112,7 +116,7 @@ exports.post = ({ appSdk }, req, res) => {
112116
cepOrigem: originZip,
113117
cepDestino: destinationZip,
114118
infComp: {
115-
doc_empresa: appData.datafrete_doc,
119+
doc_empresa: docNumber,
116120
plataforma: 'ECOM'
117121
},
118122

0 commit comments

Comments
 (0)