* docs: added documentation pages for experimental features * fix content lint issues * fixed lint errors * added migration step * added workflows introduction * add installation guides * added installation guides for modules + generated workflows reference * added missing workflows reference link * Added warning message for experimental features * fix note
123 lines
3.4 KiB
Plaintext
123 lines
3.4 KiB
Plaintext
import DocCard from '@theme/DocCard'
|
||
import Icons from '@theme/Icon'
|
||
|
||
# Pricing Module Overview
|
||
|
||
The Pricing module is the `@medusajs/pricing` NPM package that provides advanced pricing features in your Medusa and Node.js applications. It can be used to add prices to any resource, such as products or shipping options.
|
||
|
||
## Features
|
||
|
||
### Price Management
|
||
|
||
With the Product module, you can store the prices of a resource and manage them through the main interface method. Prices are grouped in a price set, allowing you to add more than one price for a resource based on different conditions, such as currency code.
|
||
|
||
```ts
|
||
const priceSet = await pricingService.create({
|
||
rules: [],
|
||
prices: [
|
||
{
|
||
amount: 500,
|
||
currency_code: "USD",
|
||
rules: {},
|
||
},
|
||
{
|
||
amount: 400,
|
||
currency_code: "EUR",
|
||
min_quantity: 0,
|
||
max_quantity: 4,
|
||
rules: {},
|
||
},
|
||
],
|
||
})
|
||
```
|
||
|
||
### Advanced Rule Engine
|
||
|
||
You can create custom rules and apply them to prices. This gives you more flexibility in how you condition prices, filter them, and ensure the best prices are retrieved for custom contexts.
|
||
|
||
```ts
|
||
const ruleTypes = await pricingService.createRuleTypes([
|
||
{
|
||
name: "Region",
|
||
rule_attribute: "region_id",
|
||
},
|
||
])
|
||
|
||
const priceSet = await pricingService.addPrices({
|
||
priceSetId,
|
||
prices: [
|
||
{
|
||
amount: 500,
|
||
currency_code: "EUR",
|
||
rules: {
|
||
region_id: "PL",
|
||
},
|
||
},
|
||
],
|
||
})
|
||
```
|
||
|
||
### Price Lists
|
||
|
||
Price lists allow you to group prices and apply them only in specific conditions. You can also use them to override existing prices for the specified conditions.
|
||
|
||
```ts
|
||
const priceList = await pricingService.createPriceLists({
|
||
title: "My Sale",
|
||
type: "sale",
|
||
starts_at: Date.parse("01/10/2023"),
|
||
ends_at: Date.parse("31/10/2023"),
|
||
rules: {
|
||
region_id: ["DE", "DK"],
|
||
},
|
||
prices: [
|
||
{
|
||
amount: 400,
|
||
currency_code: "EUR",
|
||
price_set_id: priceSet.id,
|
||
},
|
||
],
|
||
})
|
||
```
|
||
|
||
### Price Calculation Strategy
|
||
|
||
The module’s main interface provides a `calculatePrices` method to retrieve the best price for a given context. You can benefit from your custom rules here to find the best price for the specified rule values.
|
||
|
||
```ts
|
||
const price = await pricingService.calculatePrices(
|
||
{ id: [priceSetId] },
|
||
{
|
||
context: {
|
||
currency_code: "EUR",
|
||
region_id: "PL",
|
||
},
|
||
}
|
||
)
|
||
```
|
||
|
||
---
|
||
|
||
## How to Use the Pricing Module
|
||
|
||
The Pricing Module can be used in many use cases, including:
|
||
|
||
- Medusa Backend: The Medusa backend uses the pricing module to implement some features. However, it's guarded by the [experimental feature flag](../index.md#enabling-experimental-features). If you want to use the pricing module in your backend's customizations, follow [this installation guide](./install-medusa.mdx).
|
||
- Serverless Application: Use the Pricing Module in a serverless application, such as a Next.js application, without having to manage a fully-fledged ecommerce system. You can use it by [installing it in your Node.js project as an NPM package](./install-nodejs.md).
|
||
- Node.js Application: Use the Pricing Module in any Node.js application. Follow [this guide](./install-nodejs.md) to learn how to install it.
|
||
|
||
---
|
||
|
||
## Up Next
|
||
|
||
<DocCard item={{
|
||
type: 'link',
|
||
href: '/experimental/pricing/concepts',
|
||
label: 'Pricing Concepts',
|
||
customProps: {
|
||
icon: Icons['academic-cap-solid'],
|
||
description: 'Learn about the main concepts in the Pricing module.'
|
||
}
|
||
}}
|
||
/>
|