docs: edits and fixes to commerce module docs (#7468)
Apply edits and fixes to the commerce modules docs
This commit is contained in:
1 parent
130de74d6d
commit
2c5ba408d4
160 files changed
+6400
-3790
No files matched your search
@@ -8,7 +8,7 @@ In this document, you’ll get an overview of the main concepts of a cart.
|
||||
|
||||
## Shipping and Billing Addresses
|
||||
|
||||
A cart has a shipping and billing address. Both of these addresses are represented by the `Address` data model.
|
||||
A cart has a shipping and billing address. Both of these addresses are represented by the [Address data model](/references/cart/models/Address).
|
||||
|
||||

|
||||
|
||||
@@ -16,13 +16,13 @@ A cart has a shipping and billing address. Both of these addresses are represent
|
||||
|
||||
## Line Items
|
||||
|
||||
A line item, represented by the `LineItem` data model, is a product added to the cart. A cart has multiple line items.
|
||||
A line item, represented by the `LineItem` data model, is a product variant added to the cart. A cart has multiple line items.
|
||||
|
||||
A line item stores some of the product’s fields, such as the `product_title` and `product_description`. It also stores data related to the item’s quantity and price.
|
||||
A line item stores some of the product variant’s fields, such as the `product_title` and `product_description`. It also stores data related to the item’s quantity and price.
|
||||
|
||||
<Note>
|
||||
|
||||
A product can be from the [Product Module](../../product/page.mdx) but can also be a custom item used only in this cart.
|
||||
A product variant can be from the [Product Module](../../product/page.mdx) but can also be a custom item used only in this cart.
|
||||
|
||||
</Note>
|
||||
|
||||
@@ -30,16 +30,14 @@ A product can be from the [Product Module](../../product/page.mdx) but can also
|
||||
|
||||
## Shipping Methods
|
||||
|
||||
A shipping method, represented by the `ShippingMethod` data model, is the method used to fulfill the items in the cart after the order is placed. A cart can have more than one shipping method.
|
||||
A shipping method, represented by the [ShippingMethod data model](/references/cart/models/ShippingMethod), is used to fulfill the items in the cart after the order is placed. A cart can have more than one shipping method.
|
||||
|
||||
If the shipping method is created from a shipping option, typically available through the Fulfillment Module, its ID is stored in the `shipping_option_id`.
|
||||
If the shipping method is created from a shipping option, available through the [Fulfillment Module](../../fulfillment/page.mdx), its ID is stored in the `shipping_option_id`.
|
||||
|
||||
A shipping method can also be a custom method associated with this cart only.
|
||||
|
||||
### data Field
|
||||
|
||||
When fulfilling the order after its placed, you may use a third-party fulfillment provider that requires additional custom data to be passed along from the checkout process.
|
||||
After an order is placed, you may use a third-party fulfillment provider to fulfill its shipments. If the fulfillment provider requires additional custom data to be passed along from the checkout process, you can add this data in the `ShippingMethod`'s `data` field.
|
||||
|
||||
The `ShippingMethod` data model has a `data` field. It's an object used to store custom data relevant later for fulfillment.
|
||||
|
||||
In the Medusa application, it's the `data` is passed to the Fulfillment Module when fulfilling items.
|
||||
The `data` field is an object used to store custom data relevant later for fulfillment.
|
||||
@@ -8,4 +8,10 @@ export const metadata = {
|
||||
|
||||
Find in this reference the list of events emitted by the Cart Module.
|
||||
|
||||
<Note type="soon">
|
||||
|
||||
Events are still in development, so this reference will change in the future.
|
||||
|
||||
</Note>
|
||||
|
||||
<EventsTable />
|
||||
@@ -448,7 +448,7 @@ In this guide, you’ll find common examples of how you can use the Cart Module
|
||||
const cartModuleService: ICartModuleService =
|
||||
req.scope.resolve(ModuleRegistrationName.CART)
|
||||
|
||||
await cartModuleService.deleteLineItems(["cali_123"])
|
||||
await cartModuleService.deleteShippingMethods(["casm_123"])
|
||||
|
||||
res.status(200)
|
||||
}
|
||||
@@ -482,4 +482,4 @@ In this guide, you’ll find common examples of how you can use the Cart Module
|
||||
|
||||
## More Examples
|
||||
|
||||
The [module interface reference](/references/cart) provides a reference to all the methods available for use with examples for each.
|
||||
The [Cart Module's main service reference](/references/cart) provides a reference to all the methods available for use with examples for each.
|
||||
@@ -8,8 +8,6 @@ export const metadata = {
|
||||
|
||||
The Cart Module is the `@medusajs/cart` NPM package that provides cart-related features in your Medusa and Node.js applications.
|
||||
|
||||
---
|
||||
|
||||
## Features
|
||||
|
||||
### Cart Management
|
||||
@@ -67,14 +65,16 @@ When used with their respective modules and other commerce modules, you benefit
|
||||
|
||||
## Configure Cart Module
|
||||
|
||||
After installing the `@medusajs/cart` package in your Medusa application, add it to the `modules` object in `medusa-config.js`:
|
||||
To use the Cart Module, enable it in the `modules` object in `medusa-config.js`:
|
||||
|
||||
```js title="medusa-config.js"
|
||||
const { Modules } = require("@medusajs/modules-sdk")
|
||||
|
||||
// ...
|
||||
|
||||
const modules = {
|
||||
// ...
|
||||
cart: {
|
||||
resolve: "@medusajs/cart",
|
||||
},
|
||||
[Modules.CART]: true,
|
||||
}
|
||||
```
|
||||
|
||||
@@ -134,11 +134,14 @@ For example:
|
||||
import { ICartModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
|
||||
const step1 = createStep("step-1", async (_, context) => {
|
||||
const step1 = createStep(
|
||||
"step-1",
|
||||
async (_, { container }) => {
|
||||
const cartModuleService: ICartModuleService =
|
||||
context.container.resolve(
|
||||
container.resolve(
|
||||
ModuleRegistrationName.CART
|
||||
)
|
||||
|
||||
const carts = await cartModuleService.list()
|
||||
})
|
||||
```
|
||||
|
||||
@@ -14,17 +14,26 @@ In this document, you’ll learn how a promotion is applied to a cart’s line i
|
||||
|
||||
An adjustment line indicates a change to an item or a shipping method’s amount. It’s used to apply promotions or discounts on a cart.
|
||||
|
||||
The `LineItemAdjustment` data model represents adjustment lines for a line item, and the `ShippingMethodAdjustment` data model represents adjustment lines for a shipping method.
|
||||
The `LineItemAdjustment` data model represents changes on a line item, and the `ShippingMethodAdjustment` data model represents changes on a shipping method.
|
||||
|
||||

|
||||
|
||||
The `amount` field of the adjustment line indicates the amount to be discounted from the original amount. Also, the ID of the applied promotion can be stored in the `promotion_id` field of the adjustment line.
|
||||
The `amount` field of the adjustment line indicates the amount to be discounted from the original amount. Also, the ID of the applied promotion is stored in the `promotion_id` field of the adjustment line.
|
||||
|
||||
---
|
||||
|
||||
## Discountable Option
|
||||
|
||||
The `LineItem` data model has an `is_discountable` field that indicates whether promotions can be applied to the line item. It’s enabled by default.
|
||||
|
||||
When disabled, a promotion can’t be applied to a line item. In the context of the Promotion Module, the promotion isn’t applied to the line item even if it matches its rules.
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Promotion Actions
|
||||
|
||||
When using the Cart and Promotion modules together, such as in the Medusa application, use the `computeActions` method of the Promotion Module’s main service. It retrieves the actions of line items and shipping methods.
|
||||
When using the Cart and Promotion modules together, use the [computeActions method of the Promotion Module’s main service](/references/promotion/computeActions). It retrieves the actions of line items and shipping methods.
|
||||
|
||||
<Note>
|
||||
|
||||
@@ -90,12 +99,6 @@ const actions = await promotionModuleService.computeActions(
|
||||
|
||||
The `computeActions` method accepts the existing adjustments of line items and shipping methods to compute the actions accurately.
|
||||
|
||||
<Note>
|
||||
|
||||
Learn more about the `computeActions` method in [this reference](/references/promotion/computeActions).
|
||||
|
||||
</Note>
|
||||
|
||||
Then, use the returned `addItemAdjustment` and `addShippingMethodAdjustment` actions to set the cart’s line item and the shipping method’s adjustments.
|
||||
|
||||
```ts
|
||||
@@ -121,12 +124,4 @@ await cartModuleService.setShippingMethodAdjustments(
|
||||
action.action === "addShippingMethodAdjustment"
|
||||
) as AddShippingMethodAdjustment[]
|
||||
)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Discountable Option
|
||||
|
||||
The `LineItem` data model has an `is_discountable` field that indicates whether promotions can be applied to the line item. It’s enabled by default.
|
||||
|
||||
When disabled, a promotion can’t be applied to a line item. In the context of the Promotion Module, the promotion isn’t applied to the line item even if it matches its rules.
|
||||
```
|
||||
@@ -4,36 +4,50 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
When Commerce Modules are used together in a Medusa application, the Medusa application handles building the relations between these modules.
|
||||
|
||||
This document showcases the relation between the Cart Module and other Commerce Modules.
|
||||
This document showcases the link modules defined between the Cart Module and other commerce modules.
|
||||
|
||||
## Customer Module
|
||||
|
||||
A cart is scoped to the customer using it. The Medusa application forms a relation between the `Cart` and `Customer` data models.
|
||||
A cart is scoped to the customer using it. Medusa defines a link module that builds a relationship between the `Cart` and `Customer` data models.
|
||||
|
||||

|
||||

|
||||
|
||||
---
|
||||
|
||||
## Payment Module
|
||||
|
||||
The Payment Module allows you to associate payments with a cart. The Medusa application forms a relation between the `Cart` and `PaymentCollection` data models.
|
||||
The Payment Module allows you to associate payments with a cart. Medusa defines a link module that builds a relationship between the `Cart` and `PaymentCollection` data models.
|
||||
|
||||

|
||||

|
||||
|
||||
---
|
||||
|
||||
## Product Module
|
||||
|
||||
A cart's line item is associated with a product and its variant. Medusa defines a link module that builds a relationship between the `Cart`, `Product`, and `ProductVariant` data models.
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Promotion Module
|
||||
|
||||
A promotion can be applied on line items and shipping methods of a cart. The Medusa application forms a relation between the `Cart` and `Promotion` data models.
|
||||
A promotion can be applied on line items and shipping methods of a cart. Medusa defines a link module that builds a relationship between the `Cart`, `LineItemAdjustment`, and `Promotion` data models.
|
||||
|
||||

|
||||

|
||||
|
||||
---
|
||||
|
||||
## Region Module
|
||||
|
||||
A cart is scoped to a region. Medusa defines a link module that builds a relationship between the `Cart` and `Region` data models.
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Sales Channel Module
|
||||
|
||||
A cart is scoped to a sales channel. The Medusa application forms a relation between the `Cart` and `SalesChannel` data models.
|
||||
A cart is scoped to a sales channel. Medusa defines a link module that builds a relationship between the `Cart` and `SalesChannel` data models.
|
||||
|
||||

|
||||

|
||||
@@ -8,7 +8,7 @@ In this document, you’ll learn about tax lines in a cart and how to retrieve t
|
||||
|
||||
## What are Tax Lines?
|
||||
|
||||
A tax line indicates the tax rate of a line item or a shipping method. The `LineItemTaxLine` data model represents a line item’s tax line, and the `ShippingMethodTaxLine` data model represents a shipping method’s tax line.
|
||||
A tax line indicates the tax rate of a line item or a shipping method. The [LineItemTaxLine data model](/references/cart/models/LineItemTaxLine) represents a line item’s tax line, and the [ShippingMethodTaxLine data model](/references/cart/models/ShippingMethodTaxLine) represents a shipping method’s tax line.
|
||||
|
||||

|
||||
|
||||
@@ -34,7 +34,7 @@ The following diagram is a simplified showcase of how a subtotal is calculated f
|
||||
|
||||
## Retrieving Tax Lines
|
||||
|
||||
When using the Cart and Tax modules together, such as in the Medusa application, you can use the `getTaxLines` method of the Tax Module’s main service. It retrieves the tax lines for a cart’s line items and shipping methods.
|
||||
When using the Cart and Tax modules together, you can use the `getTaxLines` method of the Tax Module’s main service. It retrieves the tax lines for a cart’s line items and shipping methods.
|
||||
|
||||
```ts
|
||||
// retrieve the cart
|
||||
|
||||
Reference in new issue
Block a user