B2b
B2B commerce capabilities for Medusa v2: companies, employees, quotes, approvals, spending limits, and B2B cart workflows.
B2B commerce capabilities for Medusa v2: companies, employees, spending limits, quote negotiation, multi-level cart approvals, and a full admin UI — all as a self-contained, droppable plugin.
Medusa compatibility: — keep peer dependencies aligned with your host application.
Contents
- Features
- Requirements
- Installation
- Path Aliases
- Architecture
- Modules
- Entity Links
- Workflows
- REST API
- Admin UI
- Development
- Roadmap
- License
Features
- Company management — companies with name, contact info, address, logo, and currency
- Employee roster — link customers to companies with per-employee spending limits
- Customer-group sync — each company is backed by a Medusa CustomerGroup for price-list targeting
- Spending limits — configurable per-employee caps with reset windows (daily → yearly)
- Cart approval flow — require admin or sales-manager approval before a cart can be completed
- Quote negotiation — request-for-quote lifecycle with draft-order editing, messaging, and acceptance
- Workflow hooks — cart and order creation hooks that attach B2B context automatically
- Admin UI — overview dashboard, companies list + detail, quote list + detail + management, approval queue
- Dual API surface — (Medusa admin JWT) and (customer session/bearer)
- Role enforcement — middleware guards company-mutating store routes
- Free-shipping price API — expose threshold prices to storefronts without custom logic
Requirements
| Dependency | Version |
|---|---|
| Node | |
| pnpm | (or npm/yarn — adjust scripts accordingly) |
Installation
Register the plugin in :
Run migrations after adding the plugin:
medusa db:migrateSeeding demo data
A seed script is included to create default customer groups, a B2B sales channel, and a base region with shipping options:
Path Aliases
The plugin ships with path aliases for both backend and admin code.
| Context | Alias | Resolves to |
|---|---|---|
| Backend (server) | ||
| Admin (React) |
TypeScript — aliases are configured in both (backend) and (admin) and take effect immediately for type-checking.
Build — the script runs after to rewrite alias paths in the compiled output:
Admin Vite — to resolve aliases in the admin bundle, add the following to the host application's :
Architecture
The plugin registers three custom modules and a set of entity links that tie them to Medusa's core data model.
Quote lifecycle
Approval lifecycle
Modules
Manages companies and their employees.
| Field | Type | Notes |
|---|---|---|
| string | prefix | |
| string | ||
| string | ||
| string | nullable | |
| string | nullable | |
| string | nullable | |
| string | nullable | |
| string | nullable | |
| string | nullable | |
| string | nullable | |
| string | nullable | |
| enum | (default: ) |
| Field | Type | Notes |
|---|---|---|
| string | prefix | |
| BigNumber | = unlimited | |
| boolean | grants role | |
| FK → Company |
Service: — full CRUD via MedusaService: , , , , , , , , , .
Manages request-for-quote threads between customers and merchants.
| Field | Type | Notes |
|---|---|---|
| string | prefix | |
| enum | ||
| string | ||
| string | Medusa draft Order | |
| string | active OrderChange | |
| string | originating Cart |
| Field | Type | Notes |
|---|---|---|
| string | prefix | |
| string | ||
| string | nullable — optional line-item reference | |
| string | nullable — set when sent by admin | |
| string | nullable — set when sent by customer |
Service: — full CRUD for and .
Manages cart approval gates and company-level approval configuration.
| Field | Type | Notes |
|---|---|---|
| string | prefix | |
| string | ||
| boolean | default: | |
| boolean | default: |
| Field | Type | Notes |
|---|---|---|
| string | prefix | |
| string | ||
| enum | ||
| enum | ||
| string | customer who submitted | |
| string | nullable — admin or manager who acted |
Aggregate status for a cart — denormalized for fast lookup by cart hooks.
| Field | Type | Notes |
|---|---|---|
| string | prefix | |
| string | ||
| enum |
Service: — full CRUD + .
Entity Links
| Link | Left | Right | Cardinality |
|---|---|---|---|
| (b2b_company) | (core) | 1 : 1 | |
| (b2b_company) | (core) | 1 : 1 | |
| (b2b_company) | (core) | 1 : N | |
| (core) | (b2b_company) | 1 : 1 | |
| (b2b_company) | (b2b_approval) | 1 : 1 | |
| (core) | (b2b_approval) | 1 : N | |
| (core) | (b2b_approval) | 1 : 1 |
Quote → Order, Cart, OrderChange, Customer, and User relationships are registered as read-only virtual links via .
Workflows
Company
| ID | Description |
|---|---|
| Creates a company and its linked in a single atomic operation | |
| Updates company fields | |
| Deletes company and its associated | |
| Adds all current employees to the company's linked | |
| Removes all employees from the linked |
Employee
| ID | Description |
|---|---|
| Creates an employee record, links it to a Customer, optionally sets role, and adds the customer to the company's | |
| Updates or | |
| Removes the employee record |
Quote
| ID | Description |
|---|---|
| Snapshots the cart into a draft Order + OrderChange, then creates the Quote in status | |
| Advances quote to | |
| Sets quote status to | |
| Confirms the OrderChange, converts the draft Order to a live order, sets status | |
| Sets status to | |
| Generic quote status update | |
| Appends a to the quote thread |
Approval
| ID | Description |
|---|---|
| Creates and records and links both to the cart | |
| Updates approval status and syncs the cart's | |
| Creates for a company | |
| Toggles or |
Workflow hooks (injected into Medusa core)
| Hook point | Behavior |
|---|---|
| If is set on the cart, creates a Company → Cart link | |
| If is set, creates an Order → Company link | |
| Blocks item add when the cart has a pending approval | |
| Blocks cart update when a pending approval exists | |
| Blocks checkout if a pending approval exists or if the employee's spending limit would be exceeded |
REST API
Authentication
| Surface | Mechanism |
|---|---|
| Admin routes () | Medusa admin JWT () |
| Store routes () | Customer bearer token or session () |
| Role-guarded store routes | middleware — resolves role from |
Admin endpoints
Companies
| Method | Path | Description |
|---|---|---|
| List companies. Query: (searches name, email, phone, city), , | ||
| Create one or many companies | ||
| Retrieve company | ||
| Update company | ||
| Delete company | ||
| List employees of a company | ||
| Create employee | ||
| Retrieve employee | ||
| Update employee | ||
| Delete employee | ||
| Update approval settings | ||
| Get linked customer group | ||
| Link company to a customer group | ||
| Unlink customer group |
Quotes
| Method | Path | Description |
|---|---|---|
| List quotes. Query: (customer name/email), , , | ||
| Retrieve quote with messages and order preview | ||
| Send quote to customer (→ ) | ||
| Reject quote (→ ) | ||
| Append a message to the quote thread |
Approvals
| Method | Path | Description |
|---|---|---|
| List carts pending approval. Query: (company name), | ||
| Approve or reject. Body: |
Store endpoints
Companies
| Method | Path | Auth | Description |
|---|---|---|---|
| customer | Create company | ||
| customer | Retrieve company | ||
| customer | Update company | ||
| customer | Delete company | ||
| customer | List employees | ||
| company_admin | Create employee | ||
| customer | Retrieve employee | ||
| company_admin | Update employee | ||
| company_admin | Toggle approval requirements |
Quotes
| Method | Path | Auth | Description |
|---|---|---|---|
| customer | List quotes for the authenticated customer | ||
| customer | Create a Request for Quote from the current cart | ||
| customer | Retrieve quote | ||
| customer | Live order-change preview (pricing, items, totals) | ||
| customer | Accept quote | ||
| customer | Reject quote | ||
| customer | Append message |
Carts & approvals
| Method | Path | Auth | Description |
|---|---|---|---|
| customer | Submit cart for approval | ||
| customer | Add multiple line items in one request | ||
| customer | List approvals for the customer's company (company_admin view) | ||
| customer | Update approval status (company_admin) |
Pricing
| Method | Path | Auth | Description |
|---|---|---|---|
| none | Returns price rules with and conditions — used by storefronts to compute free-shipping thresholds |
Admin UI
The plugin registers the following pages in the Medusa admin shell under the route group.
| Route | Page | Description |
|---|---|---|
| Overview | Dashboard with stat cards: total companies, employees, pending quotes, pending approvals | |
| Companies | Searchable, paginated company table with inline create drawer | |
| Company detail | Employee roster, approval settings toggle, customer-group assignment | |
| Quotes | Filterable quote list (status, customer) | |
| Quote detail | Order preview, line items, cost breakdown, message thread, send / reject actions | |
| Quote management | Edit items and pricing within the draft order change | |
| Approval queue | Carts pending approval with approve / reject actions |
Component library
The plugin includes a shared component library under :
- — wrapper with column sorting, pagination, and pluggable filter components (, , )
- — + wrapper
- / — route-based focus modals for create and edit flows
- — kebab action dropdown
- — confirmation dialog for destructive actions
- — raw JSON section using
- Table cells — (formatted currency), (image + title)
React Query hooks
All data-fetching is handled via React Query hooks in : , , , , , , , , , , , , , , , , , .
Development
Project layout
Roadmap
-
Fix: check all typing issues and solve them.
-
Implement UI DataTable and useDataTable. Note: maybe not since the ConfigurableDataTable could be the new standard.
-
Implement ConfigurableDataTable for Employees in Company view.
-
For Employee created Customers in Company, make workflow to add them to the B2B Customer Group.
-
Integrate RBAC for approvals?
Approval Settings — How It Works Who is "admin" vs "sales manager"? There is no role system. The two flags on determine which approval types get created for a cart — not who acts on them:
- → creates an row with
- → creates an row with
The boolean exists on employees but the approval workflow never checks it. The field on an row is just a label — the > API doesn't enforce that only employees with can approve a row. Any authenticated user who knows the approval ID can call or .
The full flow
Company's ApprovalSettings has flags set (via admin drawer)
Store customer POSTs /store/b2b/carts/:id/approvals → createApprovalStep creates one Approval row per enabled flag → creates an ApprovalStatus row for the cart (status: "pending")
Cart checkout is blocked — completeCartWorkflow.validate hook throws NOT_ALLOWED if any Approval is still "pending"
Someone calls POST /admin/b2b/approvals/:id (or store equivalent) → updateApprovalStep sets that row's status + handled_by → updateApprovalStatusStep re-evaluates the cart: - All approved → ApprovalStatus = "approved" - Any rejected → ApprovalStatus = "rejected" (immediately)
Once all Approval rows are "approved", checkout can proceed Key implication The system is trust-based — there's no enforcement that only a "sales manager" employee can handle a approval. If your use case requires that, it would need to be added: e.g., check or a future field before allowing the approval action.
-
B2B / B2C product and price segmentation — control product visibility and assign prices per audience (B2B only, B2C only, or both), with support for audience-specific price lists. (stashed)
-
Full admin table feature parity — bring all table views in line with Medusa's native admin experience: view configurations (column visibility and ordering), server-side search, composable filter chains, and bulk actions. (use price-lists view as example)
License
MIT — see LICENSE.

