docs: intro + basic chapter fixes (#10361)

This commit is contained in:
Shahed Nasser
2024-12-02 09:31:47 +02:00
committed by GitHub
parent a1f36caaf7
commit b4d6a4b3f0
17 changed files with 105 additions and 91 deletions
@@ -8,11 +8,9 @@ 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.
Commerce modules are built-in [modules](../modules/page.mdx) of Medusa that provide core commerce logic specific to domains like Products, Orders, Customers, Fulfillment, and much more.
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.
Medusa's commerce modules are used to form Medusa's default [workflows](!resources!/medusa-workflows-reference) and [APIs](!api!/store). For example, when you call the add to cart endpoint. the add to cart workflow runs which 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.
<Note title="Tip">
@@ -20,6 +18,8 @@ You'll find the details and steps of the add-to-cart workflow in [this workflow
</Note>
The core commerce logic contained in Commerce Modules is also available directly when you are building customizations. This granular access to commerce functionality is unique and expands what's possible to build with Medusa drastically.
### List of Medusa's Commerce Modules
Refer to [this reference](!resources!/commerce-modules) for a full list of commerce modules in Medusa.
@@ -33,18 +33,17 @@ Similar to your [custom modules](../modules/page.mdx), the Medusa application re
For example, consider you have a [workflow](../workflows/page.mdx) (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:
export const highlights = [
["7", "Modules.PRODUCT", "Resolve the Product Module's service from the container."],
["9", "listAndCountProducts", "Use the service's method to get the products count."]
["6", `"product"`, "Resolve the Product Module's service from the container."],
["8", "listAndCountProducts", "Use the service's method to get the products count."]
]
```ts highlights={highlights}
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
import { Modules } from "@medusajs/framework/utils"
export const countProductsStep = createStep(
"count-products",
async ({ }, { container }) => {
const productModuleService = container.resolve(Modules.PRODUCT)
const productModuleService = container.resolve("product")
const [,count] = await productModuleService.listAndCountProducts()