- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
Digital Products Recipe
This recipe provides the general steps to implement digital products in your Medusa application.
Overview#
Digital products are stored privately using a storage service like S3. When the customer buys this type of product, an email is sent to them where they can download the product.
To implement digital products in Medusa, you create a Digital Product Module that introduces the concept of a digital product and link it to existing product concepts in the Product Module.
Install a File Module Provider#
A file module provider handles storage functionalities in Medusa. This includes uploading, retrieving, and downloading files, among other features.
Use a file module provider to manage your stored digital products.
During development, you can use the Local File Module Provider, which is installed by default in your store. For production, check out available file module providers or create your own.
Create Digital Product Module#
Your custom features and functionalities are implemented inside modules. The module is integrated into the Medusa application without any implications on existing functionalities.
The module will hold your custom data models and the service implementing digital-product-related features.
Create Custom Data Model#
A data model represents a table in the database. You can define in your module data models to store data related to your custom features, such as a digital product.
Then, you can link your custom data model to data models from other modules. For example, you can link the digital product model to the Product Module's ProductVariant
data model.
Implement Data Management Features#
Your module’s main service holds data-management and other related features. Then, in other resources, such as an API route, you can resolve the service from the Medusa container and use its functionalities.
Medusa facilitates implementing data-management features using the service factory. Your module's main service can extend this service factory, and it generates data-management methods for your data models.
Add Custom API Routes#
API routes expose your features to external applications, such as the admin dashboard or the storefront.
You can create custom API routes that allow merchants to list and create digital products. In these API routes, you resolve the Digital Product Module’s main service to use its data-management features.
Implement Workflows#
Your use case most likely has flows, such as creating digital products, that require multiple steps.
Create workflows to implement these flows, then utilize these workflows in other resources, such as an API route.
Manage Linked Records#
If you've defined links between data models of two modules, you can manage them through two functions: remote link and Query.
Use the remote link to create a link between two records, and use Query to fetch data across linked data models.
Customize Admin Dashboard#
You can extend the Medusa Admin to provide merchants with an interface to manage digital products. You can inject widgets into existing pages or create new pages.
In your customizations, you send requests to the API routes you created to create and list digital products.
Deliver Digital Products to the Customer#
When a customer purchases a digital product, they should receive a link to download it.
You can create or install a fulfillment module provider that handles the logic of fulfilling the digital product.
Customize or Build Storefront#
Customers use your storefront to browse your digital products and purchase them. You can also provide other helpful features, such as previewing the digital product before purchase.
Medusa provides a Next.js storefront with standard commerce features including listing products, placing orders, and managing accounts. You can customize the storefront and cater its functionalities to support digital products.
Alternatively, you can build the storefront with your preferred tech stack.