Skip to content

Commit dbfff7e

Browse files
authored
fix: multiply each item price by amount discount/subtotal factor
1 parent 560429f commit dbfff7e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ exports.post = ({ appSdk }, req, res) => {
109109
}
110110

111111
if (params.items) {
112+
let discountFactor = 0
113+
const { amount } = params
114+
if (amount && amount.discount && amount.subtotal) {
115+
discountFactor = amount.discount / amount.subtotal
116+
}
117+
112118
// send POST request to Datafrete REST API
113119
const calcParams = {
114120
token,
@@ -153,14 +159,15 @@ exports.post = ({ appSdk }, req, res) => {
153159
}
154160
}
155161
}
162+
const price = ecomUtils.price(item)
156163
return {
157164
sku,
158165
descricao: name,
159166
altura: cmDimensions.height || 0,
160167
largura: cmDimensions.width || 0,
161168
comprimento: cmDimensions.length || 0,
162169
peso: kgWeight,
163-
preco: ecomUtils.price(item),
170+
preco: parseInt((price - discountFactor * price) * 100, 10) / 100,
164171
qtd: quantity,
165172
volume: 0
166173
}

0 commit comments

Comments
 (0)