Skip to content

Commit

Permalink
fix(import-products): fix stoke with variation product
Browse files Browse the repository at this point in the history
  • Loading branch information
wisley7l committed Sep 30, 2024
1 parent 7285833 commit 6047df7
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions functions/lib/integration/import-product.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@ const createUpdateProduct = async ({ appSdk, storeId, auth }, appData, sku, prod
}
blingItems.forEach(blingItem => {
if (Array.isArray(blingItem.depositos)) {
const deposit = blingItem.depositos.find((deposito) => String(deposito.id) === String(blingDeposit)) || blingItem.depositos[0]
if (deposit) {
let quantity
const depositFind = blingItem.depositos.find((deposito) => String(deposito.id) === String(blingDeposit))
const deposits = depositFind ? [depositFind] : blingItem.depositos
let quantity = 0
deposits.forEach(deposit => {
if (Number(storeId) === 51292 || appData.has_stock_reserve) {
quantity = Number(deposit.saldoVirtual)
quantity += !Number.isNaN(Number(deposit.saldoVirtual)) ? Number(deposit.saldoVirtual) : 0
} else {
quantity = Number(deposit.saldoFisico)
quantity += !Number.isNaN(Number(deposit.saldoFisico)) ? Number(deposit.saldoFisico) : 0
}
if (!isNaN(quantity)) {
blingItem.estoqueAtual = quantity
delete blingItem.depositos
}
}
})

blingItem.estoqueAtual = quantity
delete blingItem.depositos
}
})

const blingProductFind = !variationId ? blingProduct : blingItems.find(item => item.codigo === sku)
let quantity = Number(blingProductFind.estoqueAtual)

logger.info(`> BlingProduct: ${JSON.stringify(blingProduct)}`)

if (product && (isStockOnly === true || !appData.update_product || variationId)) {
if (!isNaN(quantity)) {
if (quantity < 0) {
Expand Down Expand Up @@ -79,7 +81,7 @@ const createUpdateProduct = async ({ appSdk, storeId, auth }, appData, sku, prod
value: `${blingProduct.id}`
})
}
logger.info(`#${storeId} ${method} ${endpoint} ${JSON.stringify(bodyProduct)}`)
logger.info(`#${storeId} ${method} ${endpoint}`)

return appSdk.apiRequest(storeId, endpoint, method, bodyProduct, auth)
})
Expand Down

0 comments on commit 6047df7

Please sign in to comment.