@spree/docs 0.1.76 → 0.1.77
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/admin/admin.md +0 -1
- package/dist/developer/admin/extending-ui.md +0 -119
- package/dist/developer/admin/tables.md +0 -2
- package/dist/developer/core-concepts/slugs.md +1 -1
- package/package.json +1 -1
- package/dist/developer/contributing/updating-extensions.md +0 -67
- package/dist/developer/customization/v4/admin-panel.md +0 -78
- package/dist/developer/customization/v4/authentication.md +0 -210
- package/dist/developer/customization/v4/checkout.md +0 -212
- package/dist/developer/customization/v4/deface.md +0 -251
- package/dist/developer/customization/v4/images.md +0 -86
- package/dist/developer/customization/v4/storefront.md +0 -450
|
@@ -16,7 +16,6 @@ The Admin Dashboard allows store administrators to manage:
|
|
|
16
16
|
- **Orders** - Process orders, refunds, and shipments
|
|
17
17
|
- **Customers** - View customer accounts and order history
|
|
18
18
|
- **Promotions** - Create discounts, coupon codes, and special offers
|
|
19
|
-
- **Content** - Manage pages, menus, and blog posts
|
|
20
19
|
- **Settings** - Configure store settings, shipping, taxes, and payments
|
|
21
20
|
|
|
22
21
|
## Customization Options
|
|
@@ -944,93 +944,6 @@ Here's a list of all places you can inject your custom code:
|
|
|
944
944
|
</details>
|
|
945
945
|
|
|
946
946
|
|
|
947
|
-
### Post Categories
|
|
948
|
-
|
|
949
|
-
<details>
|
|
950
|
-
<summary>Post Categories Actions</summary>
|
|
951
|
-
|
|
952
|
-
`post_categories_actions`
|
|
953
|
-
|
|
954
|
-
Injects code into the page actions area for the post categories list page.
|
|
955
|
-
|
|
956
|
-
```erb
|
|
957
|
-
<%= link_to "Reorder Categories", reorder_post_categories_path, class: "btn btn-secondary" %>
|
|
958
|
-
```
|
|
959
|
-
|
|
960
|
-
</details>
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
<details>
|
|
964
|
-
<summary>Post Categories Header</summary>
|
|
965
|
-
|
|
966
|
-
`post_categories_header`
|
|
967
|
-
|
|
968
|
-
Injects code between the page header and the main content area for the post categories list page.
|
|
969
|
-
|
|
970
|
-
```erb
|
|
971
|
-
<div class="alert alert-info">
|
|
972
|
-
<strong>Organization:</strong> Use categories to organize your blog posts.
|
|
973
|
-
</div>
|
|
974
|
-
```
|
|
975
|
-
|
|
976
|
-
</details>
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
### Posts
|
|
980
|
-
|
|
981
|
-
<details>
|
|
982
|
-
<summary>Posts Actions</summary>
|
|
983
|
-
|
|
984
|
-
`posts_actions`
|
|
985
|
-
|
|
986
|
-
Injects code into the page actions area for the posts list page.
|
|
987
|
-
|
|
988
|
-
```erb
|
|
989
|
-
<%= link_to "Schedule Posts", schedule_posts_path, class: "btn btn-secondary" %>
|
|
990
|
-
```
|
|
991
|
-
|
|
992
|
-
</details>
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
<details>
|
|
996
|
-
<summary>Posts Header</summary>
|
|
997
|
-
|
|
998
|
-
`posts_header`
|
|
999
|
-
|
|
1000
|
-
Injects code between the page header and the main content area for the posts list page.
|
|
1001
|
-
|
|
1002
|
-
```erb
|
|
1003
|
-
<div class="alert alert-info">
|
|
1004
|
-
<strong>Publishing:</strong> Posts can be scheduled for future publication.
|
|
1005
|
-
</div>
|
|
1006
|
-
```
|
|
1007
|
-
|
|
1008
|
-
</details>
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
<details>
|
|
1012
|
-
<summary>Posts Filters</summary>
|
|
1013
|
-
|
|
1014
|
-
`posts_filters`
|
|
1015
|
-
|
|
1016
|
-
#### Variables
|
|
1017
|
-
|
|
1018
|
-
- **`f`** (`Spree::Admin::FormBuilder`) — The [Spree::Admin::FormBuilder](form-builder.md) object.
|
|
1019
|
-
|
|
1020
|
-
Injects code into the posts list filters.
|
|
1021
|
-
|
|
1022
|
-
```erb
|
|
1023
|
-
<%= f.spree_select :published_eq,
|
|
1024
|
-
[["Published", true], ["Draft", false]],
|
|
1025
|
-
{ include_blank: true, label: "Publication Status" },
|
|
1026
|
-
{ data: { filters_target: :input } } %>
|
|
1027
|
-
```
|
|
1028
|
-
|
|
1029
|
-
> **TIP:** Use [ransack](../core-concepts/search-filtering.md) search syntax for filter field names.
|
|
1030
|
-
|
|
1031
|
-
</details>
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
947
|
### Promotions
|
|
1035
948
|
|
|
1036
949
|
<details>
|
|
@@ -1621,38 +1534,6 @@ Here's a list of all places you can inject your custom code:
|
|
|
1621
1534
|
</details>
|
|
1622
1535
|
|
|
1623
1536
|
|
|
1624
|
-
### Themes
|
|
1625
|
-
|
|
1626
|
-
<details>
|
|
1627
|
-
<summary>Themes Actions</summary>
|
|
1628
|
-
|
|
1629
|
-
`themes_actions`
|
|
1630
|
-
|
|
1631
|
-
Injects code into the page actions area for the themes list page.
|
|
1632
|
-
|
|
1633
|
-
```erb
|
|
1634
|
-
<%= link_to "Preview All", preview_all_themes_path, class: "btn btn-secondary" %>
|
|
1635
|
-
```
|
|
1636
|
-
|
|
1637
|
-
</details>
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
<details>
|
|
1641
|
-
<summary>Themes Header</summary>
|
|
1642
|
-
|
|
1643
|
-
`themes_header`
|
|
1644
|
-
|
|
1645
|
-
Injects code between the page header and the main content area for the themes list page.
|
|
1646
|
-
|
|
1647
|
-
```erb
|
|
1648
|
-
<div class="alert alert-info">
|
|
1649
|
-
<strong>Customization:</strong> Themes control the visual appearance of your storefront.
|
|
1650
|
-
</div>
|
|
1651
|
-
```
|
|
1652
|
-
|
|
1653
|
-
</details>
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
1537
|
### Webhooks Subscribers
|
|
1657
1538
|
|
|
1658
1539
|
<details>
|
|
@@ -432,8 +432,6 @@ Spree registers tables for all built-in resources:
|
|
|
432
432
|
| `:metafield_definitions` | `Spree::MetafieldDefinition` |
|
|
433
433
|
| `:gift_cards` | `Spree::GiftCard` |
|
|
434
434
|
| `:stock_items` | `Spree::StockItem` |
|
|
435
|
-
| `:posts` | `Spree::Post` |
|
|
436
|
-
| `:post_categories` | `Spree::PostCategory` |
|
|
437
435
|
| `:webhook_endpoints` | `Spree::WebhookEndpoint` |
|
|
438
436
|
| `:webhook_deliveries` | `Spree::WebhookDelivery` |
|
|
439
437
|
| `:price_list_products` | `Spree::Product` (nested) |
|
|
@@ -73,7 +73,7 @@ When a slug changes (e.g., a product is renamed), Spree preserves the old slug.
|
|
|
73
73
|
|
|
74
74
|
## Internationalization
|
|
75
75
|
|
|
76
|
-
Products
|
|
76
|
+
Products and categories support localized slugs — a different slug per locale:
|
|
77
77
|
|
|
78
78
|
|
|
79
79
|
```typescript SDK
|
package/package.json
CHANGED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Updating Extensions
|
|
3
|
-
description: How to upgrade your Spree extension to work with Spree 4
|
|
4
|
-
version: v4
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Zeitwerk compatibility
|
|
8
|
-
|
|
9
|
-
Zeitwerk is the [new default code autoloader in Rails 6](https://weblog.rubyonrails.org/2019/2/22/zeitwerk-integration-in-rails-6-beta-2/).
|
|
10
|
-
|
|
11
|
-
This doesn't work well with the old approach to decorators files that name ends with decorator.rb, eg. `app/models/spree/order_decorator.rb` using [class_eval](https://www.jimmycuadra.com/posts/metaprogramming-ruby-class-eval-and-instance-eval/).
|
|
12
|
-
|
|
13
|
-
To fix this we need to convert all `class_eval` decorators to modules and use [Module.prepend](https://medium.com/@leo_hetsch/ruby-modules-include-vs-prepend-vs-extend-f09837a5b073). Also we need to name them properly according to [Zeitwerk naming rules](https://github.com/fxn/zeitwerk#file-structure)
|
|
14
|
-
|
|
15
|
-
Example of an old decorator:
|
|
16
|
-
|
|
17
|
-
```ruby app/models/spree/order_decorator.rb
|
|
18
|
-
Spree::Order.class_eval do
|
|
19
|
-
has_many :new_custom_model
|
|
20
|
-
|
|
21
|
-
def some_method
|
|
22
|
-
# ...
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
the same decorator in the new notation:
|
|
28
|
-
|
|
29
|
-
```ruby app/models/your_extension_name/order_decorator.rb
|
|
30
|
-
module YourExtensionName::OrderDecorator
|
|
31
|
-
def self.prepended(base)
|
|
32
|
-
base.has_many :new_custom_model
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def some_method
|
|
36
|
-
# ...
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
Spree::Order.prepend(YourExtensionName::OrderDecorator)
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## Fixing Deface Overrides
|
|
44
|
-
|
|
45
|
-
Please remember to prepare versioned overrides for both Spree 3.x and 4.x, eg. [https://github.com/spree-contrib/spree_static_content/commit/e4b9e4900024235158d0ec1a48a100b4732348ef](https://github.com/spree-contrib/spree_static_content/commit/e4b9e4900024235158d0ec1a48a100b4732348ef)
|
|
46
|
-
|
|
47
|
-
Spree 4 uses Bootstrap 4 and many partials and HTML structure changed compared to Spree 3.x.
|
|
48
|
-
|
|
49
|
-
Also - **remember to add deface gem to gemspec** as deface itself was removed as a dependency of Spree. eg. [https://github.com/spree/spree_auth_devise/commit/d729689ca87d8586e541ffcc865ef1e0a5a79fe4](https://github.com/spree/spree_auth_devise/commit/d729689ca87d8586e541ffcc865ef1e0a5a79fe4)
|
|
50
|
-
|
|
51
|
-
## Migrate to Spree Dev Tools
|
|
52
|
-
|
|
53
|
-
Replace all development dependencies with:
|
|
54
|
-
|
|
55
|
-
```ruby
|
|
56
|
-
s.add_development_dependency 'spree_dev_tools'
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Replace `spec_helper.rb` contents with:
|
|
60
|
-
|
|
61
|
-
[https://github.com/spree/spree/blob/777a284b4c70e69d32a05ffa61bbe3905d8f1297/cmd/lib/spree_cmd/templates/extension/spec/spec_helper.rb](https://github.com/spree/spree/blob/777a284b4c70e69d32a05ffa61bbe3905d8f1297/cmd/lib/spree_cmd/templates/extension/spec/spec_helper.rb)
|
|
62
|
-
|
|
63
|
-
Example migrations:
|
|
64
|
-
|
|
65
|
-
* [https://github.com/spree/spree_gateway/pull/357](https://github.com/spree/spree_gateway/pull/357)
|
|
66
|
-
* [https://github.com/spree-contrib/spree-product-assembly/pull/200](https://github.com/spree-contrib/spree-product-assembly/pull/200)
|
|
67
|
-
* [https://github.com/spree/spree_auth_devise/pull/487](https://github.com/spree/spree_auth_devise/pull/487)
|
|
@@ -1,78 +0,0 @@
|
|
|
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
|
-

|
|
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.
|
|
@@ -1,210 +0,0 @@
|
|
|
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.
|