fix(medusa): Creating Product with Sales Channels disabled (#3357)

This commit is contained in:
Riqwan Thamir
2023-03-02 11:59:10 +01:00
committed by GitHub
parent 4e59129a31
commit c432481319
4 changed files with 87 additions and 4 deletions
@@ -42,6 +42,7 @@ import {
} from "./transaction/create-product-variant"
import { DistributedTransaction } from "../../../../utils/transaction"
import { Logger } from "../../../../types/global"
import { FlagRouter } from "../../../../utils/flag-router"
/**
* @oas [post] /products
@@ -117,6 +118,8 @@ export default async (req, res) => {
const shippingProfileService: ShippingProfileService = req.scope.resolve(
"shippingProfileService"
)
const featureFlagRouter: FlagRouter = req.scope.resolve("featureFlagRouter")
const productVariantInventoryService: ProductVariantInventoryService =
req.scope.resolve("productVariantInventoryService")
const inventoryService: IInventoryService | undefined =
@@ -148,8 +151,12 @@ export default async (req, res) => {
.retrieveDefault()
}
// If no sales channel available, set the default one
if (!validated?.sales_channels?.length) {
// Provided that the feature flag is enabled and
// no sales channels are available, set the default one
if (
featureFlagRouter.isFeatureEnabled(SalesChannelFeatureFlag.key) &&
!validated?.sales_channels?.length
) {
const defaultSalesChannel = await salesChannelService
.withTransaction(manager)
.retrieveDefault()