@spree/docs 0.1.182 → 0.1.184

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/developer/core-concepts/addresses.md +106 -198
  2. package/dist/developer/core-concepts/architecture.md +97 -126
  3. package/dist/developer/core-concepts/calculators.md +75 -252
  4. package/dist/developer/core-concepts/carts.md +1 -1
  5. package/dist/developer/core-concepts/catalogs.md +140 -0
  6. package/dist/developer/core-concepts/channels.md +0 -4
  7. package/dist/developer/core-concepts/commissions.md +253 -0
  8. package/dist/developer/core-concepts/companies.md +240 -0
  9. package/dist/developer/core-concepts/customers.md +0 -3
  10. package/dist/developer/core-concepts/discounts.md +133 -0
  11. package/dist/developer/core-concepts/events.md +83 -576
  12. package/dist/developer/core-concepts/fees.md +144 -0
  13. package/dist/developer/core-concepts/imports-exports.md +105 -679
  14. package/dist/developer/core-concepts/inventory.md +114 -248
  15. package/dist/developer/core-concepts/markets.md +9 -12
  16. package/dist/developer/core-concepts/media.md +127 -16
  17. package/dist/developer/core-concepts/metafields.md +123 -200
  18. package/dist/developer/core-concepts/order-totals.md +110 -0
  19. package/dist/developer/core-concepts/orders.md +1 -1
  20. package/dist/developer/core-concepts/payments.md +11 -14
  21. package/dist/developer/core-concepts/pricing.md +11 -13
  22. package/dist/developer/core-concepts/products.md +191 -62
  23. package/dist/developer/core-concepts/promotions.md +12 -11
  24. package/dist/developer/core-concepts/search-filtering.md +2 -4
  25. package/dist/developer/core-concepts/sellers.md +210 -0
  26. package/dist/developer/core-concepts/staff-roles.md +56 -23
  27. package/dist/developer/core-concepts/store-credits-gift-cards.md +0 -3
  28. package/dist/developer/core-concepts/taxes.md +125 -113
  29. package/dist/developer/core-concepts/translations.md +61 -68
  30. package/dist/developer/core-concepts/webhooks.md +25 -59
  31. package/dist/developer/how-to/custom-promotion.md +3 -3
  32. package/package.json +1 -1
  33. package/dist/developer/core-concepts/companies-and-catalogs.md +0 -81
  34. package/dist/developer/core-concepts/taxes-discounts-fees.md +0 -199
@@ -1,176 +1,147 @@
1
1
  ---
2
2
  title: Architecture
3
- description: Explore how Spree's core models, APIs, and gems fit together — catalog, shopping, checkout, fulfillment, and pricingfor headless or embedded commerce.
3
+ description: How Spree fits together — the catalog, the cart, the order, and fulfillmentand the two APIs you build against.
4
4
  ---
5
5
 
6
6
  ## Overview
7
7
 
8
- Spree is a commerce engine built around interconnected models that represent the core concepts of commerce: products, orders, payments, and shipments. It adapts to your stack use it as a headless API for any frontend, embed it into an existing application, or scale it from a single storefront to a global multi-vendor marketplace.
8
+ Spree is a commerce engine you drive through a REST API. It holds the catalog, works out what a customer owes, takes the money, and tracks what was sent. You build the storefront, the mobile app, or the internal tool on top of it.
9
9
 
10
- > **INFO:** Spree supports PostgreSQL, MySQL, and SQLite. PostgreSQL is recommended for production. [Learn more about database configuration](../deployment/database.md).
10
+ There is no built-in storefront you have to accept. Everything a customer-facing app needs is on the Store API, and everything a back office needs is on the Admin API. Both ship as typed TypeScript clients.
11
11
 
12
- ## Core Commerce Flow
12
+ ## The shape of a purchase
13
13
 
14
- The following diagram shows how the main models interact during a typical customer purchase:
14
+ Four things carry a purchase from browsing to delivery. Each one has a job the others don't:
15
15
 
16
- ```mermaid
17
- flowchart TB
18
- subgraph Catalog["Catalog"]
19
- Product --> Variant
20
- Variant --> Price
21
- Variant --> StockItem
22
- StockItem --> StockLocation
23
- end
24
-
25
- subgraph Shopping["Shopping"]
26
- User --> Order
27
- Order --> LineItem
28
- LineItem --> Variant
29
- end
30
-
31
- subgraph Checkout["Checkout"]
32
- Order --> Address
33
- Order --> Shipment
34
- Order --> Payment
35
- Shipment --> ShippingMethod
36
- Payment --> PaymentMethod
37
- end
38
-
39
- subgraph Fulfillment["Fulfillment"]
40
- Shipment --> InventoryUnit
41
- InventoryUnit --> Variant
42
- StockLocation --> Shipment
43
- end
44
-
45
- subgraph Pricing["Pricing & Adjustments"]
46
- Order --> Adjustment
47
- LineItem --> Adjustment
48
- Shipment --> Adjustment
49
- TaxRate --> Adjustment
50
- Promotion --> Adjustment
51
- end
52
- ```
53
-
54
- **How it works:**
55
16
 
