Customer Module
The Customer Module is the @medusajs/customer
NPM package that provides customer-related features in your Medusa and Node.js applications.
Features
Customer Management
With the Customer Module, store and manage customers in your store.
Customer Organization
You can organize customers into groups. This has a lot of benefits and supports more use cases, such as provide discounts for specific customer groups using the Promotion Module.
Configure Customer Module
After installing the @medusajs/customer
package in your Medusa application, add it to the modules
object in medusa-config.js
:
How to Use Customer Module's Service
You can use the Customer Module's main service by resolving from the dependency container the resource ModuleRegistrationName.CUSTOMER
imported from @medusajs/modules-sdk
.
For example:
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export async function GET(
request: MedusaRequest,
res: MedusaResponse
) {
const customerModuleService: ICustomerModuleService =
request.scope.resolve(ModuleRegistrationName.CUSTOMER)
res.json({
customers: await customerModuleService.list(),
})
}
import { SubscriberArgs } from "@medusajs/medusa"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export default async function subscriberHandler({
container,
}: SubscriberArgs) {
const customerModuleService: ICustomerModuleService =
container.resolve(ModuleRegistrationName.CUSTOMER)
const customers = await customerModuleService.list()
}
import { createStep } from "@medusajs/workflows-sdk"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
const step1 = createStep("step-1", async (_, context) => {
const customerModuleService: ICustomerModuleService =
context.container.resolve(ModuleRegistrationName.PRODUCT)
const customers = await customerModuleService.list()
})
Was this section helpful?