feat(medusa, link-modules): sales channel <> product module link (#5450)

* feat: sales channel joiner config

* feat: product sales channel link config, SC list method

* feat: migration

* fix: refactor list SC

* refactor: SC repo api

* chore: changeset

* feat: add dedicated FF

* feat: product<> sc join entity

* fix: update case

* fix: add FF on in the repository, fix tests

* fix: assign id when FF is on

* fix: target table

* feat: product service - fetch SC with RQ

* feat: admin list products & SC with isolated product domain

* feat: get admin product

* feat: store endpoints

* fix: remove duplicate import

* fix: remove "name" prop

* feat: refactor

* fix: product seeder if FF is on

* fix: env

* refactor: workflow product handlers to handle remote links

* fix: condition

* fix: use correct method

* fix: build

* wip: update FF

* fix: update FF in the handlers

* chore: migrate to medusav2 FF

* chore: uncomment test

* fix: product factory

* fix: unlinking SC and product

* fix: use module name variable

* refactor: cleanup query definitions

* fix: add constraint

* chore: rename prop

* fix: add hook

* fix: address comments

* fix: temp sc filtering

* fix: use RQ to filter by SC

* fix: add sc to filter to list

---------

Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
Frane Polić
2023-12-15 13:43:00 +01:00
committed by GitHub
parent 11b1a61969
commit 1d7888afca
24 changed files with 603 additions and 88 deletions

View File

@@ -68,15 +68,13 @@ export default async (req, res) => {
const productService: ProductService = req.scope.resolve("productService")
const pricingService: PricingService = req.scope.resolve("pricingService")
const featureFlagRouter = req.scope.resolve("featureFlagRouter")
const isMedusaV2FlagOn = featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)
const productVariantInventoryService: ProductVariantInventoryService =
req.scope.resolve("productVariantInventoryService")
const salesChannelService: SalesChannelService = req.scope.resolve(
"salesChannelService"
)
let rawProduct
if (featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)) {
if (isMedusaV2FlagOn) {
rawProduct = await retrieveProduct(
req.scope,
id,
@@ -102,15 +100,30 @@ export default async (req, res) => {
req.retrieveConfig.relations?.includes("variants")
if (shouldSetAvailability) {
const [salesChannelsIds] = await salesChannelService.listAndCount(
{},
{ select: ["id"] }
)
let salesChannels
if (isMedusaV2FlagOn) {
const remoteQuery = req.scope.resolve("remoteQuery")
const query = {
sales_channel: {
fields: ["id"],
},
}
salesChannels = await remoteQuery(query)
} else {
const salesChannelService: SalesChannelService = req.scope.resolve(
"salesChannelService"
)
;[salesChannels] = await salesChannelService.listAndCount(
{},
{ select: ["id"] }
)
}
decoratePromises.push(
productVariantInventoryService.setProductAvailability(
[product],
salesChannelsIds.map((salesChannel) => salesChannel.id)
salesChannels.map((salesChannel) => salesChannel.id)
)
)
}

View File

@@ -238,6 +238,18 @@ export const defaultAdminProductRemoteQueryObject = {
profile: {
fields: ["id", "created_at", "updated_at", "deleted_at", "name", "type"],
},
sales_channels: {
fields: [
"id",
"name",
"description",
"is_disabled",
"created_at",
"updated_at",
"deleted_at",
"metadata",
],
},
}
/**

View File

@@ -198,6 +198,18 @@ export const defaultStoreProductRemoteQueryObject = {
profile: {
fields: ["id", "created_at", "updated_at", "deleted_at", "name", "type"],
},
sales_channels: {
fields: [
"id",
"name",
"description",
"is_disabled",
"created_at",
"updated_at",
"deleted_at",
"metadata",
],
},
}
export * from "./list-products"

View File

@@ -399,6 +399,10 @@ async function listAndCountProductWithIsolatedProductModule(
},
}
if (salesChannelIdFilter) {
query.product["sales_channels"]["__args"] = { id: salesChannelIdFilter }
}
const {
rows: products,
metadata: { count },