Core data model
Core adds companies, buyer memberships, company groups and addresses in the b2b_core module. Carts and orders remain native Medusa objects; CartContext and OrderContext link them to the company.
Overview
Customer (Medusa) ──< Buyer >── Company ──< CompanyAddress
│
└──< CompanyGroupMembership >── CompanyGroup
Cart (Medusa) ── CartContext ──> Company one company per cart
Order (Medusa) ── OrderContext ──> Company one company per orderA customer can belong to several companies. Each company has its own addresses and can belong to several company groups. A company cart or order is linked to exactly one company; personal purchases have no company context.
Objects
| Object | Main fields and rules |
|---|---|
Company | name, unique slug, currency_code (default eur), status (active or suspended), metadata. |
CompanyAddress | kind (billing or shipping), label, first_name, last_name, address_1, address_2, city, postal_code, country_code, province, phone, is_default_shipping. At most one non-deleted billing address and one default shipping address per company. |
Buyer | company_id, customer_id, active. One membership per company and customer. Revoke it by deactivating it; reactivate the same membership. |
CompanyGroup | name, description. |
CompanyGroupMembership | company_id, company_group_id. |
CartContext | unique cart_id, company_id, creator’s customer_id, origin. |
OrderContext | unique order_id, company_id, customer_id, origin, placed_by_actor_type, placed_by_actor_id, snapshot. |
CommerceSetting | mode: mixed or b2b_only. Read by Dashboard. |
Three technical objects complete the module: OrderPlacement (order provenance), CartHold (a purchase hold on a cart, owned by another module or by a Core cart-to-draft transfer) and CartDraftPreparation (preparing a draft order from a cart). All Core objects, like Medusa models, have an ID, timestamps and soft deletion.
Links to Medusa objects
Read them with Query:
| From | Alias | To |
|---|---|---|
Customer | customer.b2b_buyers | their buyer memberships (Buyer) |
Cart | cart.b2b_context | its company context (CartContext) |
Order | order.b2b_context | its company context (OrderContext) |
Data kept when an order is placed
- A shared cart keeps its creator, even when a colleague picks it up.
- The person who placed the order is in
OrderContext.placed_by_actor_typeandplaced_by_actor_id.Order.customer_idcan still point to the creator. - When your team creates an order for a company in the Admin, the order can belong to that company without a linked Medusa customer (
Order.customer_idis empty). The Admin user placing it is recorded separately. - When the order is placed, a snapshot records the company’s identity (id, name, slug, currency), the addresses and the contact email. Later changes to the company don’t rewrite past orders.
Rules
- Attaching a cart to the same company twice returns the existing link. Attaching it to another company is refused.
- Suspending a company blocks its buyers’ access to its Store routes. Merchants can still view and manage its orders in the Admin.
- Revoking a buyer’s membership keeps the history.
- A company with orders can’t be deleted through the API.
- Use Core workflows for writes. Direct CRUD service calls do not check the caller’s access or run the extension validators; reserve them for authorised backend code.