Products Architecture Overview
In this document, you’ll learn about Products in Medusa and their relation to other entities.
Overview
Products are items that a business sells to customers. Each product can have options and variants. Options are the different available attributes of a product, and variants are the salable combinations of these options.
For example, a product can have a “Color” option with values blue and green. You can then create two product variants from these options: one using the option value blue, and the other using the value green. This is just a simple example, as you can have multiple options and have variants combine values from each of these options.
Products can be associated with categories, collections, types, and more. This allows merchants to better organize products either internally or for their customers.
Product Entity Overview
The Product
Copy to Clipboard entity has many useful attributes, including:
title
Copy to Clipboard: The name of the product.handle
Copy to Clipboard: A slug representation of the product’s title. This can be used in the storefront to generate human-readable URLs for products, which can be beneficial for Search Engine Optimization (SEO) purposes.status
Copy to Clipboard: A string indicating the status of the product. Its values can bedraft
Copy to Clipboard,proposed
Copy to Clipboard,published
Copy to Clipboard, andrejected
Copy to Clipboard.external_id
Copy to Clipboard: A string that can be used to store an ID of the product on an external system. This is useful if you’re migrating the product from an ecommerce platform to Medusa, or if you’re connecting Medusa’s products to an external service.
Other attributes of the Product
Copy to Clipboard entity are explored in the next sections.
Customizing the Product Entity
It’s common for developers to customize the Product
Copy to Clipboard entity, as there can be different use cases for each type of businesses.
In some simple cases, you might just need to store additional values within the entity without fully customizing it. For those cases, you can use the metadata
Copy to Clipboard attribute. This is an object stored in the database as a JSONB type in the database. You can store inside it key-value data that is useful for your case:
metadata = {
"someKey": "someValue",
}
In more complex scenarios, you may need to add columns or relations to your Product
Copy to Clipboard entity. You can then extend the entity to make your customizations.
Product Option Overview
Each product is expected to have at least one option. Options are used to specify the different available properties of that product. Some examples of options are colors, sizes, or material.
Product Options are represented by the ProductOption
Copy to Clipboard entity. The entity has the attribute title
Copy to Clipboard indicating the name of the option (for example, Color). The entity is associated with the Product
Copy to Clipboard entity through the product_id
Copy to Clipboard attribute and the product
Copy to Clipboard relation. You can also access the options of a product from the Product
Copy to Clipboard entity using the options
Copy to Clipboard relation.
The available values of each option are represented by the ProductOptionValue
Copy to Clipboard entity. The entity has the attribute value
Copy to Clipboard which is a string holding the value of the option (for example, Blue).
The ProductOptionValue
Copy to Clipboard entity is associated with the ProductOption
Copy to Clipboard through the option_id
Copy to Clipboard attribute and the option
Copy to Clipboard relation. You can also access the values of an option from the ProductOption
Copy to Clipboard entity using the values
Copy to Clipboard relation.
The ProductOptionValue
Copy to Clipboard entity is also associated with a product variant using the variant_id
Copy to Clipboard attribute and the variant
Copy to Clipboard relation.
Product Variant Overview
Product variants are the actual salable item in your store. Each variant is a combination of the different option values available on the product. For example, if you have a color option and a size option, here are some variants that you might have:
- Variant A: Color blue and size large
- Variant B: Color green and size large
- Variant C: Color blue and size small
- Variant D: Color green and size small
And the list can go on.
You can’t have two product variants with the same values. For example, you can’t have another Variant E having the same option values as Variant B.
Product variants are represented by the ProductVariant
Copy to Clipboard entity. The entity’s attributes include:
title
Copy to Clipboard: A string title of the product variant. This is different from the title in theProduct
Copy to Clipboard entity.product_id
Copy to Clipboard: A string indicating which product this variant belongs to. You can also access the product through theproduct
Copy to Clipboard relation if it’s expanded.sku
Copy to Clipboard: A string indicating the Stock Keeping Unit (SKU) of the variant. This, along with other attributes likebarcode
Copy to Clipboard orupc
Copy to Clipboard are useful to store inventory-related information.inventory_quantity
Copy to Clipboard: A number indicating the available inventory of the variant. This is only useful if you havemanage_inventory
Copy to Clipboard disabled.manage_inventory
Copy to Clipboard: A boolean value indicating whether Medusa should handle the management of the product variant’s inventory. This would allow you to handle your inventory data more accurately across different locations. You can learn more in the Inventory Module documentation.inventory_items
Copy to Clipboard: A relation that gives you access to the inventory items of a variant whenmanage_inventory
Copy to Clipboard is enabled. You can learn more in the Inventory Module documentation.variant_rank
Copy to Clipboard: a number that can be used to decide the sort order of variants in a storefront.
You can also access the option values of a product variant through the options
Copy to Clipboard relation, which is an array of ProductOptionValue
Copy to Clipboard items.
Product Variant Pricing
As the product variant is the salable item in your store, the price of a product is specific to each product variant.
A product variant can have more than one price for different context. For example, a product variant can have a different price for each currency or region.
The prices of a product variant are available on the prices
Copy to Clipboard relation, which is an array of MoneyAmount
Copy to Clipboard items. MoneyAmount
Copy to Clipboard is an entity used throughout Medusa to store prices in general.
The MoneyAmount
Copy to Clipboard entity has the following attributes that are useful for a product variant:
currency_code
Copy to Clipboard: A string indicating the currency code this price is for. The currency can also be accessed through thecurrency
Copy to Clipboard relation.amount
Copy to Clipboard: A number indicating the price.region_id
Copy to Clipboard: An optional string indicating the ID of the region this price is for. The region can also be accessed through theregion
Copy to Clipboard relation.price_list_id
Copy to Clipboard: An optional string indicating the ID of the price list this price is for. The price list can also be accessed through theprice_list
Copy to Clipboard relation.
Storing the Product Variant’s Price
Although this is no requirement, it’s recommended to store the amount
Copy to Clipboard as the price multiplied by a hundred. The Medusa admin dashboard and the Next.js storefront expect the price to be of that format, so when prices are displayed they’re divided by a hundred. Also, when you add or update a product variant, its price is sent to the Medusa backend as the price multiplied by a hundred.
Displaying the Product Variant’s Price
When showing a product’s details to the customer in the storefront, you can pass in your requests query parameters that specify the customer’s context. For example, you can specify the customer’s region. This would retrieve the correct pricing of the product for each customer. You can learn more in this documentation.
Relations to Other Entities
This section explores the relations between the Product
Copy to Clipboard entity and other entities in your Medusa backend.
SalesChannel
Sales channels define the different channels a business is selling its products in. A product can be available in some or all sales channels.
You can access a product’s sales channels by expanding the sales_channels
Copy to Clipboard relation and accessing product.sales_channels
Copy to Clipboard. It’s an array of sales channels the product is available in.
ProductType
A product can belong to a type, which is represented by the ProductType
Copy to Clipboard entity.
The ID of the product’s type is stored under the attribute type_id
Copy to Clipboard. You can access the product’s type by expanding the type
Copy to Clipboard relation and accessing product.type
Copy to Clipboard.
ProductTag
A product can be associated with one or more tags. A tag is represented by the ProductTag
Copy to Clipboard entity.
You can access the product’s tags by expanding the tags
Copy to Clipboard relation and accessing product.tags
Copy to Clipboard, which is an array of product tags.
ProductCollection
A product can be associated with a collection. A collection is represented by the ProductCollection
Copy to Clipboard entity.
The ID You can access the product’s collection by expanding the collection
Copy to Clipboard relation and accessing product.collection
Copy to Clipboard.
ProductCategory
A product can be associated with a category. A category is represented by the ProductCategory
Copy to Clipboard entity.
You can access the product’s categories by expanding the categories
Copy to Clipboard relation and accessing product.categories
Copy to Clipboard, which is an array of product categories.
DiscountConditionProduct
A discount can be specified for one or more products through discount conditions. The relation between a discount condition and a product is established through the DiscountConditionProduct
Copy to Clipboard entity which holds the IDs of the product and the discount condition.