Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/getting-started/installing-solidus.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ generated initializer in `config/initializers/spree.rb`.
The very first line on it will be very similar to this one:

```ruby
Spree.load_defaults '4.1'
Spree.load_defaults '4.2'
```

Some of the default values for Solidus preferences depend on the Solidus version. That line makes
Expand Down
2 changes: 1 addition & 1 deletion docs/upgrading-solidus/v3.3.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 4
sidebar_position: -3.3
---

import PRLink from '@site/src/theme/PRLink';
Expand Down
2 changes: 1 addition & 1 deletion docs/upgrading-solidus/v3.4.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 3
sidebar_position: -3.4
---

import PRLink from '@site/src/theme/PRLink';
Expand Down
2 changes: 1 addition & 1 deletion docs/upgrading-solidus/v4.0.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 2
sidebar_position: -4.0
---

import PRLink from '@site/src/theme/PRLink';
Expand Down
2 changes: 1 addition & 1 deletion docs/upgrading-solidus/v4.1.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 1
sidebar_position: -4.1
---

import PRLink from '@site/src/theme/PRLink';
Expand Down
69 changes: 69 additions & 0 deletions docs/upgrading-solidus/v4.2.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
sidebar_position: -4.2
---

import PRLink from '@site/src/theme/PRLink';
import MinimalRequirements from '@site/src/theme/MinimalRequirements';

# Solidus v4.2 (2023-06-29)

<MinimalRequirements ruby="3.0" rails="7.0" />

Solidus v4.2 is out! 🎉

This release brings the usual load of bug fixes and improvements, but also the new branding and some new features that we are happy to share with you.

## <PRLink number="5309">Stop using partials and deface to customize the admin menu</PRLink>

This change removes the need to use of partials and deface to customize the Admin menu. Instead, we now have a new `#children` attribute added to the `MenuItem` class in which second level menus are defined.

Doing this brought a significant benefits in terms of simplicity and customization. Parent menu items can now ask the children if any of them is active without the need of duplicating the logic in the parent.

Since the list of menu items is a simple array, it can be easily manipulated by other extensions, and in the host application. Finding a menu item is as simple as checking its `label`, e.g. `menu_items.find { _1.label == :products }`.

```ruby
Spree::Backend::Config.configure do |config|
# Let solidus know that we don't want to use the partials for second level
# menu items anymore. By enabling this whenver a menu item has both children
# and a partial, the partial will be ignored.
config.prefer_menu_item_partials = false

config.menu_items
.find { _1.label == :products }
.children << MenuItem.new(
label: :collections,
condition: -> { can? :admin, MyStore::ProductCollection },
url: '/product_collections'
)
end
```

## <PRLink number="5392">Updated sidebar from the upcoming `SolidusAdmin`</PRLink>

A new sidebar is also available that matches the style of the one in `SolidusAmin`, the new admin interface that is currently under development.

The new sidebar is best experienced with the matching `solidus_admin` theme.

```ruby
Spree::Backend::Config.configure do |config|
config.theme = 'solidus_admin'
config.admin_updated_navbar = true
end
```

We hope you like it!

## <PRLink number="5068">Add support for the `SolidusAdmin` preview</PRLink>

The new `SolidusAdmin` is still under development, but you can already preview it in your application.

```shell
bundle add solidus_admin
bin/rails g solidus_admin:install
```

At the time of this writing it only covers product and order listing, and partial editing of products. We are working hard to bring more features to it, and we are looking forward to your feedback.

Permission checks and authentication is shared with the existing admin interface, so you can use the same user to access both. A toggle is available at the bottom of the navigation menu to switch between the two interfaces.

The new admin dashboard is mounted as an independent engine, and by default it can be disabled with a cookie, but that can be customized in the host application, e.g. to enable it only for a select number of users.
1 change: 1 addition & 0 deletions src/theme/SupportedVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';

