@spree/docs 0.1.95 → 0.1.97
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/api-reference/admin-api/monetary-amounts.md +91 -0
- package/dist/api-reference/store.yaml +198 -196
- package/dist/developer/cli/admin-api.md +25 -3
- package/dist/developer/cli/quickstart.md +2 -2
- package/dist/developer/core-concepts/orders.md +2 -2
- package/dist/developer/core-concepts/pricing.md +7 -7
- package/dist/developer/core-concepts/products.md +4 -4
- package/dist/developer/core-concepts/store-credits-gift-cards.md +7 -7
- package/package.json +1 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Monetary Amounts"
|
|
3
|
+
sidebarTitle: "Monetary Amounts"
|
|
4
|
+
description: "How the Admin API represents money as decimal strings, why JSON numbers are avoided, and how to send prices, costs, and amounts safely in requests."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
All monetary values in the Admin API are **strings** (e.g., `"29.99"`, `"0.0"`), both in responses and in request bodies. This preserves decimal precision and avoids the floating-point rounding issues common with JSON numbers — critical when an admin is setting prices and costs.
|
|
8
|
+
|
|
9
|
+
## Reading
|
|
10
|
+
|
|
11
|
+
Every monetary field is returned as a string, alongside a `display_` companion that includes currency formatting:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"amount": "29.99",
|
|
16
|
+
"display_amount": "$29.99",
|
|
17
|
+
"compare_at_amount": "39.99",
|
|
18
|
+
"display_compare_at_amount": "$39.99"
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Use `display_*` for rendering and the raw string fields for calculations (`parseFloat(price.amount)`).
|
|
23
|
+
|
|
24
|
+
## Writing
|
|
25
|
+
|
|
26
|
+
Send amounts back as strings too, so a value reads and writes in the same type:
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
```typescript Admin SDK
|
|
30
|
+
await client.products.create({
|
|
31
|
+
name: 'Classic Tee',
|
|
32
|
+
prices: [{ currency: 'USD', amount: '29.99', compare_at_amount: '39.99' }],
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```bash CLI
|
|
37
|
+
spree api post /products -d '{"name":"Classic Tee","prices":[{"currency":"USD","amount":"29.99","compare_at_amount":"39.99"}]}'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
JSON numbers are also accepted (`"amount": 29.99`), but strings are recommended: they round-trip with what the API returns and sidestep float precision. A `null` clears the value.
|
|
42
|
+
|
|
43
|
+
### Localized input
|
|
44
|
+
|
|
45
|
+
Amounts may be sent in the active locale's number format — Spree parses the locale's decimal separator and thousands delimiter. Under a `de` context, `1.299,00` parses to `1299.00`:
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
```typescript Admin SDK
|
|
49
|
+
await client.products.create({
|
|
50
|
+
name: 'Designer Bag',
|
|
51
|
+
prices: [{ currency: 'EUR', amount: '1.299,00' }],
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```bash CLI
|
|
56
|
+
spree api post /products -d '{"name":"Designer Bag","prices":[{"currency":"EUR","amount":"1.299,00"}]}'
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
Only the string form can express a localized amount — a JSON number literal cannot represent `1.299,00`.
|
|
61
|
+
|
|
62
|
+
## Affected types
|
|
63
|
+
|
|
64
|
+
This convention applies to all monetary fields across all resources, including back-office-only fields the Store API never exposes:
|
|
65
|
+
|
|
66
|
+
| Resource | Monetary Fields |
|
|
67
|
+
|----------|----------------|
|
|
68
|
+
| **Product / Variant** | `price`, `compare_at_amount`, `cost_price` |
|
|
69
|
+
| **Price** | `amount`, `compare_at_amount` |
|
|
70
|
+
| **Order** | `total`, `item_total`, `ship_total`, `tax_total`, `adjustment_total`, `promo_total`, `included_tax_total`, `additional_tax_total` |
|
|
71
|
+
| **Line Item** | `price`, `total`, `adjustment_total`, `promo_total`, `pre_tax_amount`, `discounted_amount`, `compare_at_amount` |
|
|
72
|
+
| **Payment** | `amount` |
|
|
73
|
+
| **Refund** | `amount` |
|
|
74
|
+
| **Shipment** | `cost` |
|
|
75
|
+
| **Gift Card** | `amount`, `amount_used`, `amount_authorized`, `amount_remaining` |
|
|
76
|
+
| **Store Credit** | `amount`, `amount_used`, `amount_remaining` |
|
|
77
|
+
|
|
78
|
+
### Amounts inside `preferences`
|
|
79
|
+
|
|
80
|
+
Calculators and some promotion rules carry their amounts inside an untyped `preferences` object (`Record<string, unknown>`) rather than as top-level fields. The same string convention applies to the money-valued keys within that hash — they read back as strings and accept strings (and localized strings) on write. The keys that are money:
|
|
81
|
+
|
|
82
|
+
| Resource | Money keys in `preferences` |
|
|
83
|
+
|----------|------------------------------|
|
|
84
|
+
| **Calculator** `flat_rate`, `per_item`, `digital_delivery` | `amount` |
|
|
85
|
+
| **Calculator** `flexi_rate` | `first_item`, `additional_item` |
|
|
86
|
+
| **Calculator** `price_sack` | `minimal_amount`, `normal_amount`, `discount_amount` |
|
|
87
|
+
| **Calculator** `tiered_flat_rate` | `base_amount`, and the values of `tiers` |
|
|
88
|
+
| **Calculator** `flat_rate` (shipping) | `amount`, `minimum_item_total`, `maximum_item_total` |
|
|
89
|
+
| **Promotion Rule** `item_total` | `amount_min`, `amount_max` |
|
|
90
|
+
|
|
91
|
+
Percentage keys (`percent`, `flat_percent`, `base_percent`), weights (`minimum_weight`, `maximum_weight`), and quantities (`max_items`, `min_quantity`) are **not** money — those stay numbers. Promotion actions (`create_adjustment`, `create_item_adjustments`) hold their money inside a nested `calculator.preferences`, per the calculator rows above.
|