Personalized Products Recipe

This recipe provides the general steps to build personalized products in Medusa.

Overview#

Personalized products are products that customers can customize based on their need. For example, they can upload an image to print on a shirt or provide a message to include in a letter.

In Medusa, you create a custom module defining data models, implementing custom features, and creating relationships to other modules' data models.

You also have freedom in how you choose to implement the storefront, allowing you to build a unique experience around your products.


Store Personalized Data#

The Cart Module's LineItem data model has a metadata property that holds any custom data. You can pass the customer's customization in the request body's metadata field when adding a product to the cart.

For example, if you’re asking customers to enter a message to put in a letter they’re purchasing, use the metadata attribute of the LineItem data model to set the personalized information entered by the customer:

Code
1curl -X POST '{backend_url}/store/carts/{id}/line-items' \2-H 'Content-Type: application/json' \3-H 'x-publishable-api-key: {your_publishable_api_key}' \4--data-raw '{5  "variant_id": "variant_123",6  "quantity": 1,7  "metadata": {8    "message": "Hello, World!"9  }10}'
NoteTwo line items in the cart having different metadata attributes are not considered the same item. So, each line item is managed separately and can have its own quantity.

In more complex cases, you can create a custom module that stores and manages the personalization data models. You can also create a relationship between these data models and the LineItem data model.

Create a Module
Learn how to create a module.
Create a Data Model
Learn how to create a data model.

Build a Custom Storefront#

Due to Medusa's modular architecture, there are no restrictions on the framework you use to build the storefront, or design and experience you provide customers. The storefront connects to the Medusa application using the Store API Routes.

You can build a unique experience around your products that focuses on the customer’s personalization capabilities.

Medusa provides a Next.js Starter storefront with basic ecommerce functionalities that can be customized. You can also build your own storefront and use Medusa’s client libraries or Store API Routes to communicate with the Medusa application.

Next.js Starter
Learn about the Next.js Starter and how to install it.
Storefront Development
Find guides for your storefront development.

Pass Personalized Data to the Order#

If you store the personalized data using a custom module:

  • Create a custom API Route that handles saving the personalization data.
  • Call that API Route from the storefront after adding the item to the cart.
  • Listen to the order.placed event to attach the personalized data to the Order Module's LineItem data model.
Create API Route
Learn how to create an API route.
Create a Subscriber
Learn how to create a subscriber.

Fulfill Personalized Products in Orders#

To fulfill your personalized products with a third-party service or custom logic, create a fulfillment module provider.

The Fulfillment Module registers your fulfillment module provider to use it to fulfill orders.

Create a Fulfillment Service
Learn how to create a fulfillment provider in Medusa.
Was this page helpful?
Edit this page