Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(medusa, link-modules): sales channel <> order link #5810

Merged
merged 76 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
f4f6bb3
feat: sales channel joiner config
fPolic Oct 19, 2023
4c6ebaf
feat: product sales channel link config, SC list method
fPolic Oct 23, 2023
268bf96
feat: migration
fPolic Oct 23, 2023
3898708
fix: refactor list SC
fPolic Oct 23, 2023
56c366c
refactor: SC repo api
fPolic Oct 23, 2023
a475a66
chore: changeset
fPolic Oct 24, 2023
a4c410f
feat: add dedicated FF
fPolic Oct 24, 2023
0a1ef33
feat: product<> sc join entity
fPolic Oct 30, 2023
130b5b6
fix: update case
fPolic Oct 30, 2023
6fa9879
fix: add FF on in the repository, fix tests
fPolic Oct 30, 2023
886d735
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Oct 30, 2023
6e821d5
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Oct 30, 2023
87c6b37
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Oct 31, 2023
67b3b3a
fix: assign id when FF is on
fPolic Oct 31, 2023
5e70379
fix: target table
fPolic Oct 31, 2023
b3f3cd1
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Oct 31, 2023
5bb1b3d
feat: product service - fetch SC with RQ
fPolic Nov 2, 2023
4c7eb86
Merge remote-tracking branch 'origin/feat/sales-channel-module--joine…
fPolic Nov 2, 2023
1e35ae3
feat: admin list products & SC with isolated product domain
fPolic Nov 2, 2023
98b3410
feat: get admin product
fPolic Nov 2, 2023
5c873e2
feat: store endpoints
fPolic Nov 2, 2023
8e3b450
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 2, 2023
1fd544c
fix: remove duplicate import
fPolic Nov 2, 2023
8fa7fb5
fix: remove "name" prop
fPolic Nov 3, 2023
c228d0f
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 3, 2023
c35b211
feat: refactor
fPolic Nov 3, 2023
87480fd
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 6, 2023
cbb2954
fix: product seeder if FF is on
fPolic Nov 6, 2023
02e81cd
fix: env
fPolic Nov 6, 2023
5e21190
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 8, 2023
4852a00
refactor: workflow product handlers to handle remote links
fPolic Nov 10, 2023
e219e10
fix: condition
fPolic Nov 10, 2023
1986dc0
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 13, 2023
62c97fc
fix: use correct method
fPolic Nov 13, 2023
364f41d
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 13, 2023
916fd00
fix: build
fPolic Nov 13, 2023
38ba66f
wip: update FF
fPolic Nov 13, 2023
6740977
fix: update FF in the handlers
fPolic Nov 13, 2023
976dbff
chore: migrate to medusav2 FF
fPolic Nov 14, 2023
5f3f23e
chore: uncomment test
fPolic Nov 14, 2023
b2a808a
fix: product factory
fPolic Nov 14, 2023
759d331
fix: unlinking SC and product
fPolic Nov 14, 2023
3634fba
fix: use module name variable
fPolic Nov 14, 2023
c151e7c
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 14, 2023
e6eb846
refactor: cleanup query definitions
fPolic Nov 14, 2023
02adccf
fix: add constraint
fPolic Nov 14, 2023
87fe8dc
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 15, 2023
9840608
chore: rename prop
fPolic Nov 15, 2023
2457d88
fix: add hook
fPolic Nov 15, 2023
b57b47f
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 15, 2023
2f2da2f
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 15, 2023
54a7367
fix: address comments
fPolic Nov 16, 2023
0a8029e
Merge branch 'develop' into feat/sales-channel-module--joiner-config
riqwan Nov 16, 2023
db4f52c
fix: temp sc filtering
fPolic Nov 16, 2023
2f225fd
Merge remote-tracking branch 'origin/feat/sales-channel-module--joine…
fPolic Nov 16, 2023
abcb96c
fix: use RQ to filter by SC
fPolic Nov 16, 2023
9b3f2e8
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 17, 2023
4b87417
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 23, 2023
4e7b6a7
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 23, 2023
6048fb2
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Nov 28, 2023
1401879
Merge remote-tracking branch 'origin/feat/sales-channel-module--joine…
fPolic Nov 28, 2023
a6a0da0
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Dec 4, 2023
a8c5e95
wip: models/migration/links
fPolic Dec 4, 2023
b6b3248
feat: service changes, add to Orders to SC model, FF array
fPolic Dec 5, 2023
96263e8
fix: typo
fPolic Dec 5, 2023
34bf721
fix: order service units
fPolic Dec 6, 2023
b96f4ec
fix: sendgrid snaps
fPolic Dec 6, 2023
8960dbe
fix: remaining snaps
fPolic Dec 6, 2023
50bf9c2
fix: rename migration
fPolic Dec 6, 2023
f63e72d
chore: changesets
fPolic Dec 6, 2023
7701814
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Dec 11, 2023
9203645
Merge branch 'develop' into feat/sales-channel-module--joiner-config
fPolic Dec 12, 2023
8358a02
Merge branch 'feat/sales-channel-module--joiner-config' into feat/sal…
fPolic Dec 12, 2023
f96e261
Merge branch 'develop' into feat/sales-channel-module-order--joiner-c…
fPolic Jan 2, 2024
ea3cad7
fix: address some comments
fPolic Jan 2, 2024
7294108
fix: update entity
fPolic Jan 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/swift-carpets-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@medusajs/link-modules": patch
"@medusajs/core-flows": patch
"@medusajs/medusa": patch
"@medusajs/utils": patch
---

