Skip to content

Commit 6f950e8

Browse files
committed
fix: properly parsing prices from tiny on product import
1 parent 4e24226 commit 6f950e8

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

functions/lib/integration/parsers/product-to-ecomplus.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,26 @@ module.exports = async (tinyProduct, storeId, auth, isNew = true, tipo, appData)
7676
const sku = tinyProduct.codigo || String(tinyProduct.id)
7777
const name = (tinyProduct.nome || sku).trim()
7878
const isProduct = tipo === 'produto'
79-
const getCorrectPrice = (price) => {
80-
return Number(price) > 0 ? Number(price) : null
79+
const fixTinyPrice = (price) => {
80+
return Number(price) > 0 ? Number(price) : 0
8181
}
82-
const price = !isProduct ? Number(tinyProduct.preco_promocional || tinyProduct.preco) : Number(getCorrectPrice(tinyProduct.precoPromocional) || tinyProduct.preco)
82+
const price = fixTinyPrice(tinyProduct.preco_promocional || tinyProduct.precoPromocional) ||
83+
fixTinyPrice(tinyProduct.preco)
8384
const product = {
8485
available: tinyProduct.situacao === 'A',
8586
sku,
8687
name,
87-
cost_price: !isProduct ? Number(tinyProduct.preco_custo) : Number(tinyProduct.precoCusto),
8888
price,
8989
base_price: Number(tinyProduct.preco),
9090
body_html: tinyProduct.descricao_complementar || tinyProduct.descricaoComplementar
9191
}
92-
92+
const costPrice = fixTinyPrice(tinyProduct.preco_custo || tinyProduct.precoCusto)
93+
if (costPrice) {
94+
product.cost_price = costPrice
95+
}
9396
if (appData && appData.disable_price && !isNew && !isProduct) {
9497
delete product.price
9598
}
96-
9799
if (tinyProduct.estoqueAtual) {
98100
product.quantity = tinyProduct.estoqueAtual
99101
}

0 commit comments

Comments
 (0)