@spree/docs 0.1.250 → 0.1.252
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.
|
@@ -250,7 +250,7 @@ For providers like Stripe, create a payment session and confirm it with their ow
|
|
|
250
250
|
const order = await client.carts.complete(cartId)
|
|
251
251
|
```
|
|
252
252
|
|
|
253
|
-
You get back an [Order](orders.md).
|
|
253
|
+
You get back an [Order](orders.md) — or, in a marketplace where the cart held several sellers' goods, an [order group](sellers.md#one-checkout-several-sellers) holding one order per seller. Tell them apart with `isOrderGroup` from `@spree/sdk`.
|
|
254
254
|
|
|
255
255
|
|
|
256
256
|
Discount codes, gift cards and store credit can be applied any time before completion:
|
|
@@ -246,6 +246,15 @@ Two details worth knowing:
|
|
|
246
246
|
> A back office must handle it too: an order raised from the admin divides the same way, so completing one may answer with a group instead of an order.
|
|
247
247
|
|
|
248
248
|
|
|
249
|
+
```typescript Store SDK
|
|
250
|
+
import { isOrderGroup } from '@spree/sdk'
|
|
251
|
+
|
|
252
|
+
const result = await client.carts.complete(cartId, { spreeToken: cart.token })
|
|
253
|
+
|
|
254
|
+
// One order per seller when the cart held several sellers' goods.
|
|
255
|
+
const orders = isOrderGroup(result) ? result.orders : [result]
|
|
256
|
+
```
|
|
257
|
+
|
|
249
258
|
```typescript Admin SDK
|
|
250
259
|
import { isOrderGroup } from '@spree/admin-sdk'
|
|
251
260
|
|
|
@@ -122,9 +122,26 @@ await client.carts.update(cartId, {
|
|
|
122
122
|
### Complete Checkout
|
|
123
123
|
|
|
124
124
|
```typescript
|
|
125
|
-
|
|
125
|
+
import { isOrderGroup } from '@spree/sdk';
|
|
126
|
+
|
|
127
|
+
const result = await client.carts.complete(cartId, { spreeToken: cart.token });
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Completing a cart usually returns one order. In a [marketplace](../../core-concepts/sellers.md#one-checkout-several-sellers), a cart holding several sellers' goods divides into one order per seller, and the response is the **order group** that ties them together: one purchase, one payment, combined totals, and the per-seller orders in `orders`. Use `isOrderGroup` to tell the two apart:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
if (isOrderGroup(result)) {
|
|
134
|
+
// One purchase, shown to the customer under the group's number and total.
|
|
135
|
+
console.log(result.number, result.display_total);
|
|
136
|
+
// How it will arrive: one order per seller, each with its own items and delivery.
|
|
137
|
+
result.orders.forEach((order) => console.log(order.number, order.items));
|
|
138
|
+
} else {
|
|
139
|
+
console.log(result.number, result.display_total);
|
|
140
|
+
}
|
|
126
141
|
```
|
|
127
142
|
|
|
143
|
+
A storefront that never sells through more than one seller always gets an order back, but checking costs nothing and keeps the confirmation page working if sellers are added later.
|
|
144
|
+
|
|
128
145
|
### Fulfillments
|
|
129
146
|
|
|
130
147
|
Fulfillments are included in the cart response — there is no separate list endpoint.
|
|
@@ -313,13 +313,15 @@ Replace it by swapping the handler:
|
|
|
313
313
|
|
|
314
314
|
```ruby
|
|
315
315
|
# config/initializers/spree.rb
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
316
|
+
Spree.hooks.unregister('returns.create.validate', 'Spree::Returns::EligibilityValidator')
|
|
317
|
+
Spree.hooks.register('returns.create.validate', 'MyStore::ReturnPolicy')
|
|
318
|
+
|
|
319
|
+
# The same validator guards exchanges — swap it there too if your policy should cover them:
|
|
320
|
+
Spree.hooks.unregister('exchanges.create.validate', 'Spree::Returns::EligibilityValidator')
|
|
321
|
+
Spree.hooks.register('exchanges.create.validate', 'MyStore::ReturnPolicy')
|
|
320
322
|
```
|
|
321
323
|
|
|
322
|
-
|
|
324
|
+
Core registers the default validator before your initializers load, so the swap works at the top level of an initializer.
|
|
323
325
|
|
|
324
326
|
A handler receives the workflow (so it can read `order`, `items`, `created_by`, `order.market`) and calls `workflow.reject!(message)` to veto. Every one of the fifteen transitions has a leading `validate` hook, so the same seam gates approving, receiving and refunding.
|
|
325
327
|
|
|
@@ -391,6 +393,20 @@ one. An order whose every parcel was recalled now reads
|
|
|
391
393
|
`fulfillment_status: unfulfilled` rather than `canceled`; only a canceled
|
|
392
394
|
order reads `canceled`.
|
|
393
395
|
|
|
396
|
+
## Payment source IDs use the `psrc_` prefix
|
|
397
|
+
|
|
398
|
+
`Spree::PaymentSource` shared the `ps_` prefix with `Spree::PaymentSession`,
|
|
399
|
+
so the same string could name either record. Payment sources now use
|
|
400
|
+
`psrc_`. The encoded part of the ID doesn't change, only the prefix. The only
|
|
401
|
+
place a payment source's ID shows up is the `source_id` of a payment backed by
|
|
402
|
+
a non-card payment source (wallets, bank redirects and similar). If you stored
|
|
403
|
+
one of those values, swap `ps_` for `psrc_`. Payment session IDs stay `ps_`.
|
|
404
|
+
|
|
405
|
+
Class-level `decode_prefixed_id` (for example `Spree::Product.decode_prefixed_id`)
|
|
406
|
+
now returns `nil` for an ID with another model's prefix, the same as
|
|
407
|
+
`find_by_prefix_id`. Call `Spree::PrefixedId.decode_prefixed_id` if you
|
|
408
|
+
really need to decode any prefix.
|
|
409
|
+
|
|
394
410
|
## Removed in 6.0
|
|
395
411
|
|
|
396
412
|
These were deprecated in 5.x and are **gone now** — there is no bridge, so calls raise `NoMethodError`. Most were one-line delegations to a replacement that already exists.
|