@spree/docs 0.1.177 → 0.1.178

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 (117) hide show
  1. package/dist/developer/cli/quickstart.md +1 -1
  2. package/dist/developer/contributing/creating-an-extension.md +2 -2
  3. package/dist/developer/core-concepts/addresses.md +3 -3
  4. package/dist/developer/core-concepts/architecture.md +4 -4
  5. package/dist/developer/core-concepts/calculators.md +2 -2
  6. package/dist/developer/core-concepts/carts.md +207 -0
  7. package/dist/developer/core-concepts/channels.md +3 -3
  8. package/dist/developer/core-concepts/customers.md +1 -1
  9. package/dist/developer/core-concepts/events.md +1 -1
  10. package/dist/developer/core-concepts/fulfillments.md +278 -0
  11. package/dist/developer/core-concepts/imports-exports.md +6 -18
  12. package/dist/developer/core-concepts/inventory.md +3 -3
  13. package/dist/developer/core-concepts/media.md +1 -1
  14. package/dist/developer/core-concepts/metafields.md +1 -1
  15. package/dist/developer/core-concepts/orders.md +92 -339
  16. package/dist/developer/core-concepts/payments.md +1 -1
  17. package/dist/developer/core-concepts/promotions.md +68 -195
  18. package/dist/developer/core-concepts/returns-exchanges-claims.md +173 -0
  19. package/dist/developer/core-concepts/store-credits-gift-cards.md +16 -18
  20. package/dist/developer/core-concepts/stores.md +1 -1
  21. package/dist/developer/core-concepts/taxes-discounts-fees.md +199 -0
  22. package/dist/developer/core-concepts/taxes.md +3 -3
  23. package/dist/developer/create-spree-app/quickstart.md +1 -1
  24. package/dist/developer/customization/api.md +36 -11
  25. package/dist/developer/customization/configuration.md +207 -37
  26. package/dist/developer/customization/decorators.md +8 -8
  27. package/dist/developer/customization/permissions.md +34 -229
  28. package/dist/developer/customization/quickstart.md +159 -108
  29. package/dist/developer/customization/validations.md +1 -1
  30. package/dist/developer/dashboard/overview.md +1 -1
  31. package/dist/developer/how-to/build-a-b2b-store.md +21 -0
  32. package/dist/developer/how-to/build-a-marketplace.md +25 -0
  33. package/dist/developer/how-to/custom-api-authentication.md +1 -1
  34. package/dist/developer/how-to/custom-delivery-rate-provider.md +242 -0
  35. package/dist/developer/how-to/custom-document-numbers.md +154 -0
  36. package/dist/developer/how-to/custom-order-routing.md +1 -1
  37. package/dist/developer/how-to/custom-payment-method.md +1 -1
  38. package/dist/developer/how-to/custom-promotion.md +76 -115
  39. package/dist/developer/how-to/custom-report.md +2 -2
  40. package/dist/developer/how-to/custom-stock-splitter.md +5 -5
  41. package/dist/developer/how-to/sell-digital-products.md +20 -0
  42. package/dist/developer/multi-tenant/quickstart.md +1 -1
  43. package/dist/developer/providers/dam.md +14 -0
  44. package/dist/developer/providers/erp.md +31 -0
  45. package/dist/developer/providers/fulfillment.md +25 -0
  46. package/dist/developer/{deployment/telemetry.md → providers/observability.md} +1 -1
  47. package/dist/developer/providers/overview.md +44 -0
  48. package/dist/developer/providers/pim.md +25 -0
  49. package/dist/developer/providers/sso.md +20 -0
  50. package/dist/developer/sdk/admin/extending.md +1 -1
  51. package/dist/developer/sdk/admin/quickstart.md +1 -1
  52. package/dist/developer/sdk/admin/resources.md +1 -1
  53. package/dist/developer/sdk/extending.md +1 -1
  54. package/dist/developer/tutorial/admin-api.md +13 -0
  55. package/dist/developer/tutorial/dashboard-plugin.md +14 -0
  56. package/dist/developer/tutorial/events.md +7 -161
  57. package/dist/developer/tutorial/introduction.md +15 -35
  58. package/dist/developer/tutorial/model.md +7 -98
  59. package/dist/developer/tutorial/store-api.md +13 -0
  60. package/dist/developer/tutorial/storefront.md +12 -0
  61. package/dist/developer/tutorial/testing.md +7 -711
  62. package/dist/developer/upgrades/5.6-to-6.0.md +2 -2
  63. package/package.json +1 -1
  64. package/dist/developer/admin/admin.md +0 -214
  65. package/dist/developer/admin/authentication.md +0 -59
  66. package/dist/developer/admin/components.md +0 -711
  67. package/dist/developer/admin/custom-css.md +0 -256
  68. package/dist/developer/admin/custom-javascript.md +0 -116
  69. package/dist/developer/admin/extending-ui.md +0 -1839
  70. package/dist/developer/admin/form-builder.md +0 -444
  71. package/dist/developer/admin/helper-methods.md +0 -531
  72. package/dist/developer/admin/navigation.md +0 -805
  73. package/dist/developer/admin/tables.md +0 -490
  74. package/dist/developer/advanced/adding_spree_to_rails_app.md +0 -92
  75. package/dist/developer/core-concepts/adjustments.md +0 -113
  76. package/dist/developer/core-concepts/reports.md +0 -208
  77. package/dist/developer/core-concepts/shipments.md +0 -307
  78. package/dist/developer/core-concepts/users.md +0 -303
  79. package/dist/developer/customization/authentication.md +0 -100
  80. package/dist/developer/customization/checkout.md +0 -202
  81. package/dist/developer/customization/emails.md +0 -18
  82. package/dist/developer/customization/routes.md +0 -24
  83. package/dist/developer/multi-vendor/installation.md +0 -61
  84. package/dist/developer/multi-vendor/quickstart.md +0 -17
  85. package/dist/developer/tutorial/admin.md +0 -206
  86. package/dist/developer/tutorial/api.md +0 -606
  87. package/dist/developer/tutorial/extending-models.md +0 -393
  88. package/dist/developer/tutorial/sdk.md +0 -170
  89. package/dist/developer/upgrades/2.0-to-2.1.md +0 -46
  90. package/dist/developer/upgrades/2.1-to-2.2.md +0 -59
  91. package/dist/developer/upgrades/2.2-to-2.3.md +0 -44
  92. package/dist/developer/upgrades/2.3-to-2.4.md +0 -42
  93. package/dist/developer/upgrades/3.0-to-3.1.md +0 -47
  94. package/dist/developer/upgrades/3.1-to-3.2.md +0 -34
  95. package/dist/developer/upgrades/3.2-to-3.3.md +0 -70
  96. package/dist/developer/upgrades/3.3-to-3.4.md +0 -36
  97. package/dist/developer/upgrades/3.4-to-3.5.md +0 -44
  98. package/dist/developer/upgrades/3.5-to-3.6.md +0 -40
  99. package/dist/developer/upgrades/3.6-to-3.7.md +0 -62
  100. package/dist/developer/upgrades/3.7-to-4.0.md +0 -152
  101. package/dist/developer/upgrades/4.0-to-4.1.md +0 -92
  102. package/dist/developer/upgrades/4.1-to-4.2.md +0 -109
  103. package/dist/developer/upgrades/4.10-to-5.0.md +0 -131
  104. package/dist/developer/upgrades/4.2-to-4.3.md +0 -100
  105. package/dist/developer/upgrades/4.3-to-4.4.md +0 -125
  106. package/dist/developer/upgrades/4.4-to-4.5.md +0 -94
  107. package/dist/developer/upgrades/4.5-to-4.6.md +0 -119
  108. package/dist/developer/upgrades/4.6-to-4.7.md +0 -39
  109. package/dist/developer/upgrades/4.8-to-4.9.md +0 -24
  110. package/dist/developer/upgrades/4.9-to-4.10.md +0 -24
  111. package/dist/developer/upgrades/4.x-to-4.8.md +0 -52
  112. package/dist/developer/upgrades/5.0-to-5.1.md +0 -28
  113. package/dist/developer/upgrades/5.1-to-5.2.md +0 -131
  114. package/dist/developer/upgrades/5.2-to-5.3.md +0 -338
  115. package/dist/developer/upgrades/5.3-to-5.4.md +0 -277
  116. package/dist/developer/upgrades/5.4-to-5.5.md +0 -301
  117. package/dist/developer/upgrades/5.5-to-5.6.md +0 -207
