@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.
- package/dist/developer/core-concepts/addresses.md +106 -198
- package/dist/developer/core-concepts/architecture.md +97 -126
- package/dist/developer/core-concepts/calculators.md +75 -252
- package/dist/developer/core-concepts/carts.md +1 -1
- package/dist/developer/core-concepts/catalogs.md +140 -0
- package/dist/developer/core-concepts/channels.md +0 -4
- package/dist/developer/core-concepts/commissions.md +253 -0
- package/dist/developer/core-concepts/companies.md +240 -0
- package/dist/developer/core-concepts/customers.md +0 -3
- package/dist/developer/core-concepts/discounts.md +133 -0
- package/dist/developer/core-concepts/events.md +83 -576
- package/dist/developer/core-concepts/fees.md +144 -0
- package/dist/developer/core-concepts/imports-exports.md +105 -679
- package/dist/developer/core-concepts/inventory.md +114 -248
- package/dist/developer/core-concepts/markets.md +9 -12
- package/dist/developer/core-concepts/media.md +127 -16
- package/dist/developer/core-concepts/metafields.md +123 -200
- package/dist/developer/core-concepts/order-totals.md +110 -0
- package/dist/developer/core-concepts/orders.md +1 -1
- package/dist/developer/core-concepts/payments.md +11 -14
- package/dist/developer/core-concepts/pricing.md +11 -13
- package/dist/developer/core-concepts/products.md +191 -62
- package/dist/developer/core-concepts/promotions.md +12 -11
- package/dist/developer/core-concepts/search-filtering.md +2 -4
- package/dist/developer/core-concepts/sellers.md +210 -0
- package/dist/developer/core-concepts/staff-roles.md +56 -23
- package/dist/developer/core-concepts/store-credits-gift-cards.md +0 -3
- package/dist/developer/core-concepts/taxes.md +125 -113
- package/dist/developer/core-concepts/translations.md +61 -68
- package/dist/developer/core-concepts/webhooks.md +25 -59
- package/dist/developer/how-to/custom-promotion.md +3 -3
- package/package.json +1 -1
- package/dist/developer/core-concepts/companies-and-catalogs.md +0 -81
- package/dist/developer/core-concepts/taxes-discounts-fees.md +0 -199
|
@@ -1,176 +1,147 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Architecture
|
|
3
|
-
description:
|
|
3
|
+
description: How Spree fits together — the catalog, the cart, the order, and fulfillment — and the two APIs you build against.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
## Overview
|
|
7
7
|
|
|
8
|
-
Spree is a commerce engine
|
|
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
|
-
|
|
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
|
-
##
|
|
12
|
+
## The shape of a purchase
|
|
13
13
|
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
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
|
-
|
|
37
|
+
## How the pieces relate
|
|
69
38
|
|
|
70
39
|
```mermaid
|
|
71
40
|
erDiagram
|
|
72
|
-
Store ||--o{
|
|
73
|
-
Store ||--o{
|
|
41
|
+
Store ||--o{ Product : "sells"
|
|
42
|
+
Store ||--o{ Order : "records"
|
|
74
43
|
|
|
75
44
|
Product ||--o{ Variant : "has many"
|
|
76
|
-
Product }o
|
|
77
|
-
Product }o--||
|
|
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 : "
|
|
81
|
-
Variant ||--o{
|
|
82
|
-
|
|
48
|
+
Variant ||--o{ Price : "priced in each currency"
|
|
49
|
+
Variant ||--o{ StockLevel : "stocked at locations"
|
|
50
|
+
StockLevel }o--|| StockLocation : "held at"
|
|
83
51
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
69
|
+
Three things in that diagram are worth calling out, because they're where Spree differs from what you might expect:
|
|
99
70
|
|
|
100
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
77
|
+
## The two APIs
|
|
110
78
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
102
|
+
Spree assumes you'll extend it, and gives you three ways in that survive an upgrade:
|
|
131
103
|
|
|
132
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
114
|
+
One Spree installation can run more than one business:
|
|
144
115
|
|
|
145
|
-
|
|
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
|
-
|
|
121
|
+
## What you install
|
|
148
122
|
|
|
149
|
-
|
|
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
|
-
|
|
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
|
-
**
|
|
131
|
+
**TypeScript:**
|
|
156
132
|
|
|
157
|
-
| Package |
|
|
158
|
-
|
|
159
|
-
| `
|
|
160
|
-
| `
|
|
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
|
-
**
|
|
139
|
+
> **INFO:** Spree runs on PostgreSQL, MySQL or SQLite. PostgreSQL is recommended for production — [database configuration](../deployment/database.md).
|
|
163
140
|
|
|
164
|
-
|
|
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
|
-
- [
|
|
173
|
-
- [
|
|
174
|
-
- [
|
|
175
|
-
- [
|
|
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.
|