B2B Recipe

This recipe provides the general steps to implement a B2B store with Medusa.

TipMedusa has a ready-to-use B2B starter that you install and use in this GitHub repository.

Overview#

In a B2B store, you provide different types of customers with relevant pricing, products, shopping experience, and more.

Medusa’s commerce modules, including Sales Channel, Customer, and Pricing modules facilitate implementing this setup. Medusa’s architecture and extendible nature allow you to customize your store based on your use case.


Create B2B Sales Channel#

Use sales channels to set product availability per channel. In this case, create a B2B sales channel that includes only B2B products.

You can create a sales channel through the Medusa Admin or Admin REST APIs.

Create Sales Channel
Create the sales channel using the REST APIs.

Create a Publishable API Key#

Use publishable API keys to specify the context of client requests:

  • You associate the publishable API key with one or more sales channels.
  • In a client such as a storefront, you pass the publishable API key in the header of your requests.

Then, all products retrieved belong to the associated sales channel(s).

You can create a publishable API key through the Medusa Admin or the Admin REST APIs, then associate it with the B2B sales channel. Later, you'll use this key when developing your B2B storefront.

Create Key#

Create Publishable API Key
Create the publishable API key using the REST APIs.

Associate Key with Sales Channel#

Create Publishable API Key
Create the publishable API key using the REST APIs.

Add Products to B2B Sales Channel#

You can create new products or add existing ones to the B2B sales channel using the Medusa Admin or Admin REST APIs.

Create Products#

Create Products
Create products using the REST APIs.

Add Products to Sales Channel#

Add to Sales Channel
Add the products to the B2B sales channel using the REST APIs.

Create B2B Module with Relationship to Customer Groups#

Use customer groups to organize your customers into different groups. Then, you can apply different prices for each group.

This is useful in B2B sales, as you often negotiate special prices with each customer or company.

You can create a B2B module that adds necessary data models to represent a B2B company. Then, you link that company to a customer group, which is defined in the Customer Module. Any customer belonging to that group also belongs to the company, meaning they're a B2B customer.

Create Module
Learn how to create a module in Medusa.
Create Data Models
Learn how to create data models.
Create Module Links
Learn how to create links between modules.

Add B2B Customers#

After adding your B2B customer group, add B2B customers and assign them to the B2B customer group.

You can do that through the Medusa Admin or Admin REST APIs.

Create Customers#

Create Customers
Create the customers using the REST APIs.

Assign Customers to Groups#

Assign Customers to Groups
Assign the customers to the B2B customer group using the REST APIs.

Create B2B Price List#

Use price lists to set different prices for each B2B customer group, among other conditions.

You can create a price list using the Medusa Admin or the Admin REST APIs. Make sure to set the B2B customer group as a condition.

Create Price List
Create the price list using the REST APIs.

Create Custom Data Model#

To implement a more advanced B2B sales flow, add custom data models such as Company, Employee, Admin, and Buyer to your B2B module.

This provides more granular control of your B2B sales and allows you to build features like privileges, limits, and more.

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

Create an API Route to Check Customers#

On the frontend clients communicating with your store, such as the storefront, you need to check whether the currently logged-in customer is a B2B customer.

The API route can check if the customer has any group with an associated company.

Create an API Route
Learn how to create an API Route in Medusa.

Customize Admin#

Based on your use case, you may need to customize the Medusa Admin to add new widgets or pages.

The Medusa Admin plugin can be extended to add widgets, new pages, and setting pages.

Create Admin Widget
Add widgets into existing admin pages.
Create Admin UI Routes
Add new pages to your Medusa Admin.
Create Admin Setting Page
Add new page to the Medusa Admin settings.

Customize Storefront#

Medusa provides a Next.js storefront to use with your application. You can either customize it or build your own to represent your B2B features.

Use the publishable API key you associated with your B2B sales channel in the storefront to ensure only B2B products are retrieved.

Next.js Storefront
Learn how to install and customize the Next.js storefront.
Storefront Development
Find guides for your storefront development.
Use Publishable API Keys
Learn how to use the publishable API key in client requests.
Was this page helpful?
Edit this page
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