export default function SupportedVersions() {
const versions = [
{ number: 'v4.2', releaseDate: '2023-09-29', eolDate: '2025-06-29' },
{ number: 'v4.1', releaseDate: '2023-06-29', eolDate: '2024-12-29' },
{ number: 'v4.0', releaseDate: '2023-05-08', eolDate: '2024-11-08' },
{ number: 'v3.4', releaseDate: '2023-04-21', eolDate: '2024-10-21' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ generated initializer in `config/initializers/spree.rb`.
The very first line on it will be very similar to this one:

```ruby
Spree.load_defaults '4.1'
Spree.load_defaults '4.2'
```

Some of the default values for Solidus preferences depend on the Solidus version. That line makes
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-4.2/advanced-solidus/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"label": "Advanced Solidus",
"position": 4,
"collapsible": true,
"collapsed": true
}
158 changes: 158 additions & 0 deletions versioned_docs/version-4.2/advanced-solidus/custom-authentication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
---
sidebar_position: 1
needs-diataxis-rewrite: true
---

# Custom authentication

:::info
You can use the official [`solidus_auth_devise`](https://github.com/solidusio/solidus_auth_devise) gem to provide
a `Spree::User` model and basic authentication for Solidus. See its documentation for additional setup instructions.
:::

Solidus requires a `User` model in order to take advantage of all its features. This model can have any name, and
Solidus can integrate with your application's existing authentication system.

In this guide, we'll explore the steps required to create a `User` model from scratch, use an authentication solution
like [Devise ](https://github.com/plataformatec/devise), or integrate your application's existing `User` model.

## Basic requirements

In order to use a custom user model, your model should have:

* **An integer `id` column:** Solidus uses integers for all foreign keys, so you need to use integer IDs in your user
model. You may use other types of IDs by changing the types of the foreign key columns, but this is generally
discouraged.
* **A `password` attribute:** This is needed if you use
`solidus_starter_frontend`, `solidus_frontend` or `solidus_backend`. You can
implement the attribute however you see fit.

This is all you need for now. The rest of the requirements will be implemented in the next steps!

## Preparing your user class

### With the generator

Solidus ships with a generator to prepare and configure your custom user class throughout the application. Just run the
following:

```bash
$ rails g spree:custom_user AmazingStore::User
```

This will do the following:

* Generate a migration to add some required columns to the custom model's table.
* Set `Spree.user_class` to your custom model's class name, so that Solidus knows to use it in associations and
throughout the store.
* Implement some authentication helpers required by `solidus_backend`,
`solidus_starter_frontend` and `solidus_frontend` in
`lib/spree/authentication_helpers.rb`.

At this point, you'll need to migrate your database to add the new columns:

```bash
$ rails db:migrate
```

You may also want to customize the helpers in `lib/spree/authentication_helpers.rb`.

### Without the generator

#### Add the required columns <a id="minimum-requirements"></a>

The first step is to add the columns Solidus expects to the users table:

* `spree_api_key`: a string containing the user's API key. This should be limited to 48 characters.
* `bill_address_id`: an integer containing the ID of the `Spree::Address` that should be used as the user's billing
address.
* `ship_address_id`: an integer containing the ID of the `Spree::Address` that should be used as the user's shipping
address.

You can easily add these with the following migration:

```bash
$ rails g migration AddAuthColumnsToUsers \
spree_api_key:string{48} \
bill_address_id:integer \
ship_address_id:integer
```

Once the migration has been generated, you can migrate the database:

```bash
$ rails db:migrate
```

#### spree\_current\_user helper <a id="spree-em-current-em-user"></a>

If you use `solidus_starter_frontend`, `solidus_frontend` or `solidus_backend`,
you need to provide a `spree_current_user` helper method in your
`ApplicationController`:

```ruby title="app/controllers/application\_controller.rb"
class ApplicationController < ActionController::Base
helper_method :spree_current_user

def spree_current_user
# If your gem already provides a current_user method,
# you may simply wrap it in spree_current_user. If not,
# you'll need some additional custom logic here.
current_user
end

# ...
end
```

#### Add authentication helpers <a id="add-authentication-helpers"></a>

If you use `solidus_starter_frontend`, `solidus_frontend` or `solidus_backend`,
you need to provide authentication helpers so that users can sign up, log in,
and log out:

```ruby title="app/controllers/application\_controller.rb"
class ApplicationController < ActionController::Base
helper_method :spree_login_path
helper_method :spree_signup_path
helper_method :spree_logout_path

def spree_login_path
login_path
end

def spree_signup_path
signup_path
end

def spree_logout_path
logout_path
end

# ...
end
```

## Adding Solidus user methods

The [`Spree::UserMethods` module ](https://github.com/solidusio/solidus/blob/v3.0/core/app/models/concerns/spree/user_methods.rb)
provides extensive integration for a `User` model, creating associations and allowing it to interact with major models
in Solidus like `Spree::Order`.

To add user methods to your `User` model, include `Spree::UserMethods` :

```ruby title="app/models/my\_store/user.rb"
module MyStore
class User
include Spree::UserMethods

# ...
end
end
```

## How-to guides

- [How to sign in to the Solidus API using solidus_auth_devise][how-to-sign-in-to-the-solidus-api-using-solidus_auth_devise]

[how-to-sign-in-to-the-solidus-api-using-solidus_auth_devise]: /how-tos/api/how-to-sign-in-to-the-solidus-api-using-solidus_auth_devise.mdx
Loading