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:
@@ -18,6 +18,7 @@ import {
|
||||
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
|
||||
export type ProductFactoryData = {
|
||||
id?: string
|
||||
@@ -30,6 +31,7 @@ export type ProductFactoryData = {
|
||||
variants?: Omit<ProductVariantFactoryData, "product_id">[]
|
||||
sales_channels?: SalesChannelFactoryData[]
|
||||
metadata?: Record<string, unknown>
|
||||
isMedusaV2Enabled?: boolean
|
||||
}
|
||||
|
||||
export const simpleProductFactory = async (
|
||||
@@ -41,6 +43,9 @@ export const simpleProductFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
data.isMedusaV2Enabled =
|
||||
data.isMedusaV2Enabled ?? process.env.MEDUSA_FF_MEDUSA_V2 == "true"
|
||||
|
||||
const manager = dataSource.manager
|
||||
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
@@ -121,10 +126,27 @@ export const simpleProductFactory = async (
|
||||
|
||||
const toSave = manager.create(Product, productToCreate)
|
||||
|
||||
toSave.sales_channels = sales_channels
|
||||
if (!data.isMedusaV2Enabled) {
|
||||
toSave.sales_channels = sales_channels
|
||||
}
|
||||
|
||||
const product = await manager.save(toSave)
|
||||
|
||||
if (data.isMedusaV2Enabled) {
|
||||
await manager.query(
|
||||
`INSERT INTO "product_sales_channel" (id, product_id, sales_channel_id)
|
||||
VALUES ${sales_channels
|
||||
.map(
|
||||
(sc) =>
|
||||
`('${generateEntityId(undefined, "prodsc")}', '${toSave.id}', '${
|
||||
sc.id
|
||||
}')`
|
||||
)
|
||||
.join(", ")};
|
||||
`
|
||||
)
|
||||
}
|
||||
|
||||
const optionId = `${prodId}-option`
|
||||
const options = data.options || [{ id: optionId, title: "Size" }]
|
||||
for (const o of options) {
|
||||
|
||||
Reference in New Issue
Block a user