From 992ef733f41a62a19f79af29cb8dae0657880b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frane=20Poli=C4=87?= <16856471+fPolic@users.noreply.github.com> Date: Wed, 14 Sep 2022 09:53:23 +0200 Subject: [PATCH] fix(medusa): Check for Sales Channel on product import (#2202) --- .../src/strategies/batch-jobs/product/import.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/medusa/src/strategies/batch-jobs/product/import.ts b/packages/medusa/src/strategies/batch-jobs/product/import.ts index f5d4cf5ba3..f68dd4d787 100644 --- a/packages/medusa/src/strategies/batch-jobs/product/import.ts +++ b/packages/medusa/src/strategies/batch-jobs/product/import.ts @@ -341,12 +341,18 @@ class ProductImportStrategy extends AbstractBatchJobStrategy { } if (!channel) { - channel = (await salesChannelServiceTx.retrieveByName(input.name, { - select: ["id"], - })) as SalesChannel + try { + channel = (await salesChannelServiceTx.retrieveByName(input.name, { + select: ["id"], + })) as SalesChannel + } catch (e) { + // noop + } } - salesChannels.push(channel) + if (channel) { + salesChannels.push(channel) + } } return salesChannels @@ -382,7 +388,7 @@ class ProductImportStrategy extends AbstractBatchJobStrategy { ) as unknown as CreateProductInput try { - if (isSalesChannelsFeatureOn) { + if (isSalesChannelsFeatureOn && productOp["product.sales_channels"]) { productData["sales_channels"] = await this.processSalesChannels( productOp["product.sales_channels"] as Pick< SalesChannel,