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: sales channel module #5923

Merged
merged 140 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 127 commits
Commits
Show all changes
140 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
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
0620bf2
wip: setup sales channel module
fPolic Dec 15, 2023
d238b82
feat: create, delete, list
fPolic Dec 18, 2023
e643a05
Merge branch 'develop' into feat/sales-channel-module
fPolic Dec 18, 2023
9552b6e
fix: remove changelog
fPolic Dec 18, 2023
39212d0
fix: rename
fPolic Dec 18, 2023
e64b5f3
fix: rm seed for now
fPolic Dec 18, 2023
524ef7c
fix: container registrations, list types
fPolic Dec 19, 2023
e0f584b
feat: list and count tests
fPolic Dec 19, 2023
1b0e36e
Merge branch 'develop' into feat/sales-channel-module
fPolic Dec 20, 2023
8c94115
chore: changesets
fPolic Dec 20, 2023
ab16f3d
wip: add service units
fPolic Dec 20, 2023
a4de24a
fix: folder name
fPolic Dec 20, 2023
1f67729
Merge branch 'develop' into feat/sales-channel-module
fPolic Dec 20, 2023
857fae5
fix: update yarn lock
fPolic Dec 20, 2023
8ac4a32
fix: interface, migrations up, loaders, refactor types
fPolic Dec 21, 2023
44f017b
fix: joiner config
fPolic Dec 21, 2023
b856842
Merge branch 'develop' into feat/sales-channel-module
fPolic Dec 21, 2023
8015677
feat: seed scripts
fPolic Dec 21, 2023
d4a3b9b
Merge branch 'develop' into feat/sales-channel-module
fPolic Dec 21, 2023
11a6cae
Merge branch 'develop' into feat/sales-channel-module
fPolic Dec 21, 2023
05112aa
Merge branch 'develop' into feat/sales-channel-module
fPolic Dec 22, 2023
2b0d285
fix: rollup build issue
fPolic Dec 22, 2023
7edd7b7
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 2, 2024
415ead8
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 2, 2024
523d4fd
refactor: split SC service and module service
fPolic Jan 2, 2024
768aeba
fix: service loading
fPolic Jan 2, 2024
707c644
fix: use correct manager decorator
fPolic Jan 2, 2024
facb562
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 2, 2024
9620080
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 3, 2024
ec7eb3b
fix: types for build
fPolic Jan 3, 2024
0c431c2
fix: mikroorm versioning
fPolic Jan 3, 2024
a200c35
fix: remove joiner config from core
fPolic Jan 3, 2024
b3d7e56
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 4, 2024
c271129
fix: test medusa config
fPolic Jan 5, 2024
06828b1
fix: create table if not exist
fPolic Jan 5, 2024
cf15d89
Merge branch 'develop' into feat/sales-channel-module
olivermrbl Jan 7, 2024
10634ce
fix: address feedback
fPolic Jan 8, 2024
d7af1a9
fix: use tx manager
fPolic Jan 8, 2024
61d2123
fix: import
fPolic Jan 8, 2024
60576cd
fix: import manager
fPolic Jan 8, 2024
aca0327
fix: test
fPolic Jan 8, 2024
2fdb572
wip: soft delete / restore
fPolic Jan 8, 2024
92bc62d
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 8, 2024
eb0cefa
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 9, 2024
ee0c229
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 9, 2024
a7949a7
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 10, 2024
47e020c
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 10, 2024
ad821d6
chore: refactor scripts & fix imports
fPolic Jan 10, 2024
7279806
chore: update repository
fPolic Jan 10, 2024
4ab83df
fix: yarn lock
fPolic Jan 11, 2024
1212578
fix: address review
fPolic Jan 15, 2024
b3b3ebc
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 15, 2024
7667234
fix: update lock file
fPolic Jan 15, 2024
3c246f2
fix: link module name
fPolic Jan 15, 2024
9c08e6e
fix: create method overload
fPolic Jan 15, 2024
1507b2d
fix: delete method overload
fPolic Jan 15, 2024
2c4835b
fix: update method overload
fPolic Jan 15, 2024
13cb4e8
fix: types
fPolic Jan 15, 2024
3ad8308
fix: readd migration
fPolic Jan 15, 2024
6bd1de3
fix: other service names from module
fPolic Jan 15, 2024
9d68977
fix: use module name variable in core-flows
fPolic Jan 15, 2024
4d102a0
fix: module name
fPolic Jan 15, 2024
3d3dc1c
fix: use module var name in the cart service
fPolic Jan 15, 2024
007ba7f
fix: address feedback
fPolic Jan 16, 2024
c1bbdb0
fix: change date types
fPolic Jan 16, 2024
15c2d0b
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 18, 2024
5553f9c
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 18, 2024
c10d4f3
refactor: use abstract service
fPolic Jan 18, 2024
946c03b
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 22, 2024
c223e2e
refactor: address feedback
fPolic Jan 22, 2024
6ba110f
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 22, 2024
76d724f
fix: add repo type
fPolic Jan 22, 2024
c057da3
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 23, 2024
22cc686
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 24, 2024
da21a0c
Merge branch 'develop' into feat/sales-channel-module
fPolic Jan 26, 2024
38a2cbd
fix: lock conflict
fPolic Jan 26, 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/flat-bees-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@medusajs/core-flows": patch
fPolic marked this conversation as resolved.
Show resolved Hide resolved
"@medusajs/modules-sdk": patch
"@medusajs/medusa": patch
"@medusajs/types": patch
---

