Skip to content

Commit

Permalink
Merge branch 'develop' into feat/add-q-and-order-to-stock-location
Browse files Browse the repository at this point in the history
  • Loading branch information
pKorsholm authored Jan 29, 2024
2 parents 1171863 + 3db2f95 commit e77cc57
Show file tree
Hide file tree
Showing 54 changed files with 1,364 additions and 61 deletions.
9 changes: 9 additions & 0 deletions .changeset/flat-bees-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@medusajs/core-flows": patch
"@medusajs/link-modules": patch
"@medusajs/medusa": patch
"@medusajs/modules-sdk": 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 @@ -71,5 +71,10 @@ module.exports = {
resources: "shared",
resolve: "@medusajs/promotion",
},
[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 @@ -17,6 +17,7 @@ export enum Modules {
PROMOTION = "promotion",
AUTHENTICATION = "authentication",
WORKFLOW_ENGINE = "workflows",
SALES_CHANNEL = "salesChannel",
CART = "cart",
CUSTOMER = "customer",
PAYMENT = "payment",
Expand All @@ -32,6 +33,7 @@ export enum ModuleRegistrationName {
PROMOTION = "promotionModuleService",
AUTHENTICATION = "authenticationModuleService",
WORKFLOW_ENGINE = "workflowsModuleService",
SALES_CHANNEL = "salesChannelModuleService",
CART = "cartModuleService",
CUSTOMER = "customerModuleService",
PAYMENT = "paymentModuleService",
Expand All @@ -48,6 +50,7 @@ export const MODULE_PACKAGE_NAMES = {
[Modules.PROMOTION]: "@medusajs/promotion",
[Modules.AUTHENTICATION]: "@medusajs/authentication",
[Modules.WORKFLOW_ENGINE]: "@medusajs/workflow-engine-inmemory",
[Modules.SALES_CHANNEL]: "@medusajs/sales-channel",
[Modules.CART]: "@medusajs/cart",
[Modules.CUSTOMER]: "@medusajs/customer",
[Modules.PAYMENT]: "@medusajs/payment",
Expand Down Expand Up @@ -182,6 +185,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

0 comments on commit e77cc57

Please sign in to comment.