Skip to content

Commit

Permalink
fix: multiply each item price by amount discount/subtotal factor
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 authored May 27, 2023
1 parent 560429f commit dbfff7e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion functions/routes/ecom/modules/calculate-shipping.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ exports.post = ({ appSdk }, req, res) => {
}

if (params.items) {
let discountFactor = 0
const { amount } = params
if (amount && amount.discount && amount.subtotal) {
discountFactor = amount.discount / amount.subtotal
}

// send POST request to Datafrete REST API
const calcParams = {
token,
Expand Down Expand Up @@ -153,14 +159,15 @@ exports.post = ({ appSdk }, req, res) => {
}
}
}
const price = ecomUtils.price(item)
return {
sku,
descricao: name,
altura: cmDimensions.height || 0,
largura: cmDimensions.width || 0,
comprimento: cmDimensions.length || 0,
peso: kgWeight,
preco: ecomUtils.price(item),
preco: parseInt((price - discountFactor * price) * 100, 10) / 100,
qtd: quantity,
volume: 0
}
Expand Down

0 comments on commit dbfff7e

Please sign in to comment.