Skip to content

Commit

Permalink
fix continue selling
Browse files Browse the repository at this point in the history
  • Loading branch information
ajluker committed Aug 1, 2024
1 parent 4ab6280 commit a512a8c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 35 deletions.
2 changes: 1 addition & 1 deletion web/connector/productUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async function getSingleVariantSuppliedProduct(suppliedProduct) {
sku,
taxable: hasVat,
tracked: true,
inventoryPolicy: isContinueSelling ? 'continue' : 'deny'
inventoryPolicy: isContinueSelling ? 'CONTINUE' : 'DENY'
};

if (images.length) {
Expand Down
2 changes: 1 addition & 1 deletion web/connector/productUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
62 changes: 29 additions & 33 deletions web/modules/sales-session/use-cases/updateExistingProducts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down

0 comments on commit a512a8c

Please sign in to comment.