Files
medusa-store/www/apps/resources/app/recipes/b2b/page.mdx
2025-07-22 16:51:57 +03:00

318 lines
10 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
products:
- product
- customer
- sales channel
- pricing
---
import { AcademicCapSolid, UsersSolid } from "@medusajs/icons"
export const metadata = {
title: `B2B Recipe`,
}
# {metadata.title}
This recipe provides the general steps to implement a B2B store with Medusa.
<Note title="Tip">
Medusa has a ready-to-use B2B starter that you install and use in [this GitHub repository](https://github.com/medusajs/b2b-starter-medusa).
</Note>
## Overview
In a B2B store, you provide different types of customers with relevant pricing, products, shopping experience, and more.
Medusas Commerce Modules, including [Sales Channel](../../commerce-modules/sales-channel/page.mdx), [Customer](../../commerce-modules/), and [Pricing](../../commerce-modules/pricing/page.mdx) 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, Medusas extensible architecture and Framework for customization allow you to scope existing and custom features to specific customer groups or sales channels.
<Note title="Related use-case">
[Visionary: Frictionless B2B ecommerce with Medusa](https://medusajs.com/blog/visionary/)
</Note>
---
## Create B2B Sales Channel
Sales channels 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, you 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.
<CardList items={[
{
href: "!user-guide!/settings/sales-channels",
title: "Using Medusa Admin",
text: "Create the sales channel using the Medusa Admin.",
icon: UsersSolid,
},
{
href: "!api!/admin#sales-channels_postsaleschannels",
title: "Using Admin API",
text: "Create the sales channel using the REST APIs.",
icon: AcademicCapSolid,
},
]} />
---
## 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
<CardList items={[
{
href: "!user-guide!/settings/developer/publishable-api-keys",
title: "Using Medusa Admin",
text: "Create the API key using the Medusa Admin.",
icon: UsersSolid,
},
{
href: "!api!/admin#api-keys_postapikeys",
title: "Using Admin API",
text: "Create the API key using the REST APIs.",
icon: AcademicCapSolid,
},
]} />
### Associate Key with Sales Channel
<CardList items={[
{
href: "!user-guide!/settings/developer/publishable-api-keys#manage-publishable-api-keys-sales-channels",
title: "Using Medusa Admin",
text: "Associate the key with the sales channel using the Medusa Admin.",
icon: UsersSolid,
},
{
href: "!api!/admin#api-keys_postapikeysidsaleschannels",
title: "Using Admin API",
text: "Associate the key with the sales channel using the REST APIs.",
icon: AcademicCapSolid,
},
]} />
---
## 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
<CardList items={[
{
href: "!user-guide!/products/create",
title: "Using Medusa Admin",
text: "Create the products using the Medusa Admin.",
icon: UsersSolid,
},
{
href: "!api!/admin#products_postproducts",
title: "Using Admin API",
text: "Create the products using the REST APIs.",
icon: AcademicCapSolid,
},
]} />
### Add Products to Sales Channel
<CardList items={[
{
href: "!user-guide!/settings/sales-channels#manage-products-in-sales-channel",
title: "Using Medusa Admin",
text: "Create the products using the Medusa Admin.",
icon: UsersSolid,
},
{
href: "!api!/admin#sales-channels_postsaleschannelsidproductsbatchadd",
title: "Using Admin API",
text: "Add the products to the sales channel using the REST APIs.",
icon: AcademicCapSolid,
},
]} />
---
## 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
<CardList items={[
{
href: "!user-guide!/customers/manage",
title: "Using Medusa Admin",
text: "Create customers using the Medusa Admin.",
icon: UsersSolid,
},
{
href: "!api!/admin#customers_postcustomers",
title: "Using Admin API",
text: "Create customers using the REST APIs.",
icon: AcademicCapSolid,
},
]} />
### Assign Customers to Groups
<CardList items={[
{
href: "!user-guide!/customers/manage#manage-customers-groups",
title: "Using Medusa Admin",
text: "Assign customer to groups using the Medusa Admin.",
icon: UsersSolid,
},
{
href: "!api!/admin#customer-groups_postcustomergroupsidcustomersbatch",
title: "Using Admin API",
text: "Assign customer to groups using the REST APIs.",
icon: AcademicCapSolid,
},
]} />
### 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.
<CardList items={[
{
href: "!docs!/learn/fundamentals/modules",
title: "Create Module",
text: "Learn how to create a module.",
icon: AcademicCapSolid,
},
{
href: "!docs!/learn/fundamentals/module-links",
title: "Define Module Links",
text: "Define links between data models.",
icon: AcademicCapSolid,
},
]} />
---
## 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.
<CardList items={[
{
href: "!user-guide!/price-lists/create",
title: "Using Medusa Admin",
text: "Create price list using the Medusa Admin.",
icon: UsersSolid,
},
{
href: "!api!/admin#price-lists_postpricelists",
title: "Using Admin API",
text: "Create price list using the REST APIs.",
icon: AcademicCapSolid,
},
]} />
---
## 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.
<CardList items={[
{
href: "!docs!/learn/fundamentals/admin/widgets",
title: "Create Admin Widget",
text: "Add widgets into existing admin pages.",
icon: AcademicCapSolid,
},
{
href: "!docs!/learn/fundamentals/admin/ui-routes",
title: "Create Admin UI Routes",
text: "Add new pages to your Medusa Admin.",
icon: AcademicCapSolid,
},
]} />
<Card
href="!docs!/learn/fundamentals/admin/ui-routes#create-settings-page"
title="Create Admin Setting Page"
text="Add new page to the Medusa Admin settings."
icon={AcademicCapSolid}
className="mt-1"
/>
---
## Customize or Build Storefront
Medusa provides a Next.js Starter Storefront to use with your application. You can customize it 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.
<CardList items={[
{
href: "/nextjs-starter",
title: "Next.js Starter Storefront",
text: "Learn how to install and customize the Next.js Starter Storefront.",
icon: AcademicCapSolid,
},
{
href: "/storefront-development",
title: "Storefront Development",
text: "Find guides to build your own storefront.",
icon: AcademicCapSolid,
},
]} />
<Card
href="!api!/store#publishable-api-key"
title="Use Publishable API Keys"
text="Learn how to use the publishable API key in client requests."
icon={AcademicCapSolid}
className="mt-1"
/>