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 can create a custom module defining data models related to personalization with the service to manage them. Then, you can link those data models to existing data models, such as products.

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}'
Note: Two 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 link between these data models and the LineItem data model.

Create a Module
Learn how to create a module.
Define Module Link
Define link between data models.

Build a Custom Storefront#

Medusa's modular architecture removes any restrictions on the your storefront's tech stack, design, and the 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 Storefront
Learn how to install the Next.js Starter Storefront.
Storefront Development
Find guides to build your own storefront.

Pass Personalized Data to the Order#

If you store the personalized data using a custom module, you can:

  • Create a workflow that handles saving the personalization data.
  • Create a custom API Route that executes the workflow.
  • Call that API Route from the storefront after adding the item to the cart.
  • Consume the orderCreated hook of the completeCartWorkflow to attach the personalized data to the Order Module's LineItem data model.
Create a Workflow
Learn how to create a workflow.
Create API Route
Learn how to create an API route.
Consume a Hook
Learn how to create a hook.

Fulfill Personalized Products in Orders#

The Fulfillment Module handles all logic related to fulfilling orders. It also supports using fulfillment module providers that implement the logic of fulfilling orders with third-party services.

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

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

Fulfillment Module
Learn about the Fulfillment Module.
Create Fulfillment Module Provider
Learn how to create a fulfillment module provider.
Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break