feat: sales channel <> order link
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ Object {
],
"locale": null,
"order": Object {
"afterLoad": [Function],
"beforeInsert": [Function],
"beforeUpdate": [Function],
"billing_address_id": null,
"canceled_at": null,
"cart_id": null,
Expand Down Expand Up @@ -753,7 +755,9 @@ Object {

exports[`medusa-plugin-sendgrid order canceled data 1`] = `
Object {
"afterLoad": [Function],
"beforeInsert": [Function],
"beforeUpdate": [Function],
"billing_address": null,
"billing_address_id": null,
"canceled_at": Any<Date>,
Expand Down Expand Up @@ -982,7 +986,9 @@ Object {

exports[`medusa-plugin-sendgrid order placed data 1`] = `
Object {
"afterLoad": [Function],
"beforeInsert": [Function],
"beforeUpdate": [Function],
"billing_address": null,
"billing_address_id": null,
"canceled_at": null,
Expand Down Expand Up @@ -1236,7 +1242,9 @@ Object {
},
"locale": null,
"order": Object {
"afterLoad": [Function],
"beforeInsert": [Function],
"beforeUpdate": [Function],
"billing_address": null,
"billing_address_id": null,
"canceled_at": null,
Expand Down Expand Up @@ -1612,7 +1620,9 @@ Object {
],
"locale": null,
"order": Object {
"afterLoad": [Function],
"beforeInsert": [Function],
"beforeUpdate": [Function],
"billing_address_id": null,
"canceled_at": null,
"cart_id": null,
Expand Down Expand Up @@ -2078,7 +2088,9 @@ Object {
],
"locale": null,
"order": Object {
"afterLoad": [Function],
"beforeInsert": [Function],
"beforeUpdate": [Function],
"billing_address_id": null,
"canceled_at": null,
"cart_id": null,
Expand Down Expand Up @@ -2533,4 +2545,4 @@ Object {
"tracking_links": Array [],
"tracking_number": "",
}
`;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ const {
startBootstrapApp,
} = require("../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../environment-helpers/use-db")
const {
useApi,
useExpressServer,
} = require("../../../environment-helpers/use-api")
const { useApi } = require("../../../environment-helpers/use-api")

const adminSeeder = require("../../../helpers/admin-seeder")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ export async function detachSalesChannelFromProducts({

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(
await promiseAll(
productIds.map((id) =>
remoteLink.dismiss({
[Modules.PRODUCT]: {
product_id: id,
Expand All @@ -57,8 +56,6 @@ export async function detachSalesChannelFromProducts({
)
)
}

return
} else {
await promiseAll(
Array.from(salesChannelIdProductIdsMap.entries()).map(
Expand Down
1 change: 1 addition & 0 deletions packages/link-modules/src/definitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./product-variant-price-set"
export * from "./product-shipping-profile"
export * from "./product-sales-channel"
export * from "./cart-sales-channel"
export * from "./order-sales-channel"
66 changes: 66 additions & 0 deletions packages/link-modules/src/definitions/order-sales-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { ModuleJoinerConfig } from "@medusajs/types"

import { LINKS } from "../links"

export const OrderSalesChannel: ModuleJoinerConfig = {
serviceName: LINKS.OrderSalesChannel,
isLink: true,
databaseConfig: {
tableName: "order_sales_channel",
idPrefix: "ordersc",
},
alias: [
{
name: "order_sales_channel",
},
{
name: "order_sales_channels",
},
],
primaryKeys: ["id", "order_id", "sales_channel_id"],
relationships: [
{
serviceName: "orderService",
isInternalService: true,
primaryKey: "id",
foreignKey: "order_id",
alias: "order",
},
{
serviceName: "salesChannelService",
isInternalService: true,
primaryKey: "id",
foreignKey: "sales_channel_id",
alias: "sales_channel",
},
],
extends: [
{
serviceName: "orderService",
fieldAlias: {
sales_channel: "sales_channel_link.sales_channel",
},
relationship: {
serviceName: LINKS.OrderSalesChannel,
isInternalService: true,
primaryKey: "order_id",
foreignKey: "id",
alias: "sales_channel_link",
},
},
{
serviceName: "salesChannelService",
fieldAlias: {
orders: "order_link.order",
},
relationship: {
serviceName: LINKS.OrderSalesChannel,
isInternalService: true,
primaryKey: "sales_channel_id",
foreignKey: "id",
alias: "order_link",
isList: true,
},
},
],
}
6 changes: 6 additions & 0 deletions packages/link-modules/src/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ export const LINKS = {
"salesChannelService",
"sales_channel_id"
),
OrderSalesChannel: composeLinkName(
"orderService",
"order_id",
"salesChannelService",
"sales_channel_id"
),
}
15 changes: 15 additions & 0 deletions packages/medusa/src/joiner-configs/order-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ModuleJoinerConfig } from "@medusajs/types"

export default {
serviceName: "orderService",
primaryKeys: ["id"],
linkableKeys: { order_id: "Order" },
alias: [
{
name: "order",
},
{
name: "orders",
},
],
} as ModuleJoinerConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import { MedusaV2Flag } from "@medusajs/utils"

import SalesChannelFeatureFlag from "../loaders/feature-flags/sales-channels"

export const featureFlag = [SalesChannelFeatureFlag.key, MedusaV2Flag.key]

export class OrderSalesChannelLink1701860329931 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE IF NOT EXISTS "order_sales_channel"
(
"id" character varying NOT NULL,
"order_id" character varying NOT NULL,
"sales_channel_id" character varying NOT NULL,
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
"updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
"deleted_at" TIMESTAMP WITH TIME ZONE,
CONSTRAINT "order_sales_channel_pk" PRIMARY KEY ("order_id", "sales_channel_id"),
CONSTRAINT "order_sales_channel_order_id_unique" UNIQUE ("order_id")
);
CREATE INDEX IF NOT EXISTS "IDX_id_order_sales_channel" ON "order_sales_channel" ("id");

insert into "order_sales_channel" (id, order_id, sales_channel_id)
(select 'ordersc_' || substr(md5(random()::text), 0, 27), id, sales_channel_id from "order" WHERE sales_channel_id IS NOT NULL);

ALTER TABLE "order" DROP CONSTRAINT IF EXISTS "FK_6ff7e874f01b478c115fdd462eb";
`)
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
UPDATE "order"
SET "sales_channel_id" = "order_sales_channel"."sales_channel_id"
FROM "order_sales_channel"
WHERE "order"."id" = "order_sales_channel"."order_id";

DROP TABLE IF EXISTS "order_sales_channel";

ALTER TABLE "order" ADD CONSTRAINT "FK_6ff7e874f01b478c115fdd462eb" FOREIGN KEY ("sales_channel_id") REFERENCES "sales_channel"("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
`)
}
}
29 changes: 29 additions & 0 deletions packages/medusa/src/models/order-sales-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { BeforeInsert, Column, Index, PrimaryColumn } from "typeorm"
import { MedusaV2Flag, SalesChannelFeatureFlag } from "@medusajs/utils"

import { generateEntityId } from "../utils"
import { SoftDeletableEntity } from "../interfaces"
import { FeatureFlagEntity } from "../utils/feature-flag-decorators"

@FeatureFlagEntity([MedusaV2Flag.key, SalesChannelFeatureFlag.key])
export class OrderSalesChannel extends SoftDeletableEntity {
fPolic marked this conversation as resolved.
Show resolved Hide resolved
@Column()
id: string

@Index("order_sales_channel_order_id_unique", {
unique: true,
})
@PrimaryColumn()
order_id: string

@PrimaryColumn()
sales_channel_id: string

/**
* @apiIgnore
*/
@BeforeInsert()
private beforeInsert(): void {
this.id = generateEntityId(this.id, "ordersc")
}
}
Loading