B2B Recipe
This recipe provides the general steps to implement a B2B store with Medusa.
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.
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#
Associate Key with Sales Channel#
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#
Add Products to Sales Channel#
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#
Assign Customers to Groups#
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 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.
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.
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.