@@ -1,303 +0,0 @@
1
- ---
2
- title: Users
3
- description: How Spree models customer and admin users — Devise authentication, account data, roles, abilities, and access permissions across stores.
4
- ---
5
-
6
- ## Overview
7
-
8
- Spree has two separate user types:
9
-
10
- - **Customers** — users who browse your store, manage their account, and purchase products via the Store API
11
- - **Admins** — users who manage the store via the Admin Panel
12
-
13
- | User type | Class | Default |
14
- |-----------|-------|---------|
15
- | Customers | `Spree.user_class` | `Spree::User` |
16
- | Admins | `Spree.admin_user_class` | `Spree::AdminUser` |
17
-
18
- > **INFO:** You can use your own user classes. See the [Customize Authentication guide](../customization/authentication.md) for details.
19
-
20
- ## Customers
21
-
22
- Customers interact with your store through the Store API. They can register, log in, manage their profile, and view order history.
23
-
24
- ```mermaid
25
- erDiagram
26
- Customer ||--o{ Order : "places"
27
- Customer ||--o{ Address : "has many"
28
- Customer ||--o{ Wishlist : "has many"
29
- Customer ||--o{ StoreCredit : "has many"
30
- Customer ||--o{ PaymentSource : "has many"
31
-
32
- Customer {
33
- string id
34
- string email
35
- string first_name
36
- string last_name
37
- }
38
-
39
- Order {
40
- string number
41
- string state
42
- }
43
-
44
- Address {
45
- string firstname
46
- string lastname
47
- string address1
48
- string city
49
- }
50
-
51
- Wishlist {
52
- string name
53
- boolean is_default
54
- }
55
- ```
56
-
57
- ### Registration
58
-
59
-
60
- ```typescript Store SDK
61
- const { token, user } = await client.customers.create({
62
- email: 'john@example.com',
63
- password: 'password123',
64
- password_confirmation: 'password123',
65
- first_name: 'John',
66
- last_name: 'Doe',
67
- })
68
- // token => JWT token for subsequent authenticated requests
69
- // user => { id: "usr_xxx", email: "john@example.com", first_name: "John", ... }
70
- ```
71
-
72
- ```bash cURL
73
- curl -X POST 'https://api.mystore.com/api/v3/store/customers' \
74
- -H 'X-Spree-Api-Key: pk_xxx' \
75
- -H 'Content-Type: application/json' \
76
- -d '{
77
- "email": "john@example.com",
78
- "password": "password123",
79
- "password_confirmation": "password123",
80
- "first_name": "John",
81
- "last_name": "Doe"
82
- }'
83
- ```
84
-
85
-
86
- ### Login
87
-
88
-
89
- ```typescript Store SDK
90
- const { token, user } = await client.auth.login({
91
- email: 'john@example.com',
92
- password: 'password123',
93
- })
94
- // Use the token for authenticated requests
95
- ```
96
-
97
- ```bash cURL
98
- curl -X POST 'https://api.mystore.com/api/v3/store/auth/login' \
99
- -H 'X-Spree-API-Key: pk_xxx' \
100
- -H 'Content-Type: application/json' \
101
- -d '{
102
- "email": "john@example.com",
103
- "password": "password123"
104
- }'
105
- ```
106
-
107
-
108
- The response includes a [JWT token](../../api-reference/store-api/authentication.md) and a `user` object. Pass the token in subsequent requests via the `Authorization: Bearer <token>` header. See the [account SDK guide](../sdk/store/account.md) for the full `auth.login`, refresh, and profile flows.
109
-
110
- ### Token Refresh
111
-
112
- Refresh an expiring token to keep the session alive:
113
-
114
-
115
- ```typescript Store SDK
116
- const { token } = await client.auth.refresh({
117
- refresh_token: existingRefreshToken,
118
- })
119
- ```
120
-
121
- ```bash cURL
122
- curl -X POST 'https://api.mystore.com/api/v3/store/auth/refresh' \
123
- -H 'X-Spree-API-Key: pk_xxx' \
124
- -H 'Content-Type: application/json' \
125
- -d '{ "refresh_token": "rt_xxx" }'
126
- ```
127
-
128
-
129
- ### Customer Profile
130
-
131
-
132
- ```typescript Store SDK
133
- // Get current customer
134
- const customer = await client.customer.get()
135
- // {
136
- // id: "usr_xxx",
137
- // email: "john@example.com",
138
- // first_name: "John",
139
- // last_name: "Doe",
140
- // default_shipping_address: { ... },
141
- // default_billing_address: { ... },
142
- // addresses: [{ ... }, { ... }],
143
- // }
144
-
145
- // Update profile
146
- const updated = await client.customer.update({
147
- first_name: 'Jonathan',
148
- accepts_email_marketing: true,
149
- })
150
- ```
151
-
152
- ```bash cURL
153
- # Get current customer
154
- curl 'https://api.mystore.com/api/v3/store/customers/me' \
155
- -H 'Authorization: Bearer <jwt_token>'
156
-
157
- # Update profile
158
- curl -X PATCH 'https://api.mystore.com/api/v3/store/customers/me' \
159
- -H 'Authorization: Bearer <jwt_token>' \
160
- -H 'Content-Type: application/json' \
161
- -d '{ "first_name": "Jonathan", "accepts_email_marketing": true }'
162
- ```
163
-
164
-
165
- ### Customer Resources
166
-
167
- Authenticated customers have access to these resources:
168
-
169
- | Resource | Description |
170
- |----------|-------------|
171
- | [**Addresses**](addresses.md#customer-address-book) | Billing and shipping addresses with default selection |
172
- | [**Orders**](orders.md#order-history) | Past order history |
173
- | **Credit Cards** | Saved credit cards for checkout |
174
- | **Payment Sources** | Other saved payment methods (PayPal, Klarna, etc.) |
175
- | **Store Credits** | Balance assigned by the store, usable at checkout |
176
- | **Gift Cards** | Gift cards owned by or assigned to the customer |
177
- | **Wishlists** | Saved product lists |
178
-
179
- ### Guest Checkout
180
-
181
- Customers don't need to register to purchase. Guest checkout uses an order token (`X-Spree-Token`) to identify the cart. See [Orders — Cart](orders.md#cart) for details.
182
-
183
- ## Admin Users
184
-
185
- Admin users manage the store via the Admin Panel. They have roles that control what they can access.
186
-
187
- ```mermaid
188
- erDiagram
189
- AdminUser ||--o{ RoleUser : "has many"
190
- RoleUser }o--|| Role : "belongs to"
191
- RoleUser }o--|| Store : "scoped to"
192
- AdminUser ||--o{ Invitation : "invites"
193
-
194
- AdminUser {
195
- string id
196
- string email
197
- }
198
-
199
- RoleUser {
200
- string role_id
201
- string resource_type
202
- string resource_id
203
- }
204
-
205
- Role {
206
- string name
207
- }
208
-
209
- Invitation {
210
- string email
211
- string status
212
- string token
213
- datetime expires_at
214
- }
215
- ```
216
-
217
- ### Roles
218
-
219
- Admin users can have different roles that control their permissions:
220
-
221
- | Role | Description |
222
- |------|-------------|
223
- | `admin` | Full access to all Admin Panel features |
224
-
225
- > **INFO:** You can create custom roles with specific permissions. See the [Customize Permissions guide](../customization/permissions.md) for details.
226
-
227
- ### Creating Admin Users
228
-
229
- Use the Spree CLI to create admin users:
230
-
231
- ```bash
232
- spree user create
233
- ```
234
-
235
- The CLI will prompt you for the email and password. You can also pass them directly:
236
-
237
- ```bash
238
- spree user create --email admin@example.com --password secret123
239
- ```
240
-
241
- The created user gets the `admin` role on the default store.
242
-
243
- ### Inviting Admin Users
244
-
245
- You can invite new admins through the Admin Panel or programmatically.
246
-
247
- **Via Admin Panel:**
248
-
249
- 1. Navigate to **Settings → Users**
250
- 2. Click **Invite User**
251
- 3. Enter the email address and select a role
252
- 4. Click **Send Invitation**
253
-
254
- The invitee receives an email with an invitation link. If they already have an account, they log in to accept. Otherwise, they create an account first.
255
-
256
- ```mermaid
257
- flowchart TB
258
- A[Admin creates invitation] --> B[Invitation email sent]
259
- B --> C[Invitee clicks link]
260
- C --> D{Has account?}
261
- D -->|Yes| E[Log in]
262
- D -->|No| F[Create account]
263
- E --> G[Accept invitation]
264
- F --> G
265
- G --> H[Role assigned to store]
266
- ```
267
-
268
- #### Invitation Details
269
-
270
- | Attribute | Description |
271
- |-----------|-------------|
272
- | `email` | Invitee's email address |
273
- | `token` | Secure token for the invitation link |
274
- | `status` | `pending` or `accepted` |
275
- | `expires_at` | Expiration date (default: 2 weeks) |
276
- | `resource` | The store being granted access to |
277
- | `role` | The role to assign upon acceptance |
278
-
279
- #### Invitation Events
280
-
281
- The invitation system publishes [events](events.md) you can subscribe to:
282
-
283
- | Event | Description |
284
- |-------|-------------|
285
- | `invitation.created` | Invitation was created (triggers email) |
286
- | `invitation.accepted` | Invitation was accepted and role assigned |
287
- | `invitation.resent` | Invitation was resent to the invitee |
288
-
289
- ## Permissions
290
-
291
- Spree uses [CanCanCan](https://github.com/CanCanCommunity/cancancan) for authorization. Permissions apply to both customers (Store API access) and admins (Admin Panel access).
292
-
293
- See the [Customize Permissions guide](../customization/permissions.md) for details on creating custom roles and permission sets.
294
-
295
- ## Related Documentation
296
-
297
- - [Addresses](addresses.md) — Customer address management
298
- - [Orders](orders.md) — Order history and checkout
299
- - [Authentication](../customization/authentication.md) — Custom authentication setup
300
- - [Permissions](../customization/permissions.md) — Roles and authorization
301
- - [Events](events.md) — Subscribe to user and invitation events
302
- - [Store API Authentication](../../api-reference/store-api/authentication.md) — Customer JWT auth flow
303
- - [Admin API Authentication](../../api-reference/admin-api/authentication.md) — Staff JWT + scopes auth flow
@@ -1,100 +0,0 @@
1
- ---
2
- title: Authentication
3
- description: Integrate Spree with a custom authentication setup, including Devise, an existing user model, OmniAuth providers, and JWT or OAuth API tokens.
4
- version: v5
5
- ---
6
-
7
- If you installed Spree following the [Quickstart guide](../quickstart.md), you can completely skip this step - you are all set and integrated with the [Devise](https://github.com/plataformatec/devise) gem.
8
-
9
- However if you're adding Spree to an existing application that has its own authentication system, you will need to follow these steps.
10
-
11
- ## Using Devise
12
-
13
- If you're currently using [Devise](https://github.com/plataformatec/devise) for authentication, you can follow the steps below to integrate Spree with your existing authentication system.
14
-
15
- Firstly set your `User` class as `Spree.user_class` in your `config/initializers/spree.rb` file:
16
-
17
- ```ruby
18
- Spree.user_class = 'User'
19
- ```
20
-
21
- Now, run the generator to set up Spree integration with Devise:
22
-
23
-
24
- ```bash Spree CLI (Docker)
25
- spree generate spree:authentication:devise
26
- ```
27
-
28
- ```bash Without Spree CLI
29
- bin/rails g spree:authentication:devise
30
- ```
31
-
32
-
33
- This will create a new file in `lib/spree/authentication_helpers.rb` that serves as a bridge between Spree and your existing authentication system routes. You can then use this file to customize the routes to your liking. It should automatically pick up standard Devise routes.
34
-
35
- Secondly, this generator will add necessary modules to your `User` model.
36
-
37
- ```ruby
38
- # app/models/user.rb
39
- class User < ApplicationRecord
40
- # ... your existing code ...
41
-
42
- include Spree::UserAddress
43
- include Spree::UserMethods
44
- include Spree::UserPaymentSource
45
- end
46
- ```
47
-
48
- This will ensure that your `User` model can be used as a Spree user.
49
-
50
- This generator will also add 2 new lines to your Spree initializer file:
51
-
52
- ```ruby
53
- Devise.parent_controller = "Spree::BaseController"
54
- Devise.parent_mailer = "Spree::BaseMailer"
55
- ```
56
-
57
- This ensures that Devise will use Spree storefront layout for login/signup/etc and use Spree mailer layout for sending emails so they'll match your Storefront branding.
58
-
59
- If you have more complex setup, you can remove these lines and customize the routes and mailer in your own initializer file.
60
-
61
- ## Using Custom Authentication
62
-
63
- If you're using a custom authentication system, you can follow the steps below to integrate Spree with your existing authentication system.
64
-
65
- Firstly set your `User` class as `Spree.user_class` in your `config/initializers/spree.rb` file:
66
-
67
- ```ruby
68
- Spree.user_class = 'User'
69
- ```
70
-
71
- Now, run the generator to set up Spree integration with your custom authentication system:
72
-
73
-
74
- ```bash Spree CLI (Docker)
75
- spree generate spree:authentication:custom
76
- ```
77
-
78
- ```bash Without Spree CLI
79
- bin/rails g spree:authentication:custom
80
- ```
81
-
82
-
83
- This will create a new file in `lib/spree/authentication_helpers.rb` that serves as a bridge between Spree and your existing authentication system routes. You will need to customize this file to fit your needs.
84
-
85
- Secondly, this generator will add necessary modules to your `User` model.
86
-
87
- ```ruby
88
- # app/models/user.rb
89
- class User < ApplicationRecord
90
- # ... your existing code ...
91
-
92
- include Spree::UserAddress
93
- include Spree::UserMethods
94
- include Spree::UserPaymentSource
95
- end
96
- ```
97
-
98
- ## Admin Panel authentication
99
-
100
- Please refer to the [Admin Panel Authentication](../admin/authentication.md) page for more details.
@@ -1,202 +0,0 @@
1
- ---
2
- title: Checkout Flow
3
- description: Customize the Spree checkout flow with the checkout DSL — add, remove, or conditionally skip address, delivery, payment, and confirmation steps.
4
- version: v5
5
- ---
6
-
7
- ## Overview
8
-
9
- The Spree checkout process has been designed for maximum flexibility. It's been redesigned several times now, each iteration has benefited from the feedback of real-world deployment experience. It is relatively simple to customize the checkout process to suit your needs. Secure transmission of customer information is possible via SSL and credit card information is never stored in the database.
10
-
11
- ## The Checkout Flow DSL
12
-
13
- Spree comes with a new checkout DSL that allows you to succinctly define the different steps of your checkout. This new DSL allows you to customize _just_ the checkout flow, while maintaining the unrelated admin states, such as "canceled" and "resumed", that an order can transition to. Ultimately, it provides a shorter syntax compared with overriding the entire state machine for the `Spree::Order` class.
14
-
15
- The default checkout flow for Spree is defined like this, adequately demonstrating the abilities of this new system:
16
-
17
- ```ruby
18
- checkout_flow do
19
- go_to_state :address
20
- go_to_state :delivery
21
- go_to_state :payment, if: ->(order) {
22
- order.update_totals
23
- order.payment_required?
24
- }
25
- go_to_state :confirm, if: ->(order) { order.confirmation_required? }
26
- go_to_state :complete
27
- remove_transition from: :delivery, to: :confirm
28
- ```
29
-
30
- we can pass a block on each checkout step definition and work some logic to figure if the step is required dynamically. e.g. the confirm step might only be necessary for payment gateways that support payment profiles.
31
-
32
- These conditional states present a situation where an order could transition from delivery to one of payment, confirm or complete. In the default checkout, we never want to transition from delivery to confirm, and therefore have removed it using the `remove_transition` method of the Checkout DSL. The resulting transitions between states look like the image below:
33
-
34
- These two helper methods are provided on `Spree::Order` instances for your convenience:
35
-
36
- * `checkout_steps` - returns a list of all the potential states of the checkout.
37
- * `has_step?` - Used to check if the current order fulfills the requirements for a specific state.
38
-
39
- If you want a list of all the currently available states for the checkout, use the `checkout_steps` method, which will return the steps in an array.
40
-
41
- ## Default Checkout Steps
42
-
43
- The Spree checkout process consists of the following steps. With the exception of the Registration step, each of these steps corresponds to a state of the [Order object](../core-concepts/orders.md):
44
-
45
- * Shipping Address and Contact Information
46
- * Delivery Options Shipping Method
47
- * Payment and Billing Information
48
- * Confirmation (optional)
49
-
50
- The following sections will provide a walk-through of checkout from a user's perspective, and offer some information on how to configure the default behavior of the various steps.
51
-
52
- ### Shipping Address and Contact Information
53
-
54
- This step allows the customer to add shipping information and contact information. Customers have also option to sign in or create an account. For payment methods such as Stripe customers can use quick checkout option via payment wallets such as Apple Pay, Google Pay, etc and skip the rest of the checkout process.
55
-
56
- The address fields include a select box for choosing state/province. If there are no states configured for a particular country, the select box will be replaced by a text field instead.
57
-
58
- The list of countries that appear in the country select box can also be configured. Spree will list all countries by default, but you can configure exactly which countries you would like to appear. The list can be limited to a specific set of countries by [setting the Store's checkout zone](../core-concepts/stores.md#checkout-configuration).
59
-
60
- ### Delivery Options
61
-
62
- During this step, the user may choose a delivery method. Spree assumes the list of shipping methods to be dependent on the shipping address. If there are multiple shipments eg. different Stock Locations or Vendors, the user will be asked to select shipping method for each shipment.
63
-
64
- ### Payment
65
-
66
- This step is where the customer provides payment and billing information. Spree does not store any payment information in the database. For payment methods such as Stripe, we use Stripe JavaScript SDKs to render their payment form inside the checkout page, fully compliant with PCI DSS standards.
67
-
68
- Besides Credit Card, Wallets and other 3rd party payment methods, Spree also supports Store Credit and Gift Cards (Spree 5.1+ only) which can be used to pay for the entire order or part of the order.
69
-
70
- For more information about payments, please see the [Payments guide](../core-concepts/payments.md).
71
-
72
- ### Confirmation
73
-
74
- This is the final opportunity for the customer to review their order before submitting it to be processed. Users have the opportunity to return to any step in the process using either the back button or by clicking on the appropriate step in the "progress breadcrumb."
75
-
76
- This step is disabled by default, but can be enabled by two ways:
77
-
78
- 1. globally for all orders by setting a preference in `config/initializers/spree.rb`:
79
-
80
- ```ruby config/initializers/spree.rb
81
- Spree::Config[:always_include_confirm_step] = true
82
- ```
83
-
84
- 2. conditionally for specific orders by overriding the `confirmation_required?` method in `Spree::Order` with a [decorator](decorators.md), eg.
85
-
86
- ```ruby app/models/spree/order_decorator.rb
87
- module Spree
88
- module OrderDecorator
89
- # require confirmation for orders with a US billing address
90
- def confirmation_required?
91
- billing_address&.country_iso == 'US'
92
- end
93
- end
94
- end
95
- ```
96
-
97
- ## Adding Logic Before or After a Particular Step
98
-
99
- There are two approaches for adding logic around checkout state transitions:
100
-
101
- ### Approach 1: Events Subscribers (Recommended for side effects)
102
-
103
- For actions that should happen **after** a checkout step completes (syncing with external services, sending notifications, logging, etc.), use [Events subscribers](../core-concepts/events.md). This is the recommended approach because it keeps your code decoupled from Spree internals.
104
-
105
- ```ruby app/subscribers/order_completed_subscriber.rb
106
- class OrderCompletedSubscriber < Spree::Subscriber
107
- subscribes_to 'order.completed'
108
-
109
- def handle(event)
110
- order = Spree::Order.find_by_prefix_id(event.payload['id'])
111
- return unless order
112
-
113
- # Sync to fulfillment system, notify warehouse, etc.
114
- FulfillmentService.notify(order)
115
- AnalyticsService.track_purchase(order)
116
- end
117
- end
118
- ```
119
-
120
- > **INFO:** Events are fired automatically when orders change state. See [Events documentation](../core-concepts/events.md#order-events) for all available order events.
121
-
122
- ### Approach 2: State Machine Callbacks (For validation/blocking logic)
123
-
124
- The [state_machines](https://github.com/state-machines/state_machines) gem allows you to implement callbacks that can **block** transitions. Use this approach only when you need to prevent a transition based on validation logic.
125
-
126
- For example, if you wanted to verify that the user provides a valid zip code before transitioning to the delivery step:
127
-
128
- ```ruby app/models/spree/order_decorator.rb
129
- module Spree
130
- module OrderDecorator
131
- def self.prepended(base)
132
- base.state_machine.before_transition to: :delivery, do: :valid_zip_code?
133
- end
134
-
135
- def valid_zip_code?
136
- # Return false to prevent the transition
137
- ship_address&.zipcode&.match?(/^\d{5}(-\d{4})?$/)
138
- end
139
- end
140
-
141
- Order.prepend(OrderDecorator)
142
- end
143
- ```
144
-
145
- This callback would prevent transitioning to the `delivery` step if `valid_zip_code?` returns false.
146
-
147
- > **WARNING:** Avoid using state machine callbacks for side effects like API calls or notifications. These can slow down checkout and may fail silently. Use [Events subscribers](../core-concepts/events.md) instead.
148
-
149
- ## Modifying the checkout flow
150
-
151
- To add or remove steps to the checkout flow, you can use the
152
- [insert_checkout_step](https://github.com/spree/spree/blob/a39ed2b69f1f2b2f413b7f46090bd0deeb439d61/core/app/models/spree/order/checkout.rb#L138) and [remove_checkout_step](https://github.com/spree/spree/blob/a39ed2b69f1f2b2f413b7f46090bd0deeb439d61/core/app/models/spree/order/checkout.rb#L157) helpers respectively.
153
-
154
- The `insert_checkout_step` method takes a `before` or `after` option to determine where to insert the step:
155
-
156
- ```ruby app/models/spree/order_decorator.rb
157
- module Spree
158
- module OrderDecorator
159
- def self.prepended(base)
160
- base.insert_checkout_step :new_step, before: :address
161
- # or
162
- # base.insert_checkout_step :new_step, after: :address
163
- end
164
- end
165
-
166
- Order.prepend(OrderDecorator)
167
- end
168
- ```
169
-
170
- The `remove_checkout_step` will remove just one checkout step at a time:
171
-
172
- ```ruby app/models/spree/order_decorator.rb
173
- module Spree
174
- module OrderDecorator
175
- def self.prepended(base)
176
- base.remove_checkout_step :address
177
- base.remove_checkout_step :delivery
178
- end
179
- end
180
-
181
- Order.prepend(OrderDecorator)
182
- end
183
- ```
184
-
185
- What will happen here is that when a user goes to checkout, they will be asked to potentially fill in their payment details and then potentially confirm the order. This is the default behavior of the payment and the confirm steps within the checkout. If they are not required to provide payment or confirmation for this order then checking out this order will result in its immediate completion.
186
-
187
- To completely re-define the flow of the checkout, use the `checkout_flow` helper:
188
-
189
- ```ruby app/models/spree/order_decorator.rb
190
- module Spree
191
- module OrderDecorator
192
- def self.prepended(base)
193
- base.checkout_flow do
194
- go_to_state :payment
195
- go_to_state :complete
196
- end
197
- end
198
- end
199
-
200
- Order.prepend(OrderDecorator)
201
- end
202
- ```
@@ -1,18 +0,0 @@
1
- ---
2
- title: Emails
3
- description: Customize Spree transactional emails using the spree_emails gem and Postmark templates, including how to preview mailers locally during development.
4
- ---
5
-
6
- > **NOTE:** Emails are now part of `spree_emails` gem. If you use `spree_starter` you already have it installed.
7
-
8
- ## Overview
9
-
10
- Spree uses [postmark templates](https://github.com/wildbit/postmark-templates), as a base for all transactional emails.
11
-
12
- ## Email previews
13
-
14
- Spree bundles [ActionMailer previews](https://guides.rubyonrails.org/action_mailer_basics.html#previewing-and-testing-mailers) for all of its transactional emails. They are served automatically in development — there is nothing to install.
15
-
16
- Start the rails server locally and go to: `localhost:3000/rails/mailers`
17
-
18
- (it requires a seeded development database in order to work properly, as the previews render real records)
@@ -1,24 +0,0 @@
1
- ---
2
- title: Routes
3
- description: Learn how to customize the routes in Spree
4
- ---
5
-
6
- ## Default configuration
7
-
8
- By default Spree is mounted at the root of your domain, this code will be inserted into `config/routes.rb`:
9
-
10
- ```ruby
11
- mount Spree::Core::Engine, at: '/'
12
- ```
13
-
14
- This means that Spree will be available at the root of your domain, for example `http://localhost:3000`.
15
-
16
- ## Customizing the mount point
17
-
18
- You can customize this simply by changing the `:at` specification in `config/routes.rb` to be something else. For example, if you would like Spree to be mounted at `/shop`, you can write this:
19
-
20
- ```ruby
21
- mount Spree::Core::Engine, at: `/shop`
22
- ```
23
-
24
- The different parts of Spree (API, Admin) will be mounted there as well, eg. `http://localhost:3000/shop/products`.