B2B Recipe

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

Tip: Medusa 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 enable this setup out-of-the-box:

  • Sales Channel: Use sales channels to set product availability per channel. In this case, create a B2B sales channel that includes only B2B products.
  • Customer: Use customer groups to organize your customers into different groups. Then, you can apply different prices for each group.
  • Pricing: Use price lists to set different prices for each B2B customer group, among other conditions.

In addition, Medusa’s extensible architecture and Framework for customization allow you to scope existing and custom featuers to specific customer groups or sales channels.


Create B2B Sales Channel#

Sales channls allow you to set product availability per channel. For B2B use cases, you can create a B2B sales channel that includes only B2B products.

Then, on the storefront, your retrieve only the B2B products for B2B customers, which is explained more in the next section.

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

Using Medusa Admin
Create the sales channel using the Medusa Admin.
Using Admin API
Create the sales channel using the REST APIs.

Create a Publishable API Key#

A publishable API key allows you to specify the context of client requests:

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

So, if you use the publishable API key associated with the B2B sales channel in your storefront, the Medusa server will only return products that are available in the B2B sales channel.

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

Create Publishable API Key#

Using Medusa Admin
Create the API key using the Medusa Admin.
Using Admin API
Create the API key using the REST APIs.

Associate Key with Sales Channel#

Using Medusa Admin
Associate the key with the sales channel using the Medusa Admin.
Using Admin API
Associate the key with the sales channel using the REST APIs.

Add Products to B2B Sales Channel#

You can manage products to be available in specific sales channels. For B2B, this allows you to add products that are only available to B2B customers.

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

Create Products#

Using Medusa Admin
Create the products using the Medusa Admin.
Using Admin API
Create the products using the REST APIs.

Add Products to Sales Channel#

Using Medusa Admin
Create the products using the Medusa Admin.
Using Admin API
Add the products to the sales channel using the REST APIs.

Add B2B Customers and Groups#

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

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

You can create a customer group for each B2B company, then add customers of that company to the group.

Create Customers#

Using Medusa Admin
Create customers using the Medusa Admin.
Using Admin API
Create customers using the REST APIs.

Assign Customers to Groups#

Using Medusa Admin
Assign customer to groups using the Medusa Admin.
Using Admin API
Assign customer to groups using the REST APIs.

Flexible Customizations: Create Custom Module#

B2B use cases often require more complex customer management, such as managing roles in a company with employees having different privileges.

For more complex use cases, you can create a custom module that introduces data models like Company, Employee, and other relevant models.

Then, you can link those companies to existing customers and groups, allowing you to benefit from existing features like price lists for specific customer groups.

Create Module
Learn how to create a module.
Define Module Links
Define links between data models.

Create B2B Price List#

Price lists allow you to set different prices for each customer group, among other conditions. They're useful to override prices for custom use cases.

For B2B use cases, you can use price lists to set different prices for each B2B customer group. Then, B2B customers can see different prices on the storefront based on their group.

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

Using Medusa Admin
Create price list using the Medusa Admin.
Using Admin API
Create price list using the REST APIs.

Customize Medusa Admin#

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

For example, you may want to add a page to manage companies and their employees, or you may want to add a widget to show the company associated with a customer group.

The Medusa Admin is an extensible application within your Medusa application. You can customize it by:

  • Widgets: Adding widgets to existing pages, such as the customer group page.
  • UI Routes: Adding new pages to the Medusa Admin, such as a page to manage companies and employees.
  • Settings Pages: Adding new pages to the Medusa Admin settings, such as a page to manage company settings.
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 or Build Storefront#

Medusa provides a Next.js Starter Storefront to use with your application. You can customize it to for your B2B use case, such as adding a login page for B2B customers or expanding the profile page to show the company associated with the customer.

Alternatively, you can build your own storefront using the Medusa APIs. This headless approach gives you the flexibility to build a custom storefront without limitations on which tech stack you use, or the design of the storefront.

In your storefront, you can use the publishable API key you associated with your B2B sales channel to ensure only B2B products are retrieved.

Next.js Starter Storefront
Learn how to install and customize the Next.js Starter Storefront.
Storefront Development
Find guides to build your own storefront.
Use Publishable API Keys
Learn how to use the publishable API key in client requests.
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