From a512a8c19c34d0050259e5faed215449fcabe08b Mon Sep 17 00:00:00 2001 From: Alex Luker Date: Thu, 1 Aug 2024 18:22:39 +0100 Subject: [PATCH] fix continue selling --- web/connector/productUtils.js | 2 +- web/connector/productUtils.test.js | 2 +- .../use-cases/updateExistingProducts.js | 62 +++++++++---------- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/web/connector/productUtils.js b/web/connector/productUtils.js index cfb04e9..7a08d55 100644 --- a/web/connector/productUtils.js +++ b/web/connector/productUtils.js @@ -73,7 +73,7 @@ async function getSingleVariantSuppliedProduct(suppliedProduct) { sku, taxable: hasVat, tracked: true, - inventoryPolicy: isContinueSelling ? 'continue' : 'deny' + inventoryPolicy: isContinueSelling ? 'CONTINUE' : 'DENY' }; if (images.length) { diff --git a/web/connector/productUtils.test.js b/web/connector/productUtils.test.js index 9d75cdb..02dcca6 100644 --- a/web/connector/productUtils.test.js +++ b/web/connector/productUtils.test.js @@ -23,7 +23,7 @@ describe('generateShopifyFDCProducts', () => { const variant = result[0].parentProduct.variants[0]; expect(variant.inventoryQuantity).toEqual(0); - expect(variant.inventoryPolicy).toEqual('continue'); + expect(variant.inventoryPolicy).toEqual('CONTINUE'); }); it('Can import single products that dont appear on transformations', async () => { diff --git a/web/modules/sales-session/use-cases/updateExistingProducts.js b/web/modules/sales-session/use-cases/updateExistingProducts.js index 3c5b08b..c0fb749 100644 --- a/web/modules/sales-session/use-cases/updateExistingProducts.js +++ b/web/modules/sales-session/use-cases/updateExistingProducts.js @@ -80,45 +80,41 @@ const updateExistingProductsUseCase = async ({ userId, shouldUpdateThePrice = false }) => { - try { - const sessionId = shopify.api.session.getOfflineId(HUB_SHOP_NAME); + const sessionId = shopify.api.session.getOfflineId(HUB_SHOP_NAME); - const session = await shopify.config.sessionStorage.loadSession(sessionId); + const session = await shopify.config.sessionStorage.loadSession(sessionId); - if (!session) { - throwError( - 'Error from updateExistingProductsUseCase: Shopify Session not found' - ); - } - const gqlClient = new shopify.api.clients.Graphql({ session }); + if (!session) { + throwError( + 'Error from updateExistingProductsUseCase: Shopify Session not found' + ); + } + const gqlClient = new shopify.api.clients.Graphql({ session }); - const { accessToken } = await obtainValidAccessToken(userId); - const productsWithVariants = await getProducerProducts(accessToken); + const { accessToken } = await obtainValidAccessToken(userId); + const productsWithVariants = await getProducerProducts(accessToken); - if (productsWithVariants.length === 0) { - return; - } + if (productsWithVariants.length === 0) { + return; + } - for (const product of productsWithVariants) { - const { hubProductId, producerProductData } = product; - const storedVariants = product.variants; - - if (producerProductData) { - await updateSingleProduct({ - gqlClient, - hubProductId, - session, - storedVariants, - producerLatestProductData: producerProductData, - shouldUpdateThePrice, - accessToken - }); - } else { - await archiveProduct({ hubProductId, gqlClient }); - } + for (const product of productsWithVariants) { + const { hubProductId, producerProductData } = product; + const storedVariants = product.variants; + + if (producerProductData) { + await updateSingleProduct({ + gqlClient, + hubProductId, + session, + storedVariants, + producerLatestProductData: producerProductData, + shouldUpdateThePrice, + accessToken + }); + } else { + await archiveProduct({ hubProductId, gqlClient }); } - } catch (e) { - throwError('Error from updateExistingProductsUseCase', e); } };