- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
2.5. Commerce Modules
In this chapter, you'll learn about Medusa's commerce modules.
What is a Commerce Module?#
A commerce module is a package built by Medusa that provides business logic and data models specific for a single commerce domain, such as the Product and Order modules. Commerce modules are available out-of-the-box in your application.
Medusa implements core commerce flows in workflows that use the commerce modules. Then, it exposes admin and storefront API routes that, under the hood, execute these workflows.
For example, the workflow to add a product to the cart uses the Product Module to check if the product exists, the Inventory Module to ensure the product is available in the inventory, and the Cart Module to finally add the product to the cart.
List of Medusa's Commerce Modules#
Refer to this reference for a full list of commerce modules in Medusa.
Use Commerce Modules in Custom Flows#
Similar to your custom modules, the Medusa application registers a commerce module's service in the container. So, you can resolve it in your custom flows. This is useful as you build unique requirements extending core commerce features.
For example, consider you have a workflow (a special function that performs a task in a series of steps with rollback mechanism) that needs a step to retrieve the total number of products. You can create a step in the workflow that resolves the Product Module's service from the container to use its methods:
1import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"2import { Modules } from "@medusajs/framework/utils"3 4export const countProductsStep = createStep(5 "count-products",6 async ({ }, { container }) => {7 const productModuleService = container.resolve(Modules.PRODUCT)8 9 const [,count] = await productModuleService.listAndCountProducts()10 11 return new StepResponse(count)12 }13)
Your workflow can use services of both custom and commerce modules, supporting you in building custom flows without having to re-build core commerce features.