docs: add more context and description to recipe steps (#9861)

This commit is contained in:
Shahed Nasser
2024-11-10 22:43:42 +01:00
committed by GitHub
parent e94f35458c
commit 5d7c1ad655
4 changed files with 94 additions and 16 deletions
@@ -51,7 +51,11 @@ By following this example, youll have a subscription commerce store with the
## Step 1: Create Subscription Module
The first step is to create a subscription module that holds the subscription's data model and provides data-management features through its service.
Medusa creates commerce features in modules. For example, product features and data models are created in the Product Module.
You also create custom commerce data models and features in custom modules. They're integrated into the Medusa application similar to Medusa's modules without side effects.
So, you'll create a subscription module that holds the data models related to a subscription and allows you to manage them.
Create the directory `src/modules/subscription`.
@@ -176,7 +180,17 @@ module.exports = defineConfig({
## Step 2: Define Links
In this step, youll define links between the Subscription Modules `Subscription` data model and the data models of Medusas commerce modules.
Modules are isolated in Medusa, making them reusable, replaceable, and integrable in your application without side effects.
So, you can't have relations between data models in modules. Instead, you define a link between them.
Links are relations between data models of different modules that maintain the isolation between the modules.
In this step, youll define links between the Subscription Modules `Subscription` data model and the data models of Medusas commerce modules:
1. Link between the `Subscription` data model and the Cart Module's `Cart` model.
2. Link between the `Subscription` data model and the Customer Module's `Customer` model.
3. Link between the `Subscription` data model and the Order Module's `Order` model.
### Define a Link to Cart
@@ -436,6 +450,8 @@ This method is used in the next step.
## Step 5: Create Subscription Workflow
To implement and expose a feature that manipulates data, you create a workflow that uses services to implement the functionality, then create an API route that executes that workflow.
In this step, youll create the workflow that youll execute when a customer purchases a subscription.
The workflow accepts a carts ID, and it has three steps:
@@ -648,6 +664,8 @@ The workflow returns the created subscription and order.
## Step 6: Override Complete Cart API Route
To expose custom commerce features to frontend applications, such as the Medusa Admin dashboard or a storefront, you expose an endpoint by creating an API route.
In this step, youll change what happens when the [Complete Cart API route](!api!/store#carts_postcartsidcomplete) is used to complete the customers purchase and place an order.
Create the file `src/api/store/carts/[id]/complete/route.ts` with the following content:
@@ -1076,6 +1094,8 @@ In the next section, youll extend the Medusa admin and use these API routes t
## Step 8: Extend Admin
The Medusa Admin is customizable, allowing you to inject widgets into existing pages or add UI routes to create new pages.
In this step, youll add two UI routes:
1. One to view all subscriptions.
@@ -1874,6 +1894,8 @@ In the next step, youll execute the workflow in a scheduled job.
## Step 10: Create New Subscription Orders Scheduled Job
A scheduled job is an asynchronous function executed at a specified interval pattern. Use scheduled jobs to execute a task at a regular interval.
In this step, youll create a scheduled job that runs once a day. It finds all subscriptions whose `next_order_date` property is the current date and uses the workflow from the previous step to create an order for them.
Create the file `src/jobs/create-subscription-orders.ts` with the following content: