@spree/docs 0.1.0

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 (183) hide show
  1. package/README.md +54 -0
  2. package/dist/api-reference/platform/authentication.md +38 -0
  3. package/dist/api-reference/store-api/authentication.md +188 -0
  4. package/dist/api-reference/store-api/errors.md +277 -0
  5. package/dist/api-reference/store-api/idempotency.md +129 -0
  6. package/dist/api-reference/store-api/introduction.md +34 -0
  7. package/dist/api-reference/store-api/localization.md +279 -0
  8. package/dist/api-reference/store-api/metadata.md +160 -0
  9. package/dist/api-reference/store-api/monetary-amounts.md +65 -0
  10. package/dist/api-reference/store-api/querying.md +399 -0
  11. package/dist/api-reference/store-api/rate-limitting.md +103 -0
  12. package/dist/api-reference/store-api/relations.md +185 -0
  13. package/dist/api-reference/storefront/authentication.md +88 -0
  14. package/dist/api-reference/tutorials/adyen-integration-guide-for-android.md +165 -0
  15. package/dist/api-reference/tutorials/adyen-integration-guide-for-ios.md +194 -0
  16. package/dist/api-reference/tutorials/quick-checkout-with-stripe.md +248 -0
  17. package/dist/api-reference/v2/fetching-multiple-resources.md +26 -0
  18. package/dist/api-reference/v2/filtering-and-sorting.md +53 -0
  19. package/dist/api-reference/v2/introduction.md +22 -0
  20. package/dist/api-reference/v2/pagination.md +37 -0
  21. package/dist/api-reference/webhooks-events.md +883 -0
  22. package/dist/developer/admin/admin.md +205 -0
  23. package/dist/developer/admin/authentication.md +59 -0
  24. package/dist/developer/admin/components.md +711 -0
  25. package/dist/developer/admin/custom-css.md +243 -0
  26. package/dist/developer/admin/custom-javascript.md +116 -0
  27. package/dist/developer/admin/extending-ui.md +1964 -0
  28. package/dist/developer/admin/form-builder.md +444 -0
  29. package/dist/developer/admin/helper-methods.md +531 -0
  30. package/dist/developer/admin/navigation.md +805 -0
  31. package/dist/developer/admin/tables.md +491 -0
  32. package/dist/developer/advanced/adding_spree_to_rails_app.md +106 -0
  33. package/dist/developer/cli/quickstart.md +137 -0
  34. package/dist/developer/contributing/creating-an-extension.md +258 -0
  35. package/dist/developer/contributing/developing-spree.md +339 -0
  36. package/dist/developer/contributing/quickstart.md +32 -0
  37. package/dist/developer/contributing/updating-extensions.md +67 -0
  38. package/dist/developer/core-concepts/addresses.md +265 -0
  39. package/dist/developer/core-concepts/adjustments.md +107 -0
  40. package/dist/developer/core-concepts/architecture.md +177 -0
  41. package/dist/developer/core-concepts/calculators.md +323 -0
  42. package/dist/developer/core-concepts/customers.md +230 -0
  43. package/dist/developer/core-concepts/events.md +624 -0
  44. package/dist/developer/core-concepts/imports-exports.md +698 -0
  45. package/dist/developer/core-concepts/inventory.md +191 -0
  46. package/dist/developer/core-concepts/markets.md +250 -0
  47. package/dist/developer/core-concepts/media.md +167 -0
  48. package/dist/developer/core-concepts/metafields.md +187 -0
  49. package/dist/developer/core-concepts/orders.md +328 -0
  50. package/dist/developer/core-concepts/payments.md +710 -0
  51. package/dist/developer/core-concepts/pricing.md +163 -0
  52. package/dist/developer/core-concepts/products.md +360 -0
  53. package/dist/developer/core-concepts/promotions.md +322 -0
  54. package/dist/developer/core-concepts/reports.md +206 -0
  55. package/dist/developer/core-concepts/search-filtering.md +237 -0
  56. package/dist/developer/core-concepts/shipments.md +212 -0
  57. package/dist/developer/core-concepts/slugs.md +111 -0
  58. package/dist/developer/core-concepts/staff-roles.md +123 -0
  59. package/dist/developer/core-concepts/store-credits-gift-cards.md +317 -0
  60. package/dist/developer/core-concepts/stores.md +117 -0
  61. package/dist/developer/core-concepts/taxes.md +135 -0
  62. package/dist/developer/core-concepts/translations.md +120 -0
  63. package/dist/developer/core-concepts/users.md +299 -0
  64. package/dist/developer/core-concepts/webhooks.md +378 -0
  65. package/dist/developer/create-spree-app/quickstart.md +158 -0
  66. package/dist/developer/customization/api.md +93 -0
  67. package/dist/developer/customization/authentication.md +88 -0
  68. package/dist/developer/customization/checkout.md +204 -0
  69. package/dist/developer/customization/configuration.md +55 -0
  70. package/dist/developer/customization/decorators.md +523 -0
  71. package/dist/developer/customization/dependencies.md +232 -0
  72. package/dist/developer/customization/emails.md +21 -0
  73. package/dist/developer/customization/extensions.md +92 -0
  74. package/dist/developer/customization/metadata.md +236 -0
  75. package/dist/developer/customization/model-preferences.md +130 -0
  76. package/dist/developer/customization/permissions.md +265 -0
  77. package/dist/developer/customization/quickstart.md +229 -0
  78. package/dist/developer/customization/routes.md +24 -0
  79. package/dist/developer/customization/v4/admin-panel.md +78 -0
  80. package/dist/developer/customization/v4/authentication.md +210 -0
  81. package/dist/developer/customization/v4/checkout.md +212 -0
  82. package/dist/developer/customization/v4/deface.md +251 -0
  83. package/dist/developer/customization/v4/images.md +86 -0
  84. package/dist/developer/customization/v4/storefront.md +450 -0
  85. package/dist/developer/deployment/assets.md +87 -0
  86. package/dist/developer/deployment/aws.md +335 -0
  87. package/dist/developer/deployment/caching.md +27 -0
  88. package/dist/developer/deployment/cdn.md +39 -0
  89. package/dist/developer/deployment/database.md +155 -0
  90. package/dist/developer/deployment/docker.md +128 -0
  91. package/dist/developer/deployment/emails.md +77 -0
  92. package/dist/developer/deployment/environment_variables.md +111 -0
  93. package/dist/developer/deployment/heroku.md +51 -0
  94. package/dist/developer/deployment/render.md +95 -0
  95. package/dist/developer/getting-started/quickstart.md +82 -0
  96. package/dist/developer/how-to/custom-payment-method.md +374 -0
  97. package/dist/developer/how-to/custom-promotion.md +373 -0
  98. package/dist/developer/how-to/custom-report.md +387 -0
  99. package/dist/developer/how-to/custom-search-provider.md +230 -0
  100. package/dist/developer/multi-store/quickstart.md +71 -0
  101. package/dist/developer/multi-store/setup.md +38 -0
  102. package/dist/developer/multi-tenant/configuration.md +41 -0
  103. package/dist/developer/multi-tenant/core-concepts.md +75 -0
  104. package/dist/developer/multi-tenant/installation.md +96 -0
  105. package/dist/developer/multi-tenant/quickstart.md +20 -0
  106. package/dist/developer/multi-vendor/installation.md +45 -0
  107. package/dist/developer/multi-vendor/quickstart.md +17 -0
  108. package/dist/developer/sdk/admin/quickstart.md +22 -0
  109. package/dist/developer/sdk/authentication.md +89 -0
  110. package/dist/developer/sdk/configuration.md +225 -0
  111. package/dist/developer/sdk/quickstart.md +82 -0
  112. package/dist/developer/sdk/store/account.md +67 -0
  113. package/dist/developer/sdk/store/cart-checkout.md +140 -0
  114. package/dist/developer/sdk/store/markets.md +151 -0
  115. package/dist/developer/sdk/store/payments.md +96 -0
  116. package/dist/developer/sdk/store/products.md +149 -0
  117. package/dist/developer/sdk/store/wishlists.md +52 -0
  118. package/dist/developer/security/pci_compliance.md +15 -0
  119. package/dist/developer/security/security_policy.md +68 -0
  120. package/dist/developer/storefront/blocks.md +285 -0
  121. package/dist/developer/storefront/custom-css.md +260 -0
  122. package/dist/developer/storefront/custom-javascript.md +166 -0
  123. package/dist/developer/storefront/helper-methods.md +1288 -0
  124. package/dist/developer/storefront/links.md +298 -0
  125. package/dist/developer/storefront/nextjs/architecture.md +150 -0
  126. package/dist/developer/storefront/nextjs/customization.md +141 -0
  127. package/dist/developer/storefront/nextjs/deployment.md +180 -0
  128. package/dist/developer/storefront/nextjs/quickstart.md +92 -0
  129. package/dist/developer/storefront/nextjs/spree-next-package.md +314 -0
  130. package/dist/developer/storefront/pages.md +163 -0
  131. package/dist/developer/storefront/sections.md +569 -0
  132. package/dist/developer/storefront/storefront.md +56 -0
  133. package/dist/developer/storefront/themes.md +161 -0
  134. package/dist/developer/tutorial/admin.md +134 -0
  135. package/dist/developer/tutorial/extending-models.md +380 -0
  136. package/dist/developer/tutorial/file-uploads.md +121 -0
  137. package/dist/developer/tutorial/introduction.md +33 -0
  138. package/dist/developer/tutorial/model.md +41 -0
  139. package/dist/developer/tutorial/page-builder.md +487 -0
  140. package/dist/developer/tutorial/rich-text.md +73 -0
  141. package/dist/developer/tutorial/seo.md +332 -0
  142. package/dist/developer/tutorial/storefront.md +352 -0
  143. package/dist/developer/tutorial/testing.md +558 -0
  144. package/dist/developer/upgrades/2.0-to-2.1.md +46 -0
  145. package/dist/developer/upgrades/2.1-to-2.2.md +59 -0
  146. package/dist/developer/upgrades/2.2-to-2.3.md +44 -0
  147. package/dist/developer/upgrades/2.3-to-2.4.md +42 -0
  148. package/dist/developer/upgrades/3.0-to-3.1.md +47 -0
  149. package/dist/developer/upgrades/3.1-to-3.2.md +34 -0
  150. package/dist/developer/upgrades/3.2-to-3.3.md +70 -0
  151. package/dist/developer/upgrades/3.3-to-3.4.md +36 -0
  152. package/dist/developer/upgrades/3.4-to-3.5.md +44 -0
  153. package/dist/developer/upgrades/3.5-to-3.6.md +40 -0
  154. package/dist/developer/upgrades/3.6-to-3.7.md +62 -0
  155. package/dist/developer/upgrades/3.7-to-4.0.md +152 -0
  156. package/dist/developer/upgrades/4.0-to-4.1.md +92 -0
  157. package/dist/developer/upgrades/4.1-to-4.2.md +109 -0
  158. package/dist/developer/upgrades/4.10-to-5.0.md +129 -0
  159. package/dist/developer/upgrades/4.2-to-4.3.md +100 -0
  160. package/dist/developer/upgrades/4.3-to-4.4.md +125 -0
  161. package/dist/developer/upgrades/4.4-to-4.5.md +94 -0
  162. package/dist/developer/upgrades/4.5-to-4.6.md +119 -0
  163. package/dist/developer/upgrades/4.6-to-4.7.md +39 -0
  164. package/dist/developer/upgrades/4.8-to-4.9.md +24 -0
  165. package/dist/developer/upgrades/4.9-to-4.10.md +24 -0
  166. package/dist/developer/upgrades/4.x-to-4.8.md +52 -0
  167. package/dist/developer/upgrades/5.0-to-5.1.md +28 -0
  168. package/dist/developer/upgrades/5.1-to-5.2.md +127 -0
  169. package/dist/developer/upgrades/5.2-to-5.3.md +338 -0
  170. package/dist/developer/upgrades/5.3-to-5.4.md +248 -0
  171. package/dist/developer/upgrades/quickstart.md +36 -0
  172. package/dist/integrations/analytics/google-analytics.md +64 -0
  173. package/dist/integrations/analytics/google-tag-manager.md +78 -0
  174. package/dist/integrations/integrations.md +39 -0
  175. package/dist/integrations/marketing/klaviyo.md +99 -0
  176. package/dist/integrations/payments/adyen.md +90 -0
  177. package/dist/integrations/payments/paypal.md +41 -0
  178. package/dist/integrations/payments/razorpay.md +45 -0
  179. package/dist/integrations/payments/stripe.md +109 -0
  180. package/dist/integrations/search/meilisearch.md +236 -0
  181. package/dist/integrations/sso-mfa-social-login/admin-dashboard.md +57 -0
  182. package/dist/integrations/sso-mfa-social-login/storefront.md +56 -0
  183. package/package.json +27 -0
@@ -0,0 +1,78 @@
1
+ > **WARNING:** This section is only relevant for Spree 4
2
+
3
+ Starting with Spree 4.7, we've introduced a new way of customizing the admin panel, that enables extensions to modify the admin panel UI without depending on the Deface gem. For Spree 4.6 and earlier, please see how to use [deface_overrides_tutorial.md](../advanced/deface_overrides_tutorial.md "mention") overrides.
4
+
5
+ ### Customizing the main menu
6
+
7
+ When extending Spree with custom features, it's common to add new options to the menu on the left-hand side.
8
+
9
+ The menu is built with [`Spree::Admin::MainMenu::Section`](https://github.com/spree/spree_backend/blob/main/app/models/spree/admin/main_menu/section.rb) and [`Spree::Admin::MainMenu::Item`](https://github.com/spree/spree_backend/blob/main/app/models/spree/admin/main_menu/item.rb) objects.
10
+
11
+ Additionally, there are two builder classes [`Spree::Admin::MainMenu::SectionBuilder`](https://github.com/spree/spree_backend/blob/main/app/models/spree/admin/main_menu/section_builder.rb) and [`Spree::Admin::MainMenu::ItemBuilder`](https://github.com/spree/spree_backend/blob/main/app/models/spree/admin/main_menu/item_builder.rb) that make it easier to build more complex sections.
12
+
13
+ The menu is available under `Rails.application.config.spree_backend.main_menu` and can be modified by both extensions as well as the Rails application code.
14
+
15
+ #### Example: adding an additional section to the admin panel:
16
+
17
+ ```ruby
18
+ Rails.application.config.after_initialize do
19
+ Rails.application.config.spree_backend.main_menu.add(
20
+ Spree::Admin::MainMenu::SectionBuilder.new('subscriptions', 'inbox-fill.svg').
21
+ with_admin_ability_check(Spree::Subscription).
22
+ with_items(
23
+ Spree::Admin::MainMenu::ItemBuilder.new('active', Spree::Core::Engine.routes.url_helpers.admin_active_subsciptions_path).build,
24
+ Spree::Admin::MainMenu::ItemBuilder.new('expired', Spree::Core::Engine.routes.url_helpers.admin_expired_subsciptions_path).build
25
+ ).
26
+ build
27
+ )
28
+ end
29
+ ```
30
+
31
+ For a more extensive example, take a look at how the [default menu is built](https://github.com/spree/spree_backend/blob/main/app/models/spree/admin/main_menu/default_configuration_builder.rb).
32
+
33
+ ### Customizing tabs
34
+
35
+ In some cases you may need to add a new tab to a page for editing Orders, Products or Users.
36
+
37
+ ![](/images/Screenshot 2023-10-31 at 18.57.13.png)
38
+
39
+ These tabs are built with [`Spree::Admin::Tabs::Tab`](https://github.com/spree/spree_backend/blob/main/app/models/spree/admin/tabs/tab.rb). You can also use [`Spree::Admin::Tabs::TabBuilder`](https://github.com/spree/spree_backend/blob/main/app/models/spree/admin/tabs/tab_builder.rb) class to construct new Tab objects. The tabs are attached to `Rails.application.config.spree_backend.tabs` and can be modified via an initializer.
40
+
41
+ #### Example: adding an additional tab to the product edit admin page
42
+
43
+ ```ruby
44
+ Rails.application.config.after_initialize do
45
+ Rails.application.config.spree_backend.tabs[:product].add(
46
+ Spree::Admin::Tabs::TabBuilder.new('discounts', ->(resource) { admin_product_discounts_path(product) }).
47
+ with_icon_key('view.svg').
48
+ with_active_check.
49
+ build
50
+ )
51
+ end
52
+ ```
53
+
54
+ ### Customizing actions
55
+
56
+ A common case for extensions is to add a new action button in the admin panel.
57
+
58
+ Action buttons are built with [`Spree::Admin::Actions::Action`](https://github.com/spree/spree_backend/blob/main/app/models/spree/admin/actions/action.rb) or with a dedicated [`Spree::Admin::Actions::ActionBuilder`](https://github.com/spree/spree_backend/blob/main/app/models/spree/admin/actions/action_builder.rb) class. The action buttons are attached to `Rails.application.config.spree_backend.actions` and can be modified with an initializer.
59
+
60
+ **Example: adding a new button to the order page**
61
+
62
+ ```ruby
63
+ Rails.application.config.after_initialize do
64
+ Rails.application.config.spree_backend.actions[:order].add(
65
+ Spree::Admin::Actions::ActionBuilder.new('generate_export', admin_export_orders_path).
66
+ with_icon_key('list.svg').
67
+ with_style(Spree::Admin::Actions::ActionStyle::PRIMARY).
68
+ with_method(:post).
69
+ build
70
+ )
71
+ end
72
+ ```
73
+
74
+ ### Customizing existing views and partials
75
+
76
+ If you need a more extensive customization of any of the admin panel pages, you can just copy their .erb file from the `spree_backend` gem to your `app/views/` directory and modify it there. This allows you to fully override default views provided by the `spree_backend` gem.
77
+
78
+ > **NOTE:** Note: This approach is not recommended for Spree extensions, as it may conflict with other extensions that modify the same view.
@@ -0,0 +1,210 @@
1
+ ---
2
+ title: Authentication
3
+ description: Learn how to use a custom authentication setup with Spree
4
+ version: v4
5
+ ---
6
+
7
+ This guide covers using a custom authentication setup with Spree, such as one provided by your own application. This is ideal in situations where you want to handle the sign-in or sign-up flow of your application uniquely, outside the realms of what would be possible with Spree or you have an existing authentication with user accounts present.
8
+
9
+ This guide assumes that you have a pre-existing model inside your application that represents the users of your application already. This model could be provided by gems such as [Devise](https://github.com/plataformatec/devise). This guide also assumes that the application that this `User` model exists in is already a Spree application.
10
+
11
+ > **NOTE:** This model **does not** need to be called `User`, but for the purposes of this guide the model we will be referring to **will** be called `User`. If your model is called something else, do some mental substitution wherever you see `User`.
12
+
13
+ To use your own authentication system with Spree, please follow these steps:
14
+
15
+ <details>
16
+ <summary>1. Change the Spree.user_class</summary>
17
+
18
+ To begin using your custom `User` class, you must first edit Spree's initializer located at `config/initializers/spree.rb` by changing this line:
19
+
20
+ ```ruby
21
+ Spree.user_class = 'Spree::User'
22
+ ```
23
+
24
+ To this:
25
+
26
+ ```ruby
27
+ Spree.user_class = 'User'
28
+ ```
29
+
30
+ </details>
31
+
32
+
33
+ <details>
34
+ <summary>2. Update User model</summary>
35
+
36
+ Next, you need to run the custom user generator for Spree which will create a migration that will add the necessary Spree fields to your users table.
37
+
38
+ Run this generator with this command:
39
+
40
+ ```bash
41
+ bin/rails g spree:custom_user User
42
+ ```
43
+
44
+ This will tell the generator that you want to use the `User` class as the class that represents users in Spree. Run the new migration by running this:
45
+
46
+ ```bash
47
+ bin/rails db:migrate
48
+ ```
49
+
50
+ This generator will also create a file at `lib/spree/current_user_helpers.rb` which will be automatically included in your application's controllers allowing you to override the `spree_current_user` method to return the current user of the request.
51
+
52
+ </details>
53
+
54
+ <details>
55
+ <summary>3. Include User concerns in your User model</summary>
56
+
57
+ In your User Model please include the following lines:
58
+
59
+ ```ruby
60
+ include Spree::UserMethods
61
+ include Spree::UserAddress
62
+ include Spree::UserPaymentSource
63
+ ```
64
+
65
+ The first of these methods are the ones added for the `has_and_belongs_to_many` association called `spree_roles`. This association will retrieve all the roles that a user has for Spree.
66
+
67
+ The second of these is the `spree_orders` association. This will return all orders associated with the user in Spree. There's also a `last_incomplete_spree_order` method which will return the last incomplete spree order for the user. This is used internal to Spree to persist order data across a user's login sessions.
68
+
69
+ The third and fourth associations are for address information for a user. When a user places an order, the address information for that order will be linked to that user so that it is available for subsequent orders.
70
+
71
+ The next method is one called `has_spree_role?` which can be used to check if a user has a specific role. This method is used internally to Spree to check if the user is authorized to perform specific actions, such as accessing the admin section. Admin users of your system should be assigned the Spree admin role, like this:
72
+
73
+ ```ruby
74
+ user = User.find_by(email: 'master@example.com')
75
+ user.spree_roles << Spree::Role.where(name: 'admin').first_or_create
76
+ ```
77
+
78
+ To test that this has worked, use the `has_spree_role?` method, like this:
79
+
80
+ ```ruby
81
+ user.has_spree_role?('admin')
82
+ ```
83
+
84
+ If this returns `true`, then the user has admin permissions within Spree.
85
+
86
+ </details>
87
+
88
+ <details>
89
+ <summary>4. Customize Spree Authentication Helpers (Optional)</summary>
90
+
91
+ > **NOTE:** This step is required if you're using **`spree_backend`** and/or `spree_frontend` gems.
92
+
93
+ Run a generator to create a file at `lib/spree/authentication_helpers.rb` which will contain the following code to help you do that:
94
+
95
+ ```bash
96
+ bin/rails g spree:custom_authentication
97
+ ```
98
+
99
+ This will create a file at `lib/spree/authentication_helpers.rb` which will contain the following code to help you do that:
100
+
101
+ ```ruby
102
+ module Spree
103
+ module AuthenticationHelpers
104
+ def self.included(receiver)
105
+ receiver.helper_method(
106
+ :spree_current_user,
107
+ :spree_login_path,
108
+ :spree_signup_path,
109
+ :spree_logout_path,
110
+ :spree_forgot_password_path,
111
+ :spree_edit_password_path,
112
+ :spree_admin_login_path,
113
+ :spree_admin_logout_path,
114
+ )
115
+ end
116
+
117
+ def spree_current_user
118
+ current_user
119
+ end
120
+
121
+ def spree_login_path(opts = {})
122
+ main_app.login_path(opts)
123
+ end
124
+
125
+ def spree_signup_path(opts = {})
126
+ main_app.signup_path(opts)
127
+ end
128
+
129
+ def spree_logout_path(opts = {})
130
+ main_app.logout_path(opts)
131
+ end
132
+
133
+ def spree_forgot_password_path(opts = {})
134
+ main_app.forgot_password_path(opts)
135
+ end
136
+
137
+ def spree_edit_password_path(opts = {})
138
+ main_app.edit_password_path(opts)
139
+ end
140
+
141
+ def spree_admin_login_path(opts = {})
142
+ main_app.admin_login_path(opts)
143
+ end
144
+
145
+ def spree_admin_logout_path(opts = {})
146
+ main_app.admin_logout_path(opts)
147
+ end
148
+ end
149
+ end
150
+ ```
151
+
152
+ Each of the methods defined in this module return values that are the most common in Rails applications today, but you may need to customize them. In order, they are:
153
+
154
+ * `spree_current_user` Used to tell Spree what the current user of a request is.
155
+ * `spree_login_path` The location of the login/sign in form in your application.
156
+ * `spree_signup_path` The location of the sign up form in your application.
157
+ * `spree_logout_path` The location of the logout feature of your application.
158
+ * `spree_forgot_password_path` The location to reset a user's password.
159
+ * `spree_edit_password_path` The location to edit a user's password.
160
+ * `spree_admin_login_path` The location of the login/sign in form for the admin panel.
161
+ * `spree_admin_logout_path` The location of the logout feature for the admin panel.
162
+
163
+ URLs inside the helpers **must** have `main_app` prefixed if they are inside your application. This is because Spree will otherwise attempt to route these paths to the Spree engine, which does not exist. By prefixing with `main_app`, you tell it to look at the application's routes.
164
+
165
+ You will need to define the `login_path`, `signup_path` and `logout_path` routes yourself, by using code like this inside your application's `config/routes.rb` if you're using Devise:
166
+
167
+ ```ruby
168
+ devise_for :users
169
+ devise_scope :user do
170
+ get '/login', to: "devise/sessions#new"
171
+ get '/signup', to: "devise/registrations#new"
172
+ delete '/logout', to: "devise/sessions#destroy"
173
+ get '/forgot_password', to: "devise/passwords#new"
174
+ get '/edit_password', to: "devise/registrations#edit"
175
+ end
176
+ ```
177
+
178
+ Of course, this code will be different if you're not using Devise. Simply **do not** use the `devise_scope` method and change the controllers and actions for these routes.
179
+
180
+ You can also customize these methods inside `lib/spree/authentication_helpers.rb` to use the routing helper methods already provided by the authentication setup you have, if you wish.
181
+
182
+ Any modifications made to `lib/spree/authentication_helpers.rb` while the server is running will require a restart, as with any other modification to other files in `lib`.
183
+
184
+ </details>
185
+
186
+ <details>
187
+ <summary>5. Remove Auth Devise gem</summary>
188
+
189
+ The `spree_auth_devise` gem is not needed when using an existing application authentication unless the goal is to have two separate authentication methods.
190
+
191
+ You can remove the `spree_auth_devise` gem by running this command:
192
+
193
+ ```bash
194
+ bundle remove spree_auth_devise
195
+ ```
196
+
197
+ </details>
198
+
199
+
200
+ ## Admin Panel authentication
201
+
202
+ By default Spree uses the same model for the admin panel as the storefront. However you can customize it to use a different model.
203
+
204
+ To do this, you need to add the following code to your `config/initializers/spree.rb` file:
205
+
206
+ ```ruby
207
+ Spree.admin_user_class = 'AdminUser'
208
+ ```
209
+
210
+ This will tell Spree to use the `AdminUser` model for the admin panel. You will need to create this model in your application and ensure that it includes the necessary Spree fields.
@@ -0,0 +1,212 @@
1
+ ---
2
+ title: Checkout Flow
3
+ description: Learn how to customize the checkout process in Spree.
4
+ version: v4
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 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](/developer/core-concepts/orders):
44
+
45
+ * Registration Optional - only if using [spree_auth_devise](https://github.com/spree/spree_auth_devise) extension, can be toggled through the `Spree::Auth::Config[:registration_step]` configuration setting
46
+ * Address Information
47
+ * Delivery Options Shipping Method
48
+ * Payment
49
+ * Confirmation
50
+
51
+ 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.
52
+
53
+ ### Registration
54
+
55
+ > **INFO:** This section only applies when using `spree_frontend` and `spree_auth_devise` gems.
56
+
57
+ Prior to beginning the checkout process, the customer will be prompted to create a new account or to log in to their existing account. By default, there is also a "guest checkout" option that allows users to specify only their email address if they do not wish to create an account.
58
+
59
+ Technically, the registration step is not an actual state in the `Spree::Order` state machine. The `spree_auth_devise` gem (an extension that comes with Spree Starter by default) adds the `check_registration` before filter to all actions of `Spree::CheckoutController` except for obvious reasons the `registration` and `update_registration` actions, which redirects to a registration page unless one of the following is true:
60
+
61
+ * `Spree::Auth::Config[:registration_step]` preference is not `true`
62
+ * user is already logged in
63
+ * the current order has an email address associated with it
64
+
65
+ The method is defined like this:
66
+
67
+ ```ruby
68
+ def check_registration
69
+ return unless Spree::Auth::Config[:registration_step]
70
+ return if spree_current_user || current_order.email
71
+ store_location
72
+ redirect_to spree.checkout_registration_path
73
+ end
74
+ ```
75
+
76
+ #### Disabling guest checkout
77
+
78
+ To completely disable guest checkout and require registration for checkout, you need to change Spree configuration in `config/initializers/spree.rb`:
79
+
80
+ ```ruby
81
+ Spree::Config[:allow_guest_checkout] = false
82
+ ```
83
+
84
+ ### Address Information
85
+
86
+ This step allows the customer to add both their billing and shipping information. Customers can click the "use billing address" option to use the same address for both.
87
+
88
+ 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.
89
+
90
+ 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](/developer/core-concepts/stores#checkout-configuration). Spree assumes that the list of billing and shipping countries will be the same. You can always change this logic via class decorator if this does not suit your needs.
91
+
92
+ ### Delivery Options
93
+
94
+ During this step, the user may choose a delivery method. Spree assumes the list of shipping methods to be dependent on the shipping address.
95
+
96
+ ### Payment
97
+
98
+ This step is where the customer provides payment information. This step is intentionally placed last in order to minimize security issues with credit card information. Credit card information is never stored in the database so it would be impossible to have a subsequent step and still be able to submit the information to the payment gateway. Spree submits the information to the gateway before saving the model so that the sensitive information can be discarded before saving the checkout information.
99
+
100
+ Spree stores only the last four digits of the credit card number along with the expiration information. The full credit card number and verification code are never stored in the Spree database.
101
+
102
+ Several gateways such as ActiveMerchant and Beanstream provide a secure method for storing a "payment profile" in your database. This approach typically involves the use of a "token" which can be used for subsequent purchases but only with your merchant account. If you are using a secure payment profile it would then be possible to show a final "confirmation" step after payment information is entered.
103
+
104
+ If you do not want to use a gateway with payment profiles then you will need to customize the checkout process so that your final step submits the credit card information. You can then perform authorization before the order is saved. This is perfectly secure because the credit card information is not ever saved. It's transmitted to the gateway and then discarded like normal.
105
+
106
+ Spree discards the credit card number after this step is processed. If you do not have a gateway with payment profiles enabled then your card information will be lost before it's time to authorize the card.
107
+
108
+ For more information about payments, please see the [Payments guide](/developer/core-concepts/payments).
109
+
110
+ ### Confirmation
111
+
112
+ 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."
113
+
114
+ This step is disabled by default, but can be enabled by two ways:
115
+
116
+ 1. globally for all orders by setting a preference in `config/initializers/spree.rb`:
117
+
118
+ ```ruby
119
+ Spree::Config[:always_include_confirm_step] = true
120
+ ```
121
+
122
+ 2. conditionally for specific orders by overriding the `confirmation_required?` method in `Spree::Order`, eg.
123
+
124
+ ```ruby
125
+ module Spree
126
+ module OrderDecorator
127
+ # require confirmation for orders with a US billing address
128
+ def confirmation_required?
129
+ billing_address&.country_iso == 'US'
130
+ end
131
+ end
132
+ end
133
+ ```
134
+
135
+ ## Adding Logic Before or After a Particular Step
136
+
137
+ The [state_machines](https://github.com/state-machines/state_machines) gem allows you to implement callbacks before or after transitioning to a particular step. These callbacks work similarly to [Active Record Callbacks](http://guides.rubyonrails.org/active_record_callbacks.html) in that you can specify a method or block of code to be executed prior to or after a transition. If the method executed in a before_transition returns false, then the transition will not execute.
138
+
139
+ So, for example, if you wanted to verify that the user provides a valid zip code before transitioning to the delivery step, you would first implement a `valid_zip_code?` method, and then tell the state machine to run this method before that transition, placing this code in a file called `app/models/spree/order_decorator.rb`:
140
+
141
+ ```ruby
142
+ module Spree
143
+ module OrderDecorator
144
+ def self.prepended(base)
145
+ base.state_machine.before_transition to: :delivery, do: :valid_zip_code?
146
+ end
147
+
148
+ def valid_zip_code?
149
+ # logic to check if the zip code is valid
150
+ end
151
+ end
152
+
153
+ Order.prepend(OrderDecorator)
154
+ end
155
+ ```
156
+
157
+ This callback would prevent transitioning to the `delivery` step if `valid_zip_code?` returns false.
158
+
159
+ ## Modifying the checkout flow
160
+
161
+ To add or remove steps to the checkout flow, you can use the
162
+ [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.
163
+
164
+ The `insert_checkout_step` method takes a `before` or `after` option to determine where to insert the step:
165
+
166
+ ```ruby
167
+ module Spree
168
+ module OrderDecorator
169
+ def self.prepended(base)
170
+ base.insert_checkout_step :new_step, before: :address
171
+ # or
172
+ # base.insert_checkout_step :new_step, after: :address
173
+ end
174
+ end
175
+
176
+ Order.prepend(OrderDecorator)
177
+ end
178
+ ```
179
+
180
+ The `remove_checkout_step` will remove just one checkout step at a time:
181
+
182
+ ```ruby
183
+ module Spree
184
+ module OrderDecorator
185
+ def self.prepended(base)
186
+ base.remove_checkout_step :address
187
+ base.remove_checkout_step :delivery
188
+ end
189
+ end
190
+
191
+ Order.prepend(OrderDecorator)
192
+ end
193
+ ```
194
+
195
+ 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.
196
+
197
+ To completely re-define the flow of the checkout, use the `checkout_flow` helper:
198
+
199
+ ```ruby
200
+ module Spree
201
+ module OrderDecorator
202
+ def self.prepended(base)
203
+ base.checkout_flow do
204
+ go_to_state :payment
205
+ go_to_state :complete
206
+ end
207
+ end
208
+ end
209
+
210
+ Order.prepend(OrderDecorator)
211
+ end
212
+ ```