B2B company accounts, buyer roles and approval workflows

Type
Concept
Applies to
Medusa v2.x
Updated

Short answer

Medusa handles B2B company accounts through the official B2B Starter. A Company module groups employees, each linked to a customer with a spending limit and an admin flag. An Approval module requires company admin or sales manager approval before checkout. Value-based or multi-level approval rules are custom, built with workflow hooks.

How company accounts work in the Medusa B2B Starter

Company accounts in Medusa come from the official Medusa B2B Starter, not from Medusa core. The starter adds a Company module with two data models:

  • Company: name, email, phone, address, Copy to clipboardcurrency_code, and Copy to clipboardspending_limit_reset_frequency. A company has many employees.
  • Employee: belongs to one company, is linked to a Medusa customer, and has a Copy to clipboardspending_limit and an Copy to clipboardis_admin flag.

A company can be linked to a customer group. The starter then adds every employee to that group, so price lists with a customer group condition give all employees the company's negotiated prices. The B2B recipe describes the same pattern of linking a custom Company module to customers and groups.

Buyer roles in Medusa

The Medusa B2B Starter has two buyer roles. A company admin (Copy to clipboardis_admin set to true) manages the company and handles approvals in the storefront. An employee places orders within their spending limit. The starter's store approval routes check for the Copy to clipboardcompany_admin role before letting a customer approve or reject.

Finer-grained roles, such as a role that can quote but not order, are Custom. You add them by extending the Employee model and the route middleware.

How spending limits work

Spending limits in the B2B Starter are enforced at checkout. The starter consumes the Copy to clipboardvalidate hook of Medusa's completeCartWorkflow, which runs before the order is created and payment is authorized. If the cart would push the employee past their spending limit for the current period, the hook throws and the order is not placed.

Each company sets how often limits reset: never, daily, weekly, monthly, or yearly. The default is monthly.

How purchase approval workflows work

Purchase approvals in the B2B Starter live in an Approval module. Each company has approval settings with two switches: Copy to clipboardrequires_admin_approval and Copy to clipboardrequires_sales_manager_approval.

  1. An employee submits their cart for approval. The starter creates one pending approval per enabled type: Copy to clipboardadmin, Copy to clipboardsales_manager, or both.
  2. While an approval is pending, Copy to clipboardvalidate hooks on add-to-cart and cart completion block changes and checkout.
  3. A company admin approves or rejects Copy to clipboardadmin approvals from the storefront. A merchant user handles Copy to clipboardsales_manager approvals in Medusa Admin.
  4. Once every approval is granted, the employee completes checkout.

How to add multi-level approval rules

Approval rules by order value or role, with several approval levels, are Custom in Medusa. The B2B Starter gives you the pieces to build them:

  1. Add a rule data model to the Approval module, for example a minimum cart total, the approver role, and a level.
  2. When an employee submits a cart, create one approval per matching rule instead of per switch.
  3. Block checkout until every required approval is granted, using the same hook the starter uses:
import { completeCartWorkflow } from "@medusajs/medusa/core-flows"
import { MedusaError } from "@medusajs/framework/utils"
completeCartWorkflow.hooks.validate(async ({ cart }, { container }) => {
const approved = await allRequiredApprovalsGranted(cart.id, container)
if (!approved) {
throw new MedusaError(MedusaError.Types.NOT_ALLOWED, "Cart needs approval")
}
})

Copy to clipboardallRequiredApprovalsGranted is your own function that reads the cart's approvals with Query and compares them to the rules. Learn more about workflow hooks.

Company accounts and approvals: Medusa vs other B2B platforms

PlatformBuyer rolesApprovalsSpending limits
Medusa (Starter)Company admin, employeeCompany admin and sales manager, per companyPer employee, periodic reset
Adobe Commerce B2BRoles and permissions per companyPurchase order approval rules by role and orderCheck vendor docs
BigCommerce B2B EditionCompany roles and permissionsCheck vendor docsCheck vendor docs
OroCommerceStorefront roles, business unitsConfigurable workflowsCheck vendor docs
Shopify B2BOrdering only, Location adminMerchant reviews submitted ordersCheck vendor docs

When Medusa is not the right choice for company accounts and approvals

Medusa is a weaker fit if you need many predefined buyer roles or value-based approval rules without writing code. Adobe Commerce B2B and BigCommerce B2B Edition document configurable role and permission systems. Teams without developers should also look at Shopify B2B, which is configured from the admin.

Common questions

Are company accounts part of Medusa core?

No. Company accounts, employees, and approvals come from the Medusa B2B Starter as custom modules. Medusa core provides customers and customer groups, which the starter links companies to.

Do company employees get company-specific prices in Medusa?

Yes. When you link a company to a customer group in the B2B Starter, its employees are added to that group, and price lists with that customer group condition apply to them.

Can an employee belong to more than one company?

Not in the Medusa B2B Starter. Its Employee model belongs to a single company. Supporting several companies per buyer is custom work.

Can Medusa approvals depend on the order total?

Not out of the box. The B2B Starter's approval settings are per-company switches. You add value-based rules by extending the Approval module and the completeCartWorkflow validate hook.