Skip to content

Commit 624c2d1

Browse files
committed
fix: always set (or reset) inventory on product import with stock changes
1 parent 60c74b7 commit 624c2d1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

functions/lib/integration/imports/products-to-ecom.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module.exports = async ({ appSdk, storeId, auth }, productHorus, opts) => {
9393
const isUpdatePriceOrStock = !opts.queueEntry?.mustUpdateAppQueue && (updatePrice || updateStock)
9494
const isUpdateStock = updateStock && (SALDO_DISPONIVEL >= 0 || SALDO >= 0)
9595

96-
let inventory
96+
const inventory = {}
9797
if (quantity !== product?.quantity && isUpdateStock) {
9898
const { stocks_url: stocksUrl, stocks_token: stocksToken } = opts.appData
9999
if (stocksUrl && stocksToken) {
@@ -114,7 +114,6 @@ module.exports = async ({ appSdk, storeId, auth }, productHorus, opts) => {
114114
})
115115
})
116116
if (res?.data?.produtos?.itensEstoque?.length > 1) {
117-
inventory = {}
118117
quantity = 0
119118
res.data.produtos.itensEstoque.forEach(({ codigoestoque, saldo }) => {
120119
const qnt = parseInt(saldo, 10)
@@ -159,7 +158,7 @@ module.exports = async ({ appSdk, storeId, auth }, productHorus, opts) => {
159158
}
160159
}
161160

162-
if ((quantity !== product.quantity || inventory) && isUpdateStock) {
161+
if ((quantity !== product.quantity || Object.keys(inventory).length) && isUpdateStock) {
163162
body.quantity = quantity
164163
body.inventory = inventory
165164
}

0 commit comments

Comments
 (0)