56
- 1. **Catalog** — [Products](products.md) have [Variants](products.md#variants) (SKUs) with prices and inventory tracked at [Stock Locations](inventory.md#stock-locations)
17
+ - [Product](products.md) What you sell. A product has variants the actual buyable items, each with its own price and stock.
18
+ - [Cart](carts.md) — What a customer is assembling. It changes constantly and is usually abandoned.
19
+ - [Order](orders.md) — What they committed to. A permanent financial record that must not change quietly.
20
+ - [Fulfillment](fulfillments.md) — What actually ships. One parcel, from one location, with one tracking number.
57
21
 
58
- 2. **Shopping** — Customers add Variants to their cart, creating an [Order](orders.md) with Line Items
59
22
 
60
- 3. **Checkout** — The Order collects [Addresses](addresses.md), calculates [Shipping](fulfillments.md) options, and processes [Payments](payments.md)
61
-
62
- 4. **Fulfillment** — [Shipments](fulfillments.md) are created from Stock Locations, tracking individual [Inventory Units](inventory.md#inventory-units)
63
-
64
- 5. **Pricing & Adjustments** — [Taxes](taxes.md) and [Promotions](promotions.md) create [Adjustments](taxes-discounts-fees.md) that modify order totals
23
+ ```mermaid
24
+ flowchart LR
25
+ Product --> Variant
26
+ Variant --> Cart
27
+ Cart -->|complete| Order
28
+ Order --> Fulfillment
29
+ Order --> Payment
30
+
31
+ style Cart fill:#e3f2fd,stroke:#0077ff
32
+ style Order fill:#e8f5e9,stroke:#2e7d32
33
+ ```
65
34
 
66
- ## Core Model Relationships
35
+ **A cart and an order are separate records**, and that distinction shapes most of the API. A cart tolerates half-finished states — no address yet, no payment chosen. An order has to keep saying what the customer actually agreed to pay, so once it exists, today's prices and promotions can't quietly rewrite it. Completing a cart creates the order.
67
36
 
68
- This diagram shows the key database relationships between Spree's main models:
37
+ ## How the pieces relate
69
38
 
70
39
  ```mermaid
71
40
  erDiagram
72
- Store ||--o{ Order : "has many"
73
- Store ||--o{ Product : "has many"
41
+ Store ||--o{ Product : "sells"
42
+ Store ||--o{ Order : "records"
74
43
 
75
44
  Product ||--o{ Variant : "has many"
76
- Product }o--|| TaxCategory : "belongs to"
77
- Product }o--|| ShippingCategory : "belongs to"
78
- Product }o--o{ Taxon : "categorized by"
45
+ Product }o--o{ Category : "filed under"
46
+ Product }o--|| DeliveryProfile : "ships by"
79
47
 
80
- Variant ||--o{ Price : "has many"
81
- Variant ||--o{ StockItem : "has many"
82
- Variant ||--o{ LineItem : "has many"
48
+ Variant ||--o{ Price : "priced in each currency"
49
+ Variant ||--o{ StockLevel : "stocked at locations"
50
+ StockLevel }o--|| StockLocation : "held at"
83
51
 
84
- Order ||--o{ LineItem : "has many"
85
- Order ||--o{ Shipment : "has many"
86
- Order ||--o{ Payment : "has many"
87
- Order ||--o{ Adjustment : "has many"
88
- Order }o--|| User : "belongs to"
89
- Order }o--|| Address : "ship address"
90
- Order }o--|| Address : "bill address"
91
-
92
- Shipment ||--o{ InventoryUnit : "has many"
93
- Shipment }o--|| StockLocation : "ships from"
94
- Shipment }o--|| ShippingMethod : "via"
52
+ Cart ||--o{ LineItem : "has many"
53
+ Cart ||--o| Order : "completes into"
54
+ LineItem }o--|| Variant : "of"
95
55
 
56
+ Order ||--o{ LineItem : "has many"
57
+ Order ||--o{ Fulfillment : "shipped as"
58
+ Order ||--o{ Payment : "paid by"
59
+ Order ||--o{ TaxLine : "taxed by"
60
+ Order ||--o{ Discount : "reduced by"
61
+ Order ||--o{ Fee : "surcharged by"
62
+ Order }o--|| Customer : "placed by"
63
+
64
+ Fulfillment }o--|| DeliveryMethod : "via"
65
+ Fulfillment }o--|| StockLocation : "ships from"
96
66
  Payment }o--|| PaymentMethod : "via"
67
+ ```
97
68
 
98
- StockLocation ||--o{ StockItem : "has many"
69
+ Three things in that diagram are worth calling out, because they're where Spree differs from what you might expect:
99
70
 
100
- TaxRate }o--|| TaxCategory : "belongs to"
101
- TaxRate }o--|| Zone : "applies to"
102
- TaxRate ||--o{ Adjustment : "creates"
71
+ **Money added or removed is never one mixed list.** Tax, discounts and fees are three separate kinds of row. "What tax did we charge?" is a direct question with a direct answer instead of a filter over a mixed pile. See [Order totals](order-totals.md).
103
72
 
104
- Promotion ||--o{ Adjustment : "creates"
105
- ```
73
+ **Delivery is described by a profile, not a category.** A [delivery profile](fulfillments.md) says how a product travels — physically shipped, or digital — and which locations and methods serve it.
106
74
 
107
- ## APIs
75
+ **Stock lives per location.** A variant has a stock level at each [stock location](inventory.md), so availability is a real question about real warehouses rather than a single number.
108
76
 
109
- Spree exposes two REST APIs:
77
+ ## The two APIs
110
78
 
111
- | API | Purpose | Authentication |
112
- |-----|---------|----------------|
113
- | [**Store API**](../../api-reference/store-api/introduction.md) | Customer-facing — cart, checkout, products, account | [Publishable API key + JWT](../../api-reference/store-api/authentication.md) |
114
- | [**Admin API**](../../api-reference/admin-api/introduction.md) | Operational — manage products, orders, customers, settings | [Secret API key](../../api-reference/admin-api/authentication.md) + JWT |
79
+ ```mermaid
80
+ flowchart TB
81
+ Storefront["Storefront / mobile app"] -->|"@spree/sdk"| StoreAPI["Store API"]
82
+ BackOffice["Dashboard / integrations"] -->|"@spree/admin-sdk"| AdminAPI["Admin API"]
83
+ StoreAPI --> Spree[(Spree)]
84
+ AdminAPI --> Spree
85
+ Spree --> Webhooks["Webhooks & events"]
86
+ Webhooks --> External["Your systems"]
87
+ ```
115
88
 
116
- Both APIs share the same list shapes, filtering, querying, and pagination, and offer fully typed TypeScript clients — [@spree/sdk](../sdk/quickstart.md) for the Store API and [@spree/admin-sdk](../sdk/admin/quickstart.md) for the Admin API.
89
+ | API | For | Authentication |
90
+ |---|---|---|
91
+ | [**Store API**](../../api-reference/store-api/introduction.md) | Anything a customer touches — browsing, cart, checkout, their account | [Publishable key](../../api-reference/store-api/authentication.md), plus a customer token once signed in |
92
+ | [**Admin API**](../../api-reference/admin-api/introduction.md) | Anything staff or systems touch — catalog, orders, settings | [Secret key](../../api-reference/admin-api/authentication.md) with scopes, or a staff token |
117
93
 
118
- Events from both APIs can trigger [Webhooks](webhooks.md) to notify external systems in real time.
94
+ The split is about exposure, not convenience. A publishable key is safe in browser code because it can only reach what a shopper is allowed to see. A secret key never belongs in a browser.
119
95
 
120
- ## Multi-Store Architecture
96
+ Both APIs share the same filtering, pagination and error shapes, so what you learn on one carries to the other. Both return **prefixed IDs** — `prod_86Rf07xd4z`, `cart_k5nR8xLq` — so an ID tells you what it points at.
121
97
 
122
- Spree supports running [multiple storefronts](../multi-tenant/quickstart.md) from a single installation. Each Store can have:
98
+ > **NOTE:** Money is always a **string**: `"135.60"`, never `135.60`. JavaScript can't represent every decimal exactly — `0.1 + 0.2` gives `0.30000000000000004` — which is not something you want inside a price. Every amount also comes formatted for its currency as `display_total`, `display_price` and so on. Render the `display_` one.
123
99
 
124
- - Its own domain and branding
125
- - Different currencies and locales
126
- - Separate product catalogs
127
- - Independent payment and shipping methods
128
- - Isolated orders and customers
100
+ ## Building on top
129
101
 
130
- This makes Spree suitable for multi-brand retailers, international expansion, or B2B/B2C hybrid setups.
102
+ Spree assumes you'll extend it, and gives you three ways in that survive an upgrade:
131
103
 
132
- ## Extension Points
104
+ | Approach | Use it for | Guide |
105
+ |---|---|---|
106
+ | **Webhooks** | Telling another system something happened — an ERP, a warehouse, an email tool | [Webhooks](webhooks.md) |
107
+ | **Custom fields** | Storing your own data on a product, order or customer without changing the schema | [Custom Fields](metafields.md) |
108
+ | **Providers** | Plugging in a real service for tax, delivery rates, payments or search | [Providers](../providers/overview.md) |
133
109
 
134
- Spree is designed to be customized without modifying core code. The main extension mechanisms are:
110
+ For merchant-managed data, reach for [custom fields](metafields.md) before anything heavier they're queryable and editable in the dashboard without touching code.
135
111
 
136
- | Mechanism | Use Case | Documentation |
137
- |-----------|----------|---------------|
138
- | **Events & Subscribers** | React to order completion, payment, shipment events | [Events Guide](events.md) |
139
- | **Webhooks** | Notify external systems of changes | [Webhooks Guide](webhooks.md) |
140
- | **Dependencies** | Swap out services (tax calculation, shipping estimation) | [Dependencies Guide](../customization/dependencies.md) |
141
- | **Decorators** | Modify existing core models & classes behavior (use sparingly) | [Decorators Guide](../customization/decorators.md) |
112
+ ## Multi-store, multi-market, multi-seller
142
113
 
143
- > **INFO:** For most customizations, prefer **Events** and **Dependencies** over Decorators. They're easier to maintain and won't break during upgrades.
114
+ One Spree installation can run more than one business:
144
115
 
145
- ## Packages
116
+ - **[Stores](stores.md)** are separate businesses — their own catalog, orders, customers and settings. Data does not cross between them.
117
+ - **[Channels](channels.md)** are the ways one store sells: a website, a mobile app, a retail till.
118
+ - **[Markets](markets.md)** are the regions a store sells into, each with its currency, locale and tax treatment.
119
+ - **[Sellers](products.md#seller-submissions)** let one store list goods from many vendors, for a marketplace.
146
120
 
147
- Spree is distributed as a set of packages:
121
+ ## What you install
148
122
 
149
- **Core (required):**
123
+ | Package | What it is |
124
+ |---|---|
125
+ | `spree` | The engine — catalog, checkout, payments, both APIs |
126
+ | `spree_emails` | Transactional email, if you don't send your own |
127
+ | `spree_dashboard` | The back-office dashboard |
150
128
 
151
- | Package | Purpose |
152
- |---------|---------|
153
- | `spree` | Models, services, business logic, Store API, Admin API, and Webhooks |
129
+ Providers for search, delivery rates, tax and payments install separately, so you only carry what you use.
154
130
 
155
- **Optional:**
131
+ **TypeScript:**
156
132
 
157
- | Package | Purpose |
158
- |---------|---------|
159
- | `spree_admin` | Admin dashboard for managing your store |
160
- | `spree_emails` | Transactional email templates (order confirmation, shipping, etc.) |
133
+ | Package | What it is |
134
+ |---|---|
135
+ | [`@spree/sdk`](../sdk/quickstart.md) | Store API client — for your storefront |
136
+ | [`@spree/admin-sdk`](../sdk/admin/quickstart.md) | Admin API client for back-office and integrations |
137
+ | [`@spree/cli`](../cli/quickstart.md) | Command line for local setup and calling the Admin API |
161
138
 
162
- **TypeScript packages:**
139
+ > **INFO:** Spree runs on PostgreSQL, MySQL or SQLite. PostgreSQL is recommended for production — [database configuration](../deployment/database.md).
163
140
 
164
- | Package | Purpose |
165
- |---------|---------|
166
- | [`@spree/sdk`](../sdk/quickstart.md) | TypeScript SDK for the Store API |
167
- | [`@spree/admin-sdk`](../sdk/admin/quickstart.md) | TypeScript SDK for the Admin API |
168
- | [`@spree/cli`](../cli/quickstart.md) | Command line interface for managing local environment and using the Admin API from the terminal |
141
+ ## Where to go next
169
142
 
170
- ## Related Documentation
171
143
 
172
- - [Products](products.md) — Product catalog and variants
173
- - [Orders](orders.md) — Order lifecycle and state machine
174
- - [Payments](payments.md) — Payment processing
175
- - [Shipments](fulfillments.md) — Shipping and fulfillment
176
- - [Customization Quickstart](../customization/quickstart.md) — How to extend Spree
144
+ - [Quickstart](../getting-started/quickstart.md) — Get an installation running.
145
+ - [Store SDK](../sdk/quickstart.md) — Build a storefront against the Store API.
146
+ - [Products](products.md) — How the catalog is modelled.
147
+ - [Carts](carts.md) — Cart, checkout, and what completion guarantees.