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

@@ -1,5 +1,6 @@
import { WorkflowArguments } from "@medusajs/workflows-sdk"
import { promiseAll } from "@medusajs/utils"
import { MedusaV2Flag, promiseAll } from "@medusajs/utils"
import { Modules } from "@medusajs/modules-sdk"
type ProductHandle = string
type SalesChannelId = string
@@ -17,6 +18,8 @@ export async function attachSalesChannelToProducts({
data,
}: WorkflowArguments<HandlerInput>): Promise<void> {
const { manager } = context
const featureFlagRouter = container.resolve("featureFlagRouter")
const productsHandleSalesChannelsMap = data.productsHandleSalesChannelsMap
const products = data.products
@@ -35,16 +38,41 @@ export async function attachSalesChannelToProducts({
}
})
await promiseAll(
Array.from(salesChannelIdProductIdsMap.entries()).map(
async ([salesChannelId, productIds]) => {
return await salesChannelServiceTx.addProducts(
salesChannelId,
productIds
)
}
if (featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)) {
const remoteLink = container.resolve("remoteLink")
const links: any[] = []
for (const [
salesChannelId,
productIds,
] of salesChannelIdProductIdsMap.entries()) {
productIds.forEach((id) =>
links.push({
[Modules.PRODUCT]: {
product_id: id,
},
salesChannelService: {
sales_channel_id: salesChannelId,
},
})
)
await remoteLink.create(links)
}
return
} else {
await promiseAll(
Array.from(salesChannelIdProductIdsMap.entries()).map(
async ([salesChannelId, productIds]) => {
return await salesChannelServiceTx.addProducts(
salesChannelId,
productIds
)
}
)
)
)
}
}
attachSalesChannelToProducts.aliases = {

View File

@@ -1,5 +1,6 @@
import { WorkflowArguments } from "@medusajs/workflows-sdk"
import { promiseAll } from "@medusajs/utils"
import { MedusaV2Flag, promiseAll } from "@medusajs/utils"
import { Modules } from "@medusajs/modules-sdk"
type ProductHandle = string
type SalesChannelId = string
@@ -15,6 +16,8 @@ export async function detachSalesChannelFromProducts({
data,
}: WorkflowArguments<HandlerInput>): Promise<void> {
const { manager } = context
const featureFlagRouter = container.resolve("featureFlagRouter")
const productsHandleSalesChannelsMap = data.productsHandleSalesChannelsMap
const products = data.products
@@ -33,16 +36,41 @@ export async function detachSalesChannelFromProducts({
}
})
await promiseAll(
Array.from(salesChannelIdProductIdsMap.entries()).map(
async ([salesChannelId, productIds]) => {
return await salesChannelServiceTx.removeProducts(
salesChannelId,
productIds
if (featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)) {
const remoteLink = container.resolve("remoteLink")
const promises: Promise<unknown>[] = []
for (const [
salesChannelId,
productIds,
] of salesChannelIdProductIdsMap.entries()) {
productIds.forEach((id) =>
promises.push(
remoteLink.dismiss({
[Modules.PRODUCT]: {
product_id: id,
},
salesChannelService: {
sales_channel_id: salesChannelId,
},
})
)
}
)
}
return
} else {
await promiseAll(
Array.from(salesChannelIdProductIdsMap.entries()).map(
async ([salesChannelId, productIds]) => {
return await salesChannelServiceTx.removeProducts(
salesChannelId,
productIds
)
}
)
)
)
}
}
detachSalesChannelFromProducts.aliases = {