docs: added dividers + see also section (#2899)
This commit is contained in:
@@ -17,6 +17,8 @@ Batch jobs can be used to perform long tasks in the background of your Medusa se
|
||||
|
||||
This documentation helps you learn how to create a batch job strategy. The batch job strategy used in this example changes the status of all draft products to `published`.
|
||||
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### Medusa Components
|
||||
@@ -31,12 +33,16 @@ Redis is required for batch jobs to work. Make sure you [install Redis](../../.
|
||||
|
||||
If you use SQLite during your development, it’s highly recommended that you use PostgreSQL when working with batch jobs. Learn how to [install PostgreSQL](../../../tutorial/0-set-up-your-development-environment.mdx#postgresql) and [configure it with your Medusa server](../../../usage/configurations.md#postgresql-configurations).
|
||||
|
||||
---
|
||||
|
||||
## 1. Create a File
|
||||
|
||||
A batch job strategy is essentially a class defined in a TypeScript or JavaScript file. You should create this file in `src/strategies`.
|
||||
|
||||
Following the example used in this documentation, create the file `src/strategies/publish.ts`.
|
||||
|
||||
---
|
||||
|
||||
## 2. Create Class
|
||||
|
||||
Batch job strategies must extend the abstract class `AbstractBatchJobStrategy` and implement its abstract methods.
|
||||
@@ -63,6 +69,8 @@ class PublishStrategy extends AbstractBatchJobStrategy {
|
||||
export default PublishStrategy
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Define Required Properties
|
||||
|
||||
A batch job strategy class must have two static properties: the `identifier` and `batchType` properties. The `identifier` must be a unique string associated with your batch job strategy, and `batchType` must be the batch job's type.
|
||||
@@ -80,6 +88,8 @@ class PublishStrategy extends AbstractBatchJobStrategy {
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Define Methods
|
||||
|
||||
### (Optional) prepareBatchJobForProcessing
|
||||
@@ -222,6 +232,8 @@ protected async handleProcessingError<T>(batchJobId: string, err: unknown, resul
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Run Build Command
|
||||
|
||||
After you create the batch job and before testing it out, you must run the build command in the directory of your Medusa server:
|
||||
@@ -230,6 +242,8 @@ After you create the batch job and before testing it out, you must run the build
|
||||
npm run build
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Test your Batch Job Strategy
|
||||
|
||||
This section covers how to test and use your batch job strategy. Make sure to start your server first:
|
||||
@@ -410,7 +424,9 @@ The batch job will start processing afterward. Based on the batch job strategy i
|
||||
|
||||
You can [retrieve the batch job](#optional-retrieve-batch-job) at any given point to check its status.
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Learn more about [batch jobs](./index.md).
|
||||
- Learn how to [import products using the Admin API](../../admin/import-products.mdx).
|
||||
## See Also
|
||||
|
||||
- [Batch Jobs Overview](./index.md).
|
||||
- [Import products using the Admin API](../../admin/import-products.mdx).
|
||||
|
||||
@@ -8,6 +8,8 @@ Product Import Strategy is essentially a batch job strategy. Medusa provides the
|
||||
|
||||
Although this documentation specifically targets import strategies, you can use the same steps to overwrite any batch job strategy in Medusa, including export strategies.
|
||||
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### Medusa Components
|
||||
@@ -22,6 +24,8 @@ Redis is required for batch jobs to work. Make sure you [install Redis](../../.
|
||||
|
||||
If you use SQLite during your development, it’s highly recommended that you use PostgreSQL when working with batch jobs. Learn how to [install PostgreSQL](../../../tutorial/0-set-up-your-development-environment.mdx#postgresql) and [configure it with your Medusa server](../../../usage/configurations.md#postgresql-configurations).
|
||||
|
||||
---
|
||||
|
||||
## Overwrite Batch Job Strategy
|
||||
|
||||
The steps required for overwriting a batch job strategy are essentially the same steps required to create a batch job strategy with a minor difference. For that reason, this documentation does not cover the basics of a batch job strategy.
|
||||
@@ -103,13 +107,17 @@ Specifically, since you create batch jobs using the [Create Batch Job](https://d
|
||||
|
||||
If you overwrote the import functionality, you can follow [these steps to learn how to import products using the Admin APIs](../../admin/import-products.mdx).
|
||||
|
||||
---
|
||||
|
||||
## Create Custom Batch Job Strategy
|
||||
|
||||
If you don’t want to overwrite Medusa’s batch job strategy, you can create a custom batch job strategy with a different `batchType` value. Then, use that type when you send a request to [Create a Batch Job](https://docs.medusajs.com/api/admin/#tag/Batch-Job).
|
||||
|
||||
For more details on creating custom batch job strategies, please check out the [Create Batch Job Strategy documentation](create.md).
|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
|
||||
- Learn more about [batch jobs](./index.md).
|
||||
- Learn [how to use the Import Product APIs](../../admin/import-products.mdx).
|
||||
- [Batch Jobs Overview](./index.md).
|
||||
- [Use the Import Product APIs](../../admin/import-products.mdx).
|
||||
|
||||
@@ -26,6 +26,8 @@ A batch job is stored in the database as a [BatchJob](https://docs.medusajs.com/
|
||||
- `count`: A number that includes the total count of records related to the operation. For example, in the case of product exports, it is used to indicate the total number of products exported.
|
||||
- `advancement_count`: A number that indicates the number of records processed so far. Can be helpful when retrying a batch job.
|
||||
|
||||
---
|
||||
|
||||
## What are Batch Job Strategies
|
||||
|
||||
Batch jobs are handled by batch job strategies. A batch job strategy is a class that extends the `AbstractBatchJobStrategy` abstract class and implements the methods defined in that class to handle the different states of a batch job.
|
||||
@@ -34,6 +36,8 @@ A batch job strategy must implement the necessary methods to handle the preparat
|
||||
|
||||
When you create a batch job strategy, the `batchType` class property indicates the batch job types this strategy handles. Then, when you create a new batch job, you set the batch job’s type to the value of `batchType` in your strategy.
|
||||
|
||||
---
|
||||
|
||||
## How Batch Jobs Work
|
||||
|
||||
A batch job’s flow from creation to completion is:
|
||||
@@ -56,6 +60,8 @@ If the batch job fails at any point in this flow, its status is changed to `fail
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
|
||||
- Learn about the [Batch Job’s events](../subscribers/events-list.md#batch-jobs-events).
|
||||
- [Batch Job’s Events Reference](../subscribers/events-list.md#batch-jobs-events).
|
||||
|
||||
@@ -24,7 +24,7 @@ A customer group is stored in the database as a [CustomerGroup](../../../refere
|
||||
|
||||
Similar to all entities in Medusa, you can use the `metadata` object attribute to store any custom data you want. For example, you can add some flag or tag to the customer group for a custom use case:
|
||||
|
||||
```jsx noReport
|
||||
```js noReport
|
||||
metadata: {
|
||||
is_seller: true
|
||||
}
|
||||
@@ -54,7 +54,7 @@ The relation between the `PriceList` and `CustomerGroup` entities is available o
|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
## See Also
|
||||
|
||||
- Learn [how to manage customer groups using the Admin APIs](../../admin/use-customergroups-api.mdx).
|
||||
- Learn more about [Price Lists and how they work](../price-lists/index.md).
|
||||
- [Manage customer groups using the Admin APIs](../../admin/use-customergroups-api.mdx).
|
||||
- [Price Lists Overview](../price-lists/index.md).
|
||||
|
||||
@@ -26,6 +26,8 @@ When you run the Medusa server, a container of the type `MedusaContainer` is cre
|
||||
|
||||
The server then registers all important resources in the container, which makes them accessible in classes and endpoints.
|
||||
|
||||
---
|
||||
|
||||
## Registered Resources
|
||||
|
||||
The Medusa server scans the core Medusa package, plugins, and your files in the `dist` directory and registers the following resources:
|
||||
@@ -550,6 +552,8 @@ Its camel-case name.
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Loading Resources
|
||||
|
||||
This section covers how to load resources that the Medusa server registers when it starts running.
|
||||
@@ -560,7 +564,7 @@ To load resources, such as services, in endpoints, use the `req.scope.resolve` f
|
||||
|
||||
For example:
|
||||
|
||||
```typescript
|
||||
```ts
|
||||
const logger = req.scope.resolve('logger');
|
||||
```
|
||||
|
||||
@@ -572,7 +576,7 @@ In classes such as services, strategies, or subscribers, you can load resources
|
||||
|
||||
For example:
|
||||
|
||||
```typescript
|
||||
```ts
|
||||
import { OrderService } from '@medusajs/medusa';
|
||||
|
||||
class OrderSubscriber {
|
||||
@@ -584,7 +588,9 @@ class OrderSubscriber {
|
||||
}
|
||||
```
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Learn [how to create services](../services/create-service.md).
|
||||
- Learn [how to create subscribers](../subscribers/create-subscriber.md).
|
||||
## See Also
|
||||
|
||||
- [Create services](../services/create-service.md).
|
||||
- [Create subscribers](../subscribers/create-subscriber.md).
|
||||
|
||||
@@ -98,7 +98,7 @@ Based on the value of `type`, one of the following relations can be used to retr
|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
## See Also
|
||||
|
||||
- Learn [how to create a discount using the admin APIs](../../admin/manage-discounts.mdx)
|
||||
- Learn [how to use discounts on the storefront](../../storefront/use-discounts-in-checkout.mdx)
|
||||
- [Create a discount using the admin APIs](../../admin/manage-discounts.mdx)
|
||||
- [Use discounts on the storefront](../../storefront/use-discounts-in-checkout.mdx)
|
||||
|
||||
@@ -6,6 +6,8 @@ In this document, you’ll learn how to create endpoints in your Medusa server.
|
||||
|
||||
Custom endpoints reside under the `src/api` directory in your Medusa Backend. They're defined in a TypeScript or JavaScript file that is named `index` (for example, `index.ts`). This file should export a function that returns an Express router.
|
||||
|
||||
---
|
||||
|
||||
## Implementation
|
||||
|
||||
To create a new endpoint, start by creating a new file in `src/api` called `index.ts`. At its basic format, `index.ts` should look something like this:
|
||||
@@ -42,6 +44,8 @@ By Medusa’s conventions:
|
||||
|
||||
You can also create endpoints that don't reside under these two prefixes, similar to the `hello` endpoint in the previous example.
|
||||
|
||||
---
|
||||
|
||||
## CORS Configuration
|
||||
|
||||
If you’re adding a storefront or admin endpoint and you want to access these endpoints from the storefront or Medusa admin, you need to pass your endpoints Cross-Origin Resource Origin (CORS) options using the `cors` package.
|
||||
@@ -94,6 +98,8 @@ router.get("/admin/hello", cors(corsOptions), (req, res) => {
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Create Multiple Endpoints
|
||||
|
||||
### Same File
|
||||
@@ -185,6 +191,8 @@ export default () => {
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Protected Routes
|
||||
|
||||
Protected routes are routes that should be accessible by logged-in customers or users only.
|
||||
@@ -238,6 +246,8 @@ router.get("/admin/products/count", cors(corsOptions), authenticate(), async (re
|
||||
|
||||
Now, only authenticated users can access this endpoint.
|
||||
|
||||
---
|
||||
|
||||
## Use Services
|
||||
|
||||
Services in Medusa bundle a set of functionalities into one class. Then, you can use that class anywhere in your backend. For example, you can use the `ProductService` to retrieve products or perform operations like creating or updating a product.
|
||||
@@ -260,6 +270,8 @@ router.get("/admin/products/count", cors(corsOptions), authenticate(), (req, res
|
||||
|
||||
The `productService` has a `count` method that returns a Promise. This Promise resolves to the count of the products. You return a JSON of the product count.
|
||||
|
||||
---
|
||||
|
||||
## Building Files
|
||||
|
||||
Custom endpoints must be transpiled and moved to the `dist` directory. This happens when you run your server using `medusa develop` and while it’s running, and when you run the following command:
|
||||
@@ -268,7 +280,10 @@ Custom endpoints must be transpiled and moved to the `dist` directory. This happ
|
||||
npm run build
|
||||
```
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Check out the available [Admin](https://docs.medusajs.com/api/admin/) and [Storefront](https://docs.medusajs.com/api/store/) APIs.
|
||||
- Learn how to create a [Service](./../services/create-service.md).
|
||||
## See Also
|
||||
|
||||
- [Storefront API Reference](/api/store)
|
||||
- [Admin API Reference](/api/admin)
|
||||
- [Create a Service](./../services/create-service.md).
|
||||
|
||||
@@ -69,6 +69,8 @@ Be careful with your file names as it can cause unclear errors in Typeorm. Make
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## Access a Custom Entity
|
||||
|
||||
:::note
|
||||
@@ -125,8 +127,10 @@ To delete soft-deletable entities that extend the `SoftDeletableEntity` class, y
|
||||
await postRepository.softDelete(post.id);
|
||||
```
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Check out Medusa's entities in the [Entities' reference](../../../references/entities/classes/Address.md).
|
||||
- Learn about [migrations](../migrations/overview.md).
|
||||
- Learn more about [Services](../services/create-service.md) and how to use them.
|
||||
## See Also
|
||||
|
||||
- [Entities' reference](../../../references/entities/classes/Address.md)
|
||||
- [Migrations Overview](../migrations/overview.md)
|
||||
- [Create a Services](../services/create-service.md)
|
||||
|
||||
@@ -10,13 +10,17 @@ Aside from Medusa’s core entities, you can also create your own entities to us
|
||||
|
||||
Entities are TypeScript files and they are based on [Typeorm’s Entities](https://typeorm.io/entities) and use Typeorm decorators.
|
||||
|
||||
---
|
||||
|
||||
## Base Entities
|
||||
|
||||
All entities must extend either the `BaseEntity` or `SoftDeletableEntity` classes. The `BaseEntity` class holds common columns including the `id`, `created_at`, and `updated_at` columns.
|
||||
|
||||
The `SoftDeletableEntity` class extends the `BaseEntity` class and adds another column `deleted_at`. If an entity can be soft deleted, meaning that a row in it can appear to the user as deleted but still be available in the database, it should extend `SoftDeletableEntity`.
|
||||
|
||||
## What's Next
|
||||
---
|
||||
|
||||
- Learn [how to create an entity](./index.md).
|
||||
- Check out Medusa's entities in the [Entities' reference](../../../references/entities/classes/Address.md).
|
||||
## See Also
|
||||
|
||||
- [Create an entity](./index.md)
|
||||
- [Entities' reference](../../../references/entities/classes/Address.md)
|
||||
@@ -8,6 +8,8 @@ Feature flags are used in Medusa to guard beta features that aren’t ready for
|
||||
|
||||
To use these beta features, you must enable their feature flags.
|
||||
|
||||
---
|
||||
|
||||
## Available Feature Flags
|
||||
|
||||
You can view a list of available feature flags that you can toggle in [the Medusa GitHub mono-repository](https://github.com/medusajs/medusa/tree/master/packages/medusa/src/loaders/feature-flags). In each feature flag file, you can find the default value of the feature flag, its name, environment variable name, and more.
|
||||
@@ -18,6 +20,8 @@ If a feature flag is enabled/disabled by default, you don’t need to manually e
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## Enable Feature Flags
|
||||
|
||||
:::caution
|
||||
@@ -73,6 +77,8 @@ You can learn more about migrations in this documentation.
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## Disable Feature Flags
|
||||
|
||||
Disabling feature flags follows the same process as enabling the feature flags. All you have to do is change the value in the environment variables or the server settings to `false`.
|
||||
@@ -85,7 +91,9 @@ If you had the feature flag previously enabled, and you want to disable this fea
|
||||
|
||||
You can follow [this documentation to learn how to revert the last migration you ran](https://docs.medusajs.com/cli/reference#migrations).
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Learn more about [Migrations](../migrations/overview.md).
|
||||
- Learn how to [configure your Medusa server](../../../usage/configurations.md).
|
||||
## See Also
|
||||
|
||||
- [Migrations Overview](../migrations/overview.md).
|
||||
- [Configure your Medusa server](../../../usage/configurations.md).
|
||||
|
||||
@@ -20,12 +20,16 @@ You can alternatively use Typeorm's `generate` command to generate a Migration f
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## Write Migration File
|
||||
|
||||
The migration file contains the necessary commands to create the database columns, foreign keys, and more.
|
||||
|
||||
You can learn more about writing the migration file in You can learn more about writing migrations in [Typeorm’s Documentation](https://typeorm.io/migrations).
|
||||
|
||||
---
|
||||
|
||||
## Build Files
|
||||
|
||||
Before you can run the migrations you need to run the build command to transpile the TypeScript files to JavaScript files:
|
||||
@@ -34,6 +38,8 @@ Before you can run the migrations you need to run the build command to transpile
|
||||
npm run build
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Run Migration
|
||||
|
||||
The last step is to run the migration with the command detailed earlier
|
||||
@@ -44,6 +50,8 @@ medusa migrations run
|
||||
|
||||
If you check your database now you should see that the change defined by the migration has been applied successfully.
|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
|
||||
- Learn more about [setting up your development server](../../../tutorial/0-set-up-your-development-environment.mdx).
|
||||
- [Set up your development server](../../../tutorial/0-set-up-your-development-environment.mdx).
|
||||
|
||||
@@ -22,6 +22,8 @@ Migrations are used to apply changes to the database schema. However, there are
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## How to Run Migrations
|
||||
|
||||
Migrations in Medusa can be done in one of two ways:
|
||||
@@ -48,7 +50,9 @@ npm run seed
|
||||
|
||||
This will use the underlying `seed` command provided by Medusa's CLI to seed your database with data from the file `data/seed.json` on your Medusa server.
|
||||
|
||||
## What's Next
|
||||
---
|
||||
|
||||
- Learn [how to create a migration](index.md)
|
||||
- Learn more about [setting up your development server](../../../tutorial/set-up-your-development-environment).
|
||||
## See Also
|
||||
|
||||
- [Create a migration](index.md)
|
||||
- [Set up your development environment](../../../tutorial/set-up-your-development-environment)
|
||||
|
||||
@@ -14,6 +14,8 @@ Before you start creating a Notification Provider, you need to install a [Medusa
|
||||
|
||||
You also need to [setup Redis](../../../tutorial/0-set-up-your-development-environment.mdx#redis) and [configure it with the Medusa server](../../../usage/configurations.md#redis).
|
||||
|
||||
---
|
||||
|
||||
## Create a Notification Provider
|
||||
|
||||
Creating a Notification Provider is as simple as creating a TypeScript or JavaScript file in `src/services`. The name of the file is the name of the provider (for example, `sendgrid.ts`). A Notification Provider is essentially a Service that extends the `AbstractNotificationService` from `@medusajs/medusa`.
|
||||
@@ -205,6 +207,8 @@ The `to` and `data` properties are used in the `NotificationService` in Medusa
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## Create a Subscriber
|
||||
|
||||
After creating your Notification Provider Service, you must create a Subscriber that registers this Service as a notification handler of events.
|
||||
@@ -235,6 +239,8 @@ Notice that the value of the `identifier` static property defined in the `EmailS
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## Test Sending Notifications with your Notification Provider
|
||||
|
||||
Make sure you've configured Redis with your Medusa server as explained in the Prerequisites section and that the Redis service is running.
|
||||
@@ -255,6 +261,8 @@ If you don’t have a storefront installed you can get started with either the [
|
||||
|
||||
After placing an order, you can see in your console the message “Notification Sent”. If you added your own notification sending logic, you should receive an email or alternatively the type of notification you’ve set up.
|
||||
|
||||
---
|
||||
|
||||
## Test Resending Notifications with your Notification Provider
|
||||
|
||||
To test resending a notification, first, retrieve the ID of the notification you just sent using the [List Notifications admin endpoint](https://docs.medusajs.com/api/admin/#tag/Notification/operation/GetNotifications). You can pass as a body parameter the `to` or `event_name` parameters to filter out the notification you just sent.
|
||||
@@ -273,9 +281,12 @@ Then, send a request to the [Resend Notification](https://docs.medusajs.com/api/
|
||||
|
||||
This request returns the same notification object as the List Notifications endpoint, but it now has a new object in the `resends` array. This is the resent notification. If you supplied a `to` parameter in the request body, you should see its value in the `to` property of the resent notification object.
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Check out the [list of events](../subscribers/events-list.md) you can listen to.
|
||||
- Check out the [SendGrid](../../../add-plugins/sendgrid.mdx) plugin for easy integration of email notifications.
|
||||
- Learn how to [create your own plugin](../plugins/create.md).
|
||||
- Learn more about [Subscribers](../subscribers/create-subscriber.md) and [Services](../services/create-service.md).
|
||||
## See Also
|
||||
|
||||
- [Events reference](../subscribers/events-list.md)
|
||||
- [SendGrid Plugin](../../../add-plugins/sendgrid.mdx)
|
||||
- [Create a Subscriber](../subscribers/create-subscriber.md)
|
||||
- [Create a Service](../services/create-service.md).
|
||||
- [Create a Plugin](../plugins/create.md).
|
||||
|
||||
@@ -8,6 +8,8 @@ Medusa provides a Notification API to mainly handle sending and resending notifi
|
||||
|
||||
The Notification architecture is made up of two main components: the Notification Provider and the Notification. Simply put, the Notification Provider handles the sending and resending of a Notification.
|
||||
|
||||
---
|
||||
|
||||
## Notification Provider
|
||||
|
||||
A Notification Provider is a provider that handles sending and resending of notifications. You can either create and integrate your own provider or install a Notification Provider through a third-party plugin.
|
||||
@@ -32,6 +34,8 @@ The `NotificationProvider` entity only has 2 attributes: `id` and `is_installed`
|
||||
|
||||
If you installed a Notification provider and then removed the Service files or plugin that registered the Notification Provider, the Notification Provider remains in your database, but the value of the `is_installed` field changes to `false`.
|
||||
|
||||
---
|
||||
|
||||
## Notification
|
||||
A notification is a form of an alert sent to the customers or users to inform them of an action that has occurred. For example, if an order is placed, the notification, in this case, can be an email that confirms their order and lists the order details.
|
||||
|
||||
@@ -67,6 +71,8 @@ You can also access the specific resource using the `resource_id` property, whic
|
||||
|
||||
The `Notification` entity also includes properties related to the receiver of the Notification. In case the receiver is a customer, the `customer_id` property is used to identify which customer.
|
||||
|
||||
---
|
||||
|
||||
## Automating Flows with Notifications
|
||||
|
||||
With Medusa you can create notifications as a reaction to a wide spectrum of events, allowing you to automate communication and processes.
|
||||
@@ -78,10 +84,13 @@ An example of a flow that can be implemented using Medusa's Notification API is
|
||||
- The customer returns the items triggering the `return.recieved` event.
|
||||
- The Notification Provider listens to the `return.received` event and sends an email to the customer with confirmation that their items have been received and that a refund has been issued.
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
## See Also
|
||||
|
||||
- [Create a Notification Provider](how-to-create-notification-provider.md)
|
||||
- [Events reference](../subscribers/events-list.md)
|
||||
- [SendGrid Plugin](../../../add-plugins/sendgrid.mdx)
|
||||
- [Subscribers Overview](../subscribers/create-subscriber.md)
|
||||
- [Services Overview](../services/create-service.md)
|
||||
|
||||
- Learn how to [create your own Notification Provider](how-to-create-notification-provider.md).
|
||||
- Check out the [list of events](../subscribers/events-list.md) in Medusa.
|
||||
- Check the [`NotificationService`](../../../references/services/classes/NotificationService.md) API reference for more details on how it works.
|
||||
- Check out the [SendGrid](../../../add-plugins/sendgrid.mdx) Notification plugin.
|
||||
- Learn more about [Subscribers](../subscribers/create-subscriber.md) and [Services](../services/create-service.md) in Medusa.
|
||||
|
||||
@@ -42,6 +42,8 @@ These methods are used at different points in the Checkout flow as well as when
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Create a Payment Provider
|
||||
|
||||
The first step to create a payment provider is to create a JavaScript or TypeScript file in `src/services`. The file's name should be the name of the payment provider.
|
||||
@@ -414,6 +416,8 @@ async cancelPayment(payment: Payment): Promise<Data> {
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Optional Methods
|
||||
|
||||
### retrieveSavedMethods
|
||||
@@ -457,7 +461,9 @@ async retrieveSavedMethods(customer: Customer): Promise<Data[]> {
|
||||
}
|
||||
```
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Check out the Payment Providers for [Stripe](https://github.com/medusajs/medusa/tree/2e6622ec5d0ae19d1782e583e099000f0a93b051/packages/medusa-payment-stripe) and [PayPal](https://github.com/medusajs/medusa/tree/2e6622ec5d0ae19d1782e583e099000f0a93b051/packages/medusa-payment-paypal) for implementation examples.
|
||||
- Learn more about the [frontend checkout flow](./../../storefront/how-to-implement-checkout-flow.mdx).
|
||||
## See Also
|
||||
|
||||
- Implementation Examples: [Stripe](https://github.com/medusajs/medusa/tree/2e6622ec5d0ae19d1782e583e099000f0a93b051/packages/medusa-payment-stripe) and [PayPal](https://github.com/medusajs/medusa/tree/2e6622ec5d0ae19d1782e583e099000f0a93b051/packages/medusa-payment-paypal) payment providers.
|
||||
- [Implement checkout flow on the storefront](./../../storefront/how-to-implement-checkout-flow.mdx).
|
||||
|
||||
@@ -14,6 +14,8 @@ In Medusa, there are 3 main components in the payment architecture: Payment Prov
|
||||
|
||||
An important part in the Payment architecture to understand is the **Idempotency Key**. It’s a unique value that’s generated for a cart and is used to retry payments during checkout if they fail.
|
||||
|
||||
---
|
||||
|
||||
## Payment Provider
|
||||
|
||||
A Payment Provider in Medusa is a method to handle payments in selected regions. It is not associated with a cart, customer, or order in particular. It provides the necessary implementation to create Payment Sessions and Payments, as well as authorize and capture payments, among other functionalities.
|
||||
@@ -42,6 +44,8 @@ It’s important to choose a payment provider in the list of payment providers i
|
||||
|
||||
The [`PaymentProvider`](../../../references/entities/classes/PaymentProvider.md) entity only has 2 attributes: `is_installed` to indicate if the payment provider is installed and its value is a boolean; and `id` which is the unique identifier that you define in the Payment Provider service.
|
||||
|
||||
---
|
||||
|
||||
## Payment Session
|
||||
|
||||
Payment Sessions are linked to a customer’s cart. Each Payment Session is associated with a payment provider that is available in the customer cart’s region.
|
||||
@@ -80,6 +84,8 @@ The `status` attributes indicates the current status of the Payment Session. It
|
||||
|
||||
These statuses are important in the checkout flow to determine the current step the customer is at and which action should come next. For example, if there is an attempt to place the order but the status of the Payment Session is not `authorized`, an error will be thrown.
|
||||
|
||||
---
|
||||
|
||||
## Payment
|
||||
|
||||
A Payment is used to represent the amount authorized for a customer’s purchase. It is associated with the order placed by the customer and will be used after that for all operations related to the order’s payment such as capturing or refunding the payment.
|
||||
@@ -104,6 +110,8 @@ Similar to `PaymentSession`, `Payment` has a `data` attribute which is an objec
|
||||
|
||||
Additionally, `Payment` has the `captured_at` date-time attribute which is filled when the payment has been captured, and a `canceled_at` date-time attribute which is filled when the order has been canceled.
|
||||
|
||||
---
|
||||
|
||||
## Idempotency Key
|
||||
|
||||
An Idempotency Key is a unique key associated with a cart. It is generated at the last step of checkout before authorization of the payment is attempted.
|
||||
@@ -118,7 +126,9 @@ If then the request is interrupted for any reason or the payment fails, the clie
|
||||
|
||||
This prevents any payment issues from occurring with the customers and allows for secure retries of failed payments or interrupted connections.
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- [Check out how the checkout flow is implemented on the frontend.](./../../storefront/how-to-implement-checkout-flow.mdx)
|
||||
- Check out payment plugins like [Stripe](../../../add-plugins/stripe.md), [Paypal](/add-plugins/paypal), and [Klarna](../../../add-plugins/klarna.md).
|
||||
## See Also
|
||||
|
||||
- [Create a Payment Provider](./how-to-create-payment-provider.md)
|
||||
- [Implement the checkout flow in the storefront](./../../storefront/how-to-implement-checkout-flow.mdx)
|
||||
|
||||
@@ -16,6 +16,8 @@ If you run into any errors while installing the CLI tool, check out the [trouble
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## Initialize Project
|
||||
|
||||
The recommended way to create a plugin is using the Medusa CLI. Run the following command to create a new Medusa project:
|
||||
@@ -28,6 +30,8 @@ Where `medusa-plugin-custom` is the name of the plugin you’re creating. In Med
|
||||
|
||||
By convention, all plugin names start with `medusa` followed by a descriptive name of what the plugin does. For example, the Stripe plugin is named `medusa-payment-stripe`.
|
||||
|
||||
---
|
||||
|
||||
## Changes to package.json
|
||||
|
||||
### Rename Project Name
|
||||
@@ -145,6 +149,8 @@ npm install --save-dev cross-env
|
||||
- `repository`: The repository that holds your plugin’s codebase.
|
||||
- `keywords`: This should hold the keywords that are related to your plugin. It’s recommended that all plugins use the keywords `medusa-plugin` or `medusa`.
|
||||
|
||||
---
|
||||
|
||||
## Develop your Plugin
|
||||
|
||||
Now, You can start developing your plugin. This can include adding services, endpoints, entities, or anything that's relevant to your plugin.
|
||||
@@ -196,6 +202,8 @@ This guide doesn't cover how to create different files and components. If you’
|
||||
- How to [create an entity](./../entities/index.md)
|
||||
- How to [create a migration](../migrations/index.md)
|
||||
|
||||
---
|
||||
|
||||
## Add Plugin Configuration
|
||||
|
||||
Plugins often allow developers that will later use them to enter their own configuration. For example, you can allow developers to specify the API key of a service you’re integrating.
|
||||
@@ -248,6 +256,8 @@ Make sure to include in the README of your plugin the configurations that can be
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## Test Your Plugin
|
||||
|
||||
While you develop your plugin, you’ll need to test it on an actual Medusa server. This can be done by using the [npm link](https://docs.npmjs.com/cli/v8/commands/npm-link) command.
|
||||
@@ -354,6 +364,8 @@ It is safe to ignore any `cross-env: command not found` error you may receive.
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## NPM Ignore File
|
||||
|
||||
Not all files that you use while developing your plugin are necessary to be published.
|
||||
@@ -387,6 +399,8 @@ medusa-db.sql
|
||||
develop.sh
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Publish Plugin
|
||||
|
||||
Once you’re done developing your plugin you can publish the package on NPM’s registry so that other developers can benefit from it and use it.
|
||||
@@ -439,6 +453,8 @@ Then, publish the new update:
|
||||
npm publish
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Add Plugin to Medusa’s Repository
|
||||
|
||||
All officially-supported plugins are available in the [`packages` directory of the Medusa GitHub repository](https://github.com/medusajs/medusa/tree/master/packages).
|
||||
@@ -451,6 +467,8 @@ Before contributing to the Medusa repository, please check out the [contribution
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## Install a Plugin
|
||||
|
||||
To install any published plugin, you can run the following command on any Medusa server project:
|
||||
@@ -459,8 +477,10 @@ To install any published plugin, you can run the following command on any Medusa
|
||||
npm install medusa-plugin-custom
|
||||
```
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Check out [available Services in Medusa](references/services/../../../../../references/services/classes/AuthService.md) that you can use in your plugin.
|
||||
- Check out [available events](../subscribers/events-list.md) that you can listen to in Subscribers.
|
||||
- Check out [available official plugins](https://github.com/medusajs/medusa/tree/master/packages).
|
||||
## See Also
|
||||
|
||||
- [Available official plugins](https://github.com/medusajs/medusa/tree/master/packages)
|
||||
- [Services reference](references/services/../../../../../references/services/classes/AuthService.md)
|
||||
- [Events reference](../subscribers/events-list.md)
|
||||
|
||||
@@ -14,6 +14,8 @@ An alternative approach is developing a custom way of handling payment on your e
|
||||
|
||||
Plugins run within the same process as the core Medusa server eliminating the need for extra server capacity, infrastructure, and maintenance. As a result, plugins can use all other services as dependencies and access the database.
|
||||
|
||||
---
|
||||
|
||||
## Using Existing Plugins
|
||||
|
||||
### Official Plugins
|
||||
@@ -48,7 +50,9 @@ If you’re installing an official plugin from the Medusa repository, you can fi
|
||||
|
||||
For community plugins, please refer to the installation instructions of that plugin to learn about any required configurations.
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Learn how to [create your own plugin](create.md).
|
||||
- Learn how to [create a fulfillment provider](../shipping/add-fulfillment-provider.md) or a [payment provider](../payment/how-to-create-payment-provider.md).
|
||||
## See Also
|
||||
|
||||
- [Create your own plugin](create.md)
|
||||
- [Create a fulfillment provider](../shipping/add-fulfillment-provider.md) or a [payment provider](../payment/how-to-create-payment-provider.md)
|
||||
|
||||
@@ -81,7 +81,7 @@ Since the line item belongs to a cart, there’s no need to pass the `region_id`
|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
## See Also
|
||||
|
||||
- Learn more about [price selection strategies](../price-selection-strategy/index.md).
|
||||
- Learn [how to use the PriceList Admin APIs](./use-api.mdx).
|
||||
- [Price Selection Strategy Overview](../price-selection-strategy/index.md).
|
||||
- [Use the PriceList Admin APIs](./use-api.mdx).
|
||||
|
||||
@@ -474,7 +474,7 @@ This request returns the ID of the deleted price list.
|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
## See Also
|
||||
|
||||
- Learn more about [price lists](./index.md).
|
||||
- Learn how the [price selection strategy works](../price-selection-strategy/index.md).
|
||||
- [Price Lists Overview](./index.md).
|
||||
- [Price Selection Strategy Overview](../price-selection-strategy/index.md).
|
||||
|
||||
@@ -60,7 +60,7 @@ The context that is passed to the `calculateVariantPrice` method is an object th
|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
## See Also
|
||||
|
||||
- Learn [how to override the price selection strategy](./override.md).
|
||||
- Learn more about [price lists](./../price-lists/index.md).
|
||||
- [Override the Price Selection Strategy](./override.md)
|
||||
- [Price Lists Overview](./../price-lists/index.md)
|
||||
|
||||
@@ -114,6 +114,6 @@ Then, try out your strategy using any of the [Products](https://docs.medusajs.co
|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
## See Also
|
||||
|
||||
- Learn more about [price list selection strategy](./index.md).
|
||||
- [Price List Selection Strategy Overview](./index.md)
|
||||
|
||||
@@ -111,7 +111,7 @@ The relation between the `Region` and `TaxRate` entities is available on both en
|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
## See Also
|
||||
|
||||
- Learn [how to use regions in a storefront using the store REST APIs](../../storefront/use-regions.mdx).
|
||||
- Learn how to [manage regions using the admin REST APIs](../../admin/manage-regions.mdx).
|
||||
- [Use Regions in a storefront](../../storefront/use-regions.mdx).
|
||||
- [Use Regions in the admin](../../admin/manage-regions.mdx).
|
||||
|
||||
@@ -68,7 +68,7 @@ The relation is implemented in the [Order](../../../references/entities/classes/
|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
## See Also
|
||||
|
||||
- Learn how to [manage Sales Channels using the Admin APIs](./manage-admin.mdx).
|
||||
- Check out the [Sales Channel’s Admin APIs](https://docs.medusajs.com/api/admin/#tag/Sales-Channel).
|
||||
- [Manage Sales Channels using the Admin APIs](./manage-admin.mdx)
|
||||
- [Sales Channel’s Admin APIs Reference](/api/admin/#tag/Sales-Channel)
|
||||
|
||||
@@ -530,6 +530,6 @@ The request returns an array of orders that are associated with the specified sa
|
||||
|
||||
---
|
||||
|
||||
## What’s Next
|
||||
## See Also
|
||||
|
||||
- Learn more about [Sales Channels and how they work](./index.md).
|
||||
- [Sales Channels Overview](./index.md).
|
||||
@@ -8,6 +8,8 @@ Medusa allows you to create scheduled jobs that run at specific times during you
|
||||
|
||||
This guide explains how to create a scheduled job on your Medusa server. The scheduled job in this example will simply change the status of draft products to `published`.
|
||||
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### Medusa Components
|
||||
@@ -18,6 +20,8 @@ It is assumed that you already have a Medusa server installed and set up. If not
|
||||
|
||||
Redis is required for scheduled jobs to work. Make sure you [install Redis](../../../tutorial/0-set-up-your-development-environment.mdx#redis) and [configure it with your Medusa server](../../../usage/configurations.md#redis).
|
||||
|
||||
---
|
||||
|
||||
## 1. Create a File
|
||||
|
||||
Each scheduled job should reside in a TypeScript or JavaScript file under the `src/loaders` directory.
|
||||
@@ -26,6 +30,8 @@ Start by creating the `src/loaders` directory. Then, inside that directory, crea
|
||||
|
||||
For the example in this tutorial, you can create the file `src/loaders/publish.ts`.
|
||||
|
||||
---
|
||||
|
||||
## 2. Create Cron Job
|
||||
|
||||
To create a scheduled job, add the following code in the file you created, which is `src/loaders/publish.ts` in this example:
|
||||
@@ -89,6 +95,8 @@ jobSchedulerService.create("publish-products", {
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Run Medusa Server
|
||||
|
||||
:::info
|
||||
@@ -129,6 +137,8 @@ To test the previous example out instantly, you can change the scheduled job exp
|
||||
|
||||
:::
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Learn more about [services and how you can use them](../services/overview.md).
|
||||
## See Also
|
||||
|
||||
- [Services Overview](../services/overview.md).
|
||||
|
||||
@@ -23,6 +23,8 @@ class HelloService extends TransactionBaseService {
|
||||
export default HelloService
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Service Constructor
|
||||
|
||||
As the service extends the `TransactionBaseService` class, all services in Medusa’s core, as well as all your custom services, will be available in your service’s constructor using dependency injection.
|
||||
@@ -46,6 +48,8 @@ async getProductCount() {
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Use a Service
|
||||
|
||||
In this section, you'll learn how to use services throughout your Medusa server. This includes both Medusa's services and your custom services.
|
||||
@@ -93,7 +97,9 @@ constructor({ helloService, eventBusService }) {
|
||||
}
|
||||
```
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Check out the [Services Reference](/references/services/classes/AuthService) to see a list of all services in Medusa.
|
||||
- [Learn How to Create an Endpoint.](../endpoints/add.md)
|
||||
## See Also
|
||||
|
||||
- [Services Reference](/references/services/classes/AuthService)
|
||||
- [Create an Endpoint](../endpoints/add.md)
|
||||
|
||||
@@ -18,7 +18,9 @@ For example, if the file name is `hello.ts`, the service will be registered as `
|
||||
|
||||
The registration name of the service is important, as you’ll be referring to it when you want to get access to the service using dependency injection or in routes.
|
||||
|
||||
## What's Next
|
||||
---
|
||||
|
||||
- Learn [how to create a service](./create-service.md)
|
||||
- Check out the [Services Reference](/references/services/classes/AuthService) to see a list of all services in Medusa.
|
||||
## See Also
|
||||
|
||||
- [Create a Service](./create-service.md)
|
||||
- [Services Reference](/references/services/classes/AuthService)
|
||||
|
||||
@@ -19,6 +19,8 @@ Also, the fulfillment provider class should have a static property `identifier`.
|
||||
|
||||
Fulfillment providers are loaded and installed on the server startup.
|
||||
|
||||
---
|
||||
|
||||
## Create a Fulfillment Provider
|
||||
|
||||
The first step is to create a JavaScript or TypeScript file under `src/services`. For example, create the file `src/services/my-fulfillment.ts` with the following content:
|
||||
@@ -269,7 +271,8 @@ cancelFulfillment(fulfillment) {
|
||||
}
|
||||
```
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Check out the [Webshipper plugin](https://github.com/medusajs/medusa/tree/cab5821f55cfa448c575a20250c918b7fc6835c9/packages/medusa-fulfillment-webshipper) for an example of a fulfillment provider that interacts with a third-party providers.
|
||||
- Check out the [manual fulfillment plugin](https://github.com/medusajs/medusa/tree/cab5821f55cfa448c575a20250c918b7fc6835c9/packages/medusa-fulfillment-manual) for a basic implementation of a fulfillment provider.
|
||||
## See Also
|
||||
|
||||
- Example Implementations: [Webshipper plugin](https://github.com/medusajs/medusa/tree/cab5821f55cfa448c575a20250c918b7fc6835c9/packages/medusa-fulfillment-webshipper) and the [manual fulfillment plugin](https://github.com/medusajs/medusa/tree/cab5821f55cfa448c575a20250c918b7fc6835c9/packages/medusa-fulfillment-manual)
|
||||
|
||||
@@ -10,6 +10,8 @@ The distinction between the four is important. It has been carefully planned and
|
||||
|
||||
It’s also constructed to support multiple regions, provide different shipment configurations and options for different product types, provide promotional shipments for your customers, and much more.
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
- **Fulfillment Provider:** Fulfillment providers are plugins or [Services](../services/create-service.md) used to ship the products to your customers, whether physically or virtually. An example of a fulfillment provider would be FedEx.
|
||||
@@ -19,6 +21,8 @@ It’s also constructed to support multiple regions, provide different shipment
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Fulfillment Provider
|
||||
|
||||
A Fulfillment Provider in Medusa is a method to handle shipping products in selected regions. It is not associated with a cart, customer, or order in particular.
|
||||
@@ -43,6 +47,8 @@ Once the Fulfillment Provider is added to the server, the store operator will be
|
||||
|
||||
The [`FulfillmentProvider`](../../../references/entities/classes/FulfillmentProvider.md) entity only has 2 attributes: `is_installed` to indicate if the fulfillment provider is installed and its value is a boolean; and `id` which is the unique identifier that you define in the Fulfillment Provider Service.
|
||||
|
||||
---
|
||||
|
||||
## Shipping Profile
|
||||
|
||||
Shipping profiles are the highest in the hierarchy in the shipping architecture.
|
||||
@@ -69,6 +75,8 @@ The `ShippingProfile` has a `type` attribute that can be `default`, `gift_ca
|
||||
|
||||
The `ShippingProfile` entity also has an array of `ShippingOption` instances.
|
||||
|
||||
---
|
||||
|
||||
## Shipping Option
|
||||
|
||||
After the admin adds a shipping profile, they can add shipping options that belong to that shipping profile from the admin dashboard.
|
||||
@@ -105,6 +113,8 @@ The `data` attribute is used to specify any data necessary for fulfilling the
|
||||
|
||||
The `data` attribute does not have any specific format. It’s up to you to choose whatever data is included here.
|
||||
|
||||
---
|
||||
|
||||
## Shipping Method
|
||||
|
||||
Unlike the previous two components, a shipping method is not created by the admin. It’s created when a `POST` request is sent to `/store/carts/:id/shipping-methods` after the customer chooses a shipping option.
|
||||
@@ -135,7 +145,9 @@ The `ShippingMethod` also belongs to the `Order` entity. This association is
|
||||
|
||||
The `ShippingMethod` instance holds a `price` attribute, which will either be the flat rate price or the calculated price.
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- [Learn how to Create a Fulfillment Provider.](./add-fulfillment-provider.md)
|
||||
- Check out [available shipping plugins](https://github.com/medusajs/medusa/tree/master/packages).
|
||||
## See Also
|
||||
|
||||
- [Create a Fulfillment Provider](./add-fulfillment-provider.md)
|
||||
- [Available shipping plugins](https://github.com/medusajs/medusa/tree/master/packages)
|
||||
|
||||
@@ -8,6 +8,8 @@ Medusa's event system works by pushing data to a Queue that each handler then ge
|
||||
|
||||
You can learn how to [install Redis](../../../tutorial/0-set-up-your-development-environment.mdx#redis) and [configure it with Medusa](../../../usage/configurations.md#redis) before you get started.
|
||||
|
||||
---
|
||||
|
||||
## Implementation
|
||||
|
||||
A subscriber is a TypeScript or JavaScript file that is created under `src/subscribers`. Its file name, by convension, should be the class name of the subscriber without the word `Subscriber`. For example, if the subscriber is `HelloSubscriber`, the file name should be `hello.ts`.
|
||||
@@ -40,6 +42,8 @@ The `data` object won't contain other order data. Only the ID of the order. You
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## Using Services in Subscribers
|
||||
|
||||
You can access any service through the dependencies injected to your subscriber’s constructor.
|
||||
@@ -69,7 +73,9 @@ When using attributes defined in the subscriber, such as the `productService` in
|
||||
|
||||
:::
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- [View the list of all events](events-list.md)
|
||||
- [Learn how to create a service.](/advanced/backend/services/create-service)
|
||||
## See Also
|
||||
|
||||
- [Events reference](events-list.md)
|
||||
- [Create a Service](../services/create-service)
|
||||
|
||||
@@ -6,6 +6,8 @@ This document details all events in Medusa, when they are triggered, and what da
|
||||
|
||||
It is assumed you’re already familiar with [Subscribers in Medusa and how to listen to events](create-subscriber.md). You can then use the name of events from this documentation in your subscriber to listen to events.
|
||||
|
||||
---
|
||||
|
||||
## Legend
|
||||
|
||||
Events in this document are listed under the entity they’re associated with. They’re listed in a table of three columns:
|
||||
@@ -14,6 +16,8 @@ Events in this document are listed under the entity they’re associated with. T
|
||||
2. **Description:** When this event is triggered.
|
||||
3. **Event Data Payload**: The data your handler receives as a parameter.
|
||||
|
||||
---
|
||||
|
||||
## Batch Jobs Events
|
||||
|
||||
This section holds all events related to batch jobs.
|
||||
@@ -208,6 +212,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Cart Events
|
||||
|
||||
This section holds all events related to a cart.
|
||||
@@ -284,6 +290,8 @@ An object with at least the ID of the cart, however, in most cases the entire ca
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Claim Events
|
||||
|
||||
This section holds all events related to claims.
|
||||
@@ -459,6 +467,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Claim Item Events
|
||||
|
||||
This section holds all events related to claim items.
|
||||
@@ -553,6 +563,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Currency Events
|
||||
|
||||
This section holds all events related to currencies.
|
||||
@@ -599,6 +611,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Customer Events
|
||||
|
||||
This section holds all events related to customers.
|
||||
@@ -685,6 +699,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Draft Order Events
|
||||
|
||||
This section holds all events related to draft orders.
|
||||
@@ -755,6 +771,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Gift Card Events
|
||||
|
||||
This section holds all events related to gift cards.
|
||||
@@ -802,6 +820,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Invite Events
|
||||
|
||||
This section holds all events related to invites.
|
||||
@@ -849,6 +869,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Note Events
|
||||
|
||||
This section holds all events related to notes.
|
||||
@@ -943,6 +965,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## App Authentication Events
|
||||
|
||||
This section holds all events related to app authentications.
|
||||
@@ -1008,6 +1032,8 @@ The returned data from the method `refreshToken` in the auth handler service of
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Order Events
|
||||
|
||||
This section holds all events related to orders.
|
||||
@@ -1460,6 +1486,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Order Edit Events
|
||||
|
||||
This section holds all events related to order edits.
|
||||
@@ -1637,6 +1665,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Order Edit Item Changes Events
|
||||
|
||||
This section holds all events related to order edit item changes.
|
||||
@@ -1714,6 +1744,8 @@ Triggered when an order edit item change is deleted.
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Payment Events
|
||||
|
||||
This section holds all events related to payment.
|
||||
@@ -1859,6 +1891,8 @@ The entire payment passed as an object. You can refer to the [Payment entity](..
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Payment Collection Events
|
||||
|
||||
This section holds all events related to payment collections.
|
||||
@@ -1954,6 +1988,8 @@ The entire payment collection passed as an object. You can refer to the [Payment
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Product Events
|
||||
|
||||
This section holds all events related to products.
|
||||
@@ -2052,6 +2088,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Product Variant Events
|
||||
|
||||
This section holds all events related to product variants.
|
||||
@@ -2151,6 +2189,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Publishable API Key Events
|
||||
|
||||
This section holds all events related to publishable API keys.
|
||||
@@ -2233,6 +2273,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Region Events
|
||||
|
||||
This section holds all events related to regions.
|
||||
@@ -2327,6 +2369,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Sales Channel Events
|
||||
|
||||
This section holds all events related to sales channels.
|
||||
@@ -2431,6 +2475,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Swap Events
|
||||
|
||||
This section holds all events related to swaps.
|
||||
@@ -2681,6 +2727,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## Token Events
|
||||
|
||||
This section holds all events related to tokens.
|
||||
@@ -2730,6 +2778,8 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
## User Events
|
||||
|
||||
This section holds all events related to users.
|
||||
@@ -2848,7 +2898,9 @@ Object of the following format:
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Learn how you can [use services in subscribers](create-subscriber.md#using-services-in-subscribers).
|
||||
- Learn how to [create notifications](../notification/overview.md) in Medusa.
|
||||
## See Also
|
||||
|
||||
- [Use services in subscribers](create-subscriber.md#using-services-in-subscribers)
|
||||
- [Create a notification provider](../notification/overview.md)
|
||||
|
||||
@@ -10,6 +10,8 @@ The purpose of these events is to allow other parts of the platform, or third-pa
|
||||
|
||||
Medusa's queuing and events system is handled by Redis. So, you must have [Redis configured](../../../tutorial/0-set-up-your-development-environment.mdx#redis) on your server to use subscribers.
|
||||
|
||||
---
|
||||
|
||||
## What are Subscribers
|
||||
|
||||
Subscribers register handlers for an events and allows you to perform an action when that event occurs. For example, if you want to send your customer an email when they place an order, then you can listen to the `order.placed` event and send the email when the event is emitted.
|
||||
@@ -20,7 +22,9 @@ Custom subscribers are TypeScript or JavaScript files in your project's `src/sub
|
||||
|
||||
Whenever an event is emitted, the subscriber’s registered handler method is executed. The handler method receives as a parameter an object that holds data related to the event. For example, if an order is placed the `order.placed` event will be emitted and all the handlers will receive the order id in the parameter object.
|
||||
|
||||
## What's Next
|
||||
---
|
||||
|
||||
- Learn [how to create a Subscriber](create-subscriber.md).
|
||||
- [View the list of all events](events-list.md).
|
||||
## See Also
|
||||
|
||||
- [Create a Subscriber](create-subscriber.md).
|
||||
- [Events reference](events-list.md).
|
||||
|
||||
@@ -21,6 +21,8 @@ This can be useful when some countries have the same currency but have different
|
||||
|
||||
Then, Medusa handles calculating the tax amount using the tax rate and the tax-inclusive price. This is managed in the backend and relayed to accounting and analytics tools.
|
||||
|
||||
---
|
||||
|
||||
## How is Tax Inclusivity Defined
|
||||
|
||||
Tax inclusivity can be toggled for regions, currencies, price lists, and shipping options either during creation or while editing. This is represented by the boolean attribute `includes_tax` available in the entities `Region`, `Currency`, `PriceList`, and `ShippingOption`. By default, this attribute is set to `false`.
|
||||
@@ -54,6 +56,8 @@ When a shipping option is selected, a shipping method is created based on that s
|
||||
|
||||
The `ShippingMethod` entity also has the `includes_tax` attribute. Its value is the same as the value of `includes_tax` of the shipping option the method is associated with.
|
||||
|
||||
---
|
||||
|
||||
## Tax Amount Calculation Formula
|
||||
|
||||
When a price is tax-inclusive, the tax amount is calculated using the following formula:
|
||||
@@ -66,6 +70,8 @@ Where `taxRate` is the tax rate to be applied to the price, and `taxInclusivePri
|
||||
|
||||
For example, if the tax rate is `0.25` and the price of a product is `100`, the resulting tax amount calculated by Medusa will be `0.25 * 100 / 1.25 = 20`.
|
||||
|
||||
---
|
||||
|
||||
## Retrieving Tax Amounts
|
||||
|
||||
This section covers at which point tax amounts are calculated for different entities, how they are calculated when the price is tax inclusive, and what fields can be returned in the endpoints relative to each of the entities.
|
||||
@@ -187,7 +193,9 @@ The relevant fields are:
|
||||
|
||||
During the calculation of the totals of different components of the cart or order, such as shipping or line items, if tax inclusivity is enabled on that component, a process similar to those explained above will be applied to retrieve the total.
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Learn how to [calculate taxes manually](manual-calculation.md).
|
||||
- [Check out the API reference](https://docs.medusajs.com/api/store/).
|
||||
## See Also
|
||||
|
||||
- [Calculate taxes manually](manual-calculation.md)
|
||||
- [Storefront API reference](/api/store)
|
||||
|
||||
@@ -8,6 +8,8 @@ By default, taxes are automatically calculated by Medusa during checkout. This b
|
||||
|
||||
If you disable this behavior, you must manually trigger taxes calculation. When taxes are calculated, this means that requests will be sent to the tax provider to retrieve the tax rates.
|
||||
|
||||
---
|
||||
|
||||
## How to Manually Calculate Taxes in Checkout
|
||||
|
||||
This section explores different ways you can calculate taxes based on your purpose.
|
||||
@@ -80,7 +82,9 @@ You can learn how to [retrieve and use services](../services/create-service.md#u
|
||||
|
||||
:::
|
||||
|
||||
## What’s Next
|
||||
---
|
||||
|
||||
- Learn about [tax-inclusive pricing](inclusive-pricing.md).
|
||||
- Learn about available methods in [CartsService](../../../references/services/classes/CartService.md) and [TotalsService](../../../references/services/classes/TotalsService.md).
|
||||
## See Also
|
||||
|
||||
- [Tax-Inclusive Pricing Overview](inclusive-pricing.md)
|
||||
- [CartsService](../../../references/services/classes/CartService.md) and [TotalsService](../../../references/services/classes/TotalsService.md)
|
||||
|
||||
@@ -20,6 +20,8 @@ TYPEORM_MIGRATIONS=./node_modules/@medusajs/medusa/dist/migrations/*.js
|
||||
|
||||
These environment variables are used in the data migration scripts in this upgrade. Make sure to replace `<DATABASE_URL>` with your PostgreSQL database URL.
|
||||
|
||||
---
|
||||
|
||||
## Environment Variables
|
||||
|
||||
In previous versions of Medusa, The server automatically loads all environment variables in the `.env` file at the root of the Medusa server.
|
||||
@@ -58,6 +60,8 @@ const dotenv = require('dotenv')
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Line Item Adjustments
|
||||
|
||||
This new version of Medusa allows store operators to adjust line items in an order or a swap which provides more customization capabilities.
|
||||
@@ -76,6 +80,8 @@ For that reason, it’s essential to run the data migration script after upgradi
|
||||
node ./node_modules/@medusajs/medusa/dist/scripts/line-item-adjustment-migration.js
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Advanced Discount Conditions
|
||||
|
||||
This new version of Medusa holds advanced promotions functionalities to provide store operators with even more customization capabilities when creating discounts. You can now add even more conditions to your discounts to make them specific for a set of products, collections, customer groups, and more.
|
||||
|
||||
@@ -26,6 +26,8 @@ TYPEORM_MIGRATIONS=./node_modules/@medusajs/medusa/dist/migrations/*.js
|
||||
|
||||
These environment variables are used in the data migration scripts in this upgrade. Make sure to replace `<DATABASE_URL>` with your PostgreSQL database URL.
|
||||
|
||||
---
|
||||
|
||||
## Sales Channels
|
||||
|
||||
Sales Channels were introduced in v1.3.5 guarded by a [feature flag](../feature-flags/toggle.md). By enabling Sales Channels, developers and users can associate products and other entities with a specific Sales Channel.
|
||||
|
||||
@@ -10,6 +10,8 @@ Updating your medusa server to version `1.3.8` may cause issues when using NPM.
|
||||
|
||||
It's highly recommended to use [yarn](https://yarnpkg.com/) when working with Medusa. Updating with yarn should resolve any issues you might run into during the update.
|
||||
|
||||
---
|
||||
|
||||
## Resolving Update Issues with NPM
|
||||
|
||||
### Update All Medusa Dependencies
|
||||
|
||||
@@ -12,6 +12,8 @@ As the new version `1.6.1` make changes to the database schema, it is required t
|
||||
|
||||
Without running the migrations, you might have trouble accessing and using the Medusa admin.
|
||||
|
||||
---
|
||||
|
||||
## Actions Required
|
||||
|
||||
After updating your server, run migrations with the following command:
|
||||
|
||||
@@ -12,6 +12,8 @@ In this new version, the method [`retrieveByEmail` in the Customer Service](../.
|
||||
|
||||
In addition, after introducing the Claim Order feature, this version of Medusa introduces changes in the database that allows two customers having the same email based on the value of the `has_account` field. This change requires running migrations after the update.
|
||||
|
||||
---
|
||||
|
||||
## Actions Required
|
||||
|
||||
### Run Migrations
|
||||
|
||||
@@ -14,6 +14,8 @@ With this introduction, the previous use of `EventBus` to create a cron job has
|
||||
|
||||
In addition, this version features some fixes to gift cards that requires running migrations, and changes to how payment providers are implemented.
|
||||
|
||||
---
|
||||
|
||||
## Actions Required
|
||||
|
||||
### Run Migrations
|
||||
|
||||
@@ -12,6 +12,8 @@ Medusa Admin previously was built using Gatsby. As of a recent update, the Admin
|
||||
|
||||
This introduced breaking changes related to environment variables used and the published directory. Read below for actions required following this update.
|
||||
|
||||
---
|
||||
|
||||
## Required Node.js Version
|
||||
|
||||
<!-- vale docs.Numbers = NO -->
|
||||
@@ -20,6 +22,8 @@ Following the change to Vite 3, the required Node.js version for the Admin has c
|
||||
|
||||
<!-- vale docs.Numbers = YES -->
|
||||
|
||||
---
|
||||
|
||||
## Changed Environment Variables
|
||||
|
||||
Previously, the Medusa Admin used the environment variables `GATSBY_MEDUSA_BACKEND_URL` or `GATSBY_STORE_URL` to store the Medusa server’s URL.
|
||||
@@ -36,6 +40,8 @@ Change your `GATSBY_MEDUSA_BACKEND_URL` or `GATSBY_STORE_URL` environment variab
|
||||
MEDUSA_BACKEND_URL=<YOUR_MEDUSA_SERVER_URL>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Changed Publish Directory
|
||||
|
||||
Previously, the build output of the Medusa Admin was placed in the `dist` directory. After this update, the build output is placed in the `public` directory.
|
||||
|
||||
Reference in New Issue
Block a user