* docs improvements and changes * updated module definition * modules + dml changes * fix build * fix vale error * fix lint errors * fixes to stripe docs * fix condition * fix condition * fix module defintion * fix checkout * disable UI action * change oas preview action * flatten provider module options * fix lint errors * add module link docs * pr comments fixes * fix vale error * change node engine version * links -> linkable * add note about database name * small fixes * link fixes * fix response code in api reference * added migrations step
50 lines
1.7 KiB
Plaintext
50 lines
1.7 KiB
Plaintext
export const metadata = {
|
||
title: `${pageNumber} Commerce Modules`,
|
||
}
|
||
|
||
# {metadata.title}
|
||
|
||
In this chapter, you'll learn about Medusa's commerce modules.
|
||
|
||
## What is a Commerce Module?
|
||
|
||
Medusa provides all its commerce features as separate modules, such as the Product or Order modules.
|
||
|
||
These modules and your custom modules are interchangeable in the Medusa application, making Medusa’s architecture more flexible.
|
||
|
||
Refer to [this reference](!resources!/commerce-modules) for a full list of commerce modules in Medusa.
|
||
|
||
---
|
||
|
||
## Resolve Commerce Module Services
|
||
|
||
Similarly to your custom module, a commerce module's main service is registered in the Medusa container. So, you can resolve it in your resources, such as API routes, to use its functionality.
|
||
|
||
For example, you saw this code snippet in the [Medusa container chapter](../medusa-container/page.mdx):
|
||
|
||
```ts highlights={[["13"]]}
|
||
import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
|
||
import { IProductModuleService } from "@medusajs/types"
|
||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||
|
||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||
const productModuleService: IProductModuleService = req.scope.resolve(
|
||
ModuleRegistrationName.PRODUCT
|
||
)
|
||
|
||
const [, count] = await productModuleService.listAndCount()
|
||
|
||
res.json({
|
||
count,
|
||
})
|
||
}
|
||
```
|
||
|
||
When you resolve the `ModuleRegistrationName.PRODUCT` (or `productModuleService`) registration name, you're actually resolving the main service of the Product Module.
|
||
|
||
<Note title="Tip">
|
||
|
||
To resolve the main service of any commerce module, use the registration name defined in the `ModuleRegistrationName` enum imported from `@medusajs/modules-sdk`.
|
||
|
||
</Note>
|