feat: Sales Channel module
5 changes: 5 additions & 0 deletions integration-tests/plugins/medusa-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,10 @@ module.exports = {
resources: "shared",
resolve: "@medusajs/pricing",
},
[Modules.SALES_CHANNEL]: {
scope: "internal",
resources: "shared",
resolve: "@medusajs/sales-channel",
},
},
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MedusaV2Flag } from "@medusajs/utils"
import { WorkflowArguments } from "@medusajs/workflows-sdk"
import { Modules } from "@medusajs/modules-sdk"

type HandlerInputData = {
cart: {
Expand Down Expand Up @@ -30,10 +31,10 @@ export async function attachCartToSalesChannel({
const salesChannel = data[Aliases.SalesChannel]

await remoteLink.create({
cartService: {
[Modules.CART]: {
cart_id: cart.id,
},
salesChannelService: {
[Modules.SALES_CHANNEL]: {
sales_channel_id: salesChannel.sales_channel_id,
},
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MedusaV2Flag } from "@medusajs/utils"
import { WorkflowArguments } from "@medusajs/workflows-sdk"
import { Modules } from "@medusajs/modules-sdk"

type HandlerInputData = {
cart: {
Expand Down Expand Up @@ -30,10 +31,10 @@ export async function detachCartFromSalesChannel({
const salesChannel = data[Aliases.SalesChannel]

await remoteLink.dismiss({
cartService: {
[Modules.CART]: {
cart_id: cart.id,
},
salesChannelService: {
[Modules.SALES_CHANNEL]: {
sales_channel_id: salesChannel.sales_channel_id,
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function attachSalesChannelToProducts({
[Modules.PRODUCT]: {
product_id: id,
},
salesChannelService: {
[Modules.SALES_CHANNEL]: {
sales_channel_id: salesChannelId,
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function detachSalesChannelFromProducts({
[Modules.PRODUCT]: {
product_id: id,
},
salesChannelService: {
[Modules.SALES_CHANNEL]: {
sales_channel_id: salesChannelId,
},
})
Expand Down
9 changes: 5 additions & 4 deletions packages/link-modules/src/definitions/cart-sales-channel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ModuleJoinerConfig } from "@medusajs/types"
import { LINKS } from "../links"
import { Modules } from "@medusajs/modules-sdk"

export const CartSalesChannel: ModuleJoinerConfig = {
serviceName: LINKS.CartSalesChannel,
Expand All @@ -19,14 +20,14 @@ export const CartSalesChannel: ModuleJoinerConfig = {
primaryKeys: ["id", "cart_id", "sales_channel_id"],
relationships: [
{
serviceName: "cartService",
serviceName: Modules.CART,
isInternalService: true,
primaryKey: "id",
foreignKey: "cart_id",
alias: "cart",
},
{
serviceName: "salesChannelService",
serviceName: Modules.SALES_CHANNEL,
isInternalService: true,
primaryKey: "id",
foreignKey: "sales_channel_id",
Expand All @@ -35,7 +36,7 @@ export const CartSalesChannel: ModuleJoinerConfig = {
],
extends: [
{
serviceName: "cartService",
serviceName: Modules.CART,
fieldAlias: {
sales_channel: "sales_channel_link.sales_channel",
},
Expand All @@ -48,7 +49,7 @@ export const CartSalesChannel: ModuleJoinerConfig = {
},
},
{
serviceName: "salesChannelService",
serviceName: Modules.SALES_CHANNEL,
fieldAlias: {
carts: "cart_link.cart",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const ProductSalesChannel: ModuleJoinerConfig = {
alias: "product",
},
{
serviceName: "salesChannelService",
serviceName: Modules.SALES_CHANNEL,
isInternalService: true,
primaryKey: "id",
foreignKey: "sales_channel_id",
Expand All @@ -48,7 +48,7 @@ export const ProductSalesChannel: ModuleJoinerConfig = {
},
},
{
serviceName: "salesChannelService",
serviceName: Modules.SALES_CHANNEL,
relationship: {
serviceName: LINKS.ProductSalesChannel,
isInternalService: true,
Expand Down
10 changes: 5 additions & 5 deletions packages/link-modules/src/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ export const LINKS = {
ProductSalesChannel: composeLinkName(
Modules.PRODUCT,
"product_id",
"salesChannelService",
Modules.SALES_CHANNEL,
"sales_channel_id"
),
CartSalesChannel: composeLinkName(
"cartService",
Modules.CART,
"cart_id",
"salesChannelService",
Modules.SALES_CHANNEL,
"sales_channel_id"
),
OrderSalesChannel: composeLinkName(
"orderService",
"order_id",
"salesChannelService",
Modules.SALES_CHANNEL,
"sales_channel_id"
),
PublishableApiKeySalesChannel: composeLinkName(
"publishableApiKeyService",
"publishable_key_id",
"salesChannelService",
Modules.SALES_CHANNEL,
"sales_channel_id"
),
}
2 changes: 1 addition & 1 deletion packages/medusa/src/joiner-configs/cart-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ModuleJoinerConfig } from "@medusajs/types"
import { Cart } from "../models"

export default {
serviceName: "cartService",
serviceName: Modules.CART,
primaryKeys: ["id"],
linkableKeys: { cart_id: "Cart" },
alias: {
Expand Down
1 change: 0 additions & 1 deletion packages/medusa/src/joiner-configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * as cart from "./cart-service"
export * as customer from "./customer-service"
export * as region from "./region-service"
export * as salesChannel from "./sales-channel-service"
export * as shippingProfile from "./shipping-profile-service"
export * as publishableApiKey from "./publishable-api-key-service"
32 changes: 0 additions & 32 deletions packages/medusa/src/joiner-configs/sales-channel-service.ts

This file was deleted.

14 changes: 7 additions & 7 deletions packages/medusa/src/services/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import { ShippingMethodRepository } from "../repositories/shipping-method"
import { PaymentSessionInput } from "../types/payment"
import { validateEmail } from "../utils/is-email"
import { RemoteQueryFunction } from "@medusajs/types"
import { RemoteLink } from "@medusajs/modules-sdk"
import { Modules, RemoteLink } from "@medusajs/modules-sdk"

type InjectedDependencies = {
manager: EntityManager
Expand Down Expand Up @@ -501,10 +501,10 @@ class CartService extends TransactionBaseService {
)

await this.remoteLink_.create({
cartService: {
[Modules.CART]: {
cart_id: cart.id,
},
salesChannelService: {
[Modules.SALES_CHANNEL]: {
sales_channel_id: salesChannel.id,
},
})
Expand Down Expand Up @@ -1294,20 +1294,20 @@ class CartService extends TransactionBaseService {
if (this.featureFlagRouter_.isFeatureEnabled(MedusaV2Flag.key)) {
if (cart.sales_channel_id) {
await this.remoteLink_.dismiss({
cartService: {
[Modules.CART]: {
cart_id: cart.id,
},
salesChannelService: {
[Modules.SALES_CHANNEL]: {
sales_channel_id: cart.sales_channel_id,
},
})
}

await this.remoteLink_.create({
cartService: {
[Modules.CART]: {
cart_id: cart.id,
},
salesChannelService: {
[Modules.SALES_CHANNEL]: {
sales_channel_id: salesChannel.id,
},
})
Expand Down
17 changes: 17 additions & 0 deletions packages/modules-sdk/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum Modules {
PRICING = "pricingService",
PROMOTION = "promotion",
AUTHENTICATION = "authentication",
SALES_CHANNEL = "salesChannel",
CART = "cart",
PAYMENT = "payment",
}
Expand All @@ -28,6 +29,7 @@ export enum ModuleRegistrationName {
PRICING = "pricingModuleService",
PROMOTION = "promotionModuleService",
AUTHENTICATION = "authenticationModuleService",
SALES_CHANNEL = "salesChannelModuleService",
CART = "cartModuleService",
PAYMENT = "paymentModuleService",
}
Expand All @@ -41,6 +43,7 @@ export const MODULE_PACKAGE_NAMES = {
[Modules.PRICING]: "@medusajs/pricing",
[Modules.PROMOTION]: "@medusajs/promotion",
[Modules.AUTHENTICATION]: "@medusajs/authentication",
[Modules.SALES_CHANNEL]: "@medusajs/sales-channel",
[Modules.CART]: "@medusajs/cart",
[Modules.PAYMENT]: "@medusajs/payment",
}
Expand Down Expand Up @@ -160,6 +163,20 @@ export const ModulesDefinition: { [key: string | Modules]: ModuleDefinition } =
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.SALES_CHANNEL]: {
key: Modules.SALES_CHANNEL,
registrationName: ModuleRegistrationName.SALES_CHANNEL,
defaultPackage: false,
label: upperCaseFirst(ModuleRegistrationName.SALES_CHANNEL),
isRequired: false,
canOverride: true,
isQueryable: true,
dependencies: ["logger"],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.CART]: {
key: Modules.CART,
registrationName: ModuleRegistrationName.CART,
Expand Down
6 changes: 6 additions & 0 deletions packages/sales-channel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/dist
node_modules
.DS_store
.env*
.env
*.sql
3 changes: 3 additions & 0 deletions packages/sales-channel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Sales Channel Module

Sales Channel module enables management of sales channels that are used for grouping Products/Carts/Orders etc.
40 changes: 40 additions & 0 deletions packages/sales-channel/integration-tests/__fixtures__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { SalesChannel } from "@models"

const salesChannelData = [
{
id: "channel-1",
name: "Channel 1",
description: "Channel description 1",
is_disabled: false,
},
{
id: "channel-2",
name: "Channel 2",
description: "Channel description 2",
is_disabled: false,
},
{
id: "channel-3",
name: "Channel 3",
description: "Channel description 3",
is_disabled: true,
},
]

export async function createSalesChannels(
manager: SqlEntityManager,
channelData: any[] = salesChannelData
): Promise<SalesChannel[]> {
const channels: SalesChannel[] = []

for (let data of channelData) {
const sc = manager.create(SalesChannel, data)

channels.push(sc)
}

await manager.persistAndFlush(channels)

return channels
}
Loading