* 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
164 lines
3.6 KiB
Plaintext
164 lines
3.6 KiB
Plaintext
import DocCard from '@theme/DocCard'
|
|
import Icons from '@theme/Icon'
|
|
import Tabs from '@theme/Tabs';
|
|
import TabItem from '@theme/TabItem';
|
|
|
|
# Install Pricing Module in Medusa
|
|
|
|
In this document, you'll learn how to install the Pricing module using NPM in the Medusa backend.
|
|
|
|
## Step 1: Install Module
|
|
|
|
To install the Pricing module, run the following command in the root directory of the Medusa backend:
|
|
|
|
```bash npm2yarn
|
|
npm install @medusajs/pricing
|
|
```
|
|
|
|
---
|
|
|
|
## Step 2: Add Module to Configurations
|
|
|
|
In `medusa-config.js`, add the pricing module to the exported object under the `modules` property:
|
|
|
|
```js title=medusa-config.js
|
|
module.exports = {
|
|
// ...
|
|
modules: {
|
|
// ...
|
|
pricingService: {
|
|
resolve: "@medusajs/pricing",
|
|
},
|
|
},
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Step 3: Run Migrations
|
|
|
|
Run the following command to reflect schema changes into your database:
|
|
|
|
```bash
|
|
npx medusa migrations run
|
|
```
|
|
|
|
---
|
|
|
|
## Use the Module
|
|
|
|
You can now start using the module's `PricingModuleService` by resolving it through [dependency injection](../../development/fundamentals/dependency-injection.md).
|
|
|
|
For example:
|
|
|
|
<Tabs groupId="resource-type" isCodeTabs={true}>
|
|
<TabItem value="api-route" label="API Route" attributes={{
|
|
title: "src/api/store/custom/route.ts"
|
|
}} default>
|
|
|
|
```ts
|
|
import type {
|
|
MedusaRequest,
|
|
MedusaResponse
|
|
} from "@medusajs/medusa";
|
|
import {
|
|
PricingModuleService
|
|
} from "@medusajs/pricing"
|
|
|
|
export async function GET(
|
|
req: MedusaRequest,
|
|
res: MedusaResponse
|
|
) {
|
|
const pricingModuleService = req.scope.resolve(
|
|
"pricingModuleService"
|
|
)
|
|
|
|
return res.json({
|
|
pricings: pricingModuleService.list()
|
|
})
|
|
}
|
|
```
|
|
|
|
</TabItem>
|
|
<TabItem value="subscribers" label="Subscribers" attributes={{
|
|
title: "src/subscribers/create-customer.ts"
|
|
}}>
|
|
|
|
```ts
|
|
import {
|
|
type SubscriberConfig,
|
|
type SubscriberArgs,
|
|
PricingService,
|
|
} from "@medusajs/medusa"
|
|
import {
|
|
PricingModuleService
|
|
} from "@medusajs/pricing"
|
|
|
|
export default async function handleListPriceSets({
|
|
data, eventName, container, pluginOptions
|
|
}: SubscriberArgs<Customer>) {
|
|
const pricingModuleService = container.resolve(
|
|
"pricingModuleService"
|
|
)
|
|
|
|
console.log(await pricingModuleService.list())
|
|
}
|
|
|
|
export const config: SubscriberConfig = {
|
|
event: PricingService.Events.CREATED,
|
|
context: {
|
|
subscriberId: "list-pricings"
|
|
}
|
|
}
|
|
```
|
|
|
|
</TabItem>
|
|
<TabItem value="service" label="Service" attributes={{
|
|
title: "src/service/hello.ts"
|
|
}}>
|
|
|
|
```ts
|
|
import { TransactionBaseService } from "@medusajs/medusa"
|
|
import {
|
|
PricingModuleService
|
|
} from "@medusajs/pricing"
|
|
|
|
class HelloService extends TransactionBaseService {
|
|
private pricingModuleService: PricingModuleService
|
|
|
|
constructor(container) {
|
|
super(container)
|
|
this.pricingModuleService = container.pricingModuleService
|
|
}
|
|
|
|
await listPriceSets() {
|
|
return await this.pricingModuleService.list()
|
|
}
|
|
}
|
|
|
|
export default HelloService
|
|
```
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
:::tip
|
|
|
|
In the Examples or API Reference guides, you may see an initialization of the pricing module. This is only necessary if you're using the module outside the Medusa backend.
|
|
|
|
:::
|
|
|
|
---
|
|
|
|
## Up Next
|
|
|
|
<DocCard item={{
|
|
type: 'link',
|
|
href: '/references/pricing',
|
|
label: 'Service Interface Reference',
|
|
customProps: {
|
|
icon: Icons['academic-cap-solid'],
|
|
description: 'Find a full reference of the module\' service interface\s methods.'
|
|
}
|
|
}}
|
|
/> |