-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configuration guide #1607
Add configuration guide #1607
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Added some notes below, though
|
||
When you first setup a Rails app with Solidus installed, you will want to customize its looks and behaviour to fit your company's needs. Solidus can be customized in six ways: | ||
|
||
* Configuration options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to link these?
|
||
You will most probably use at least methods 1-4, and most shops we know also use some combination of the last three. | ||
|
||
As Solidus is an Engine, much of what the [Spree Guide on using Engines](http:https://guides.rubyonrails.org/engines.html) explains applies directly to Solidus. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpreeGuide on using Engines
Rails Guide on using Engines
|
||
## Configuration options | ||
|
||
Since Solidus is a [Rails Engine](http:https://guides.rubyonrails.org/engines.html), much of its behaviour can be customized through the Solidus initializer. After you have run the `rails g spree:install` generator, this initializer will live in `config/initializers/spree.rb`. Open this file, and have a look at the first block (comments left out): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe explaining the spree
vs. solidus
incidence in the introductory section would be helpful to understand the differing file names especially for the unaware.
|
||
Of course, it the template you wish to modify references other template files, you can override those, too. For example, the product list references a shared partial `app/views/spree/shared/_products.html.erb` - you can find it [here](https://github.com/solidusio/solidus/blob/master/frontend/app/views/spree/shared/_products.html.erb) and also override it in your host app. | ||
|
||
When you override a view from a Gem, there is the possibility of difficulties when upgrading, because Controller code within the Gem might have changed, such as for example the name of an instance variable. Be careful when upgrading, and always read `CHANGELOG.md`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe mark this as side note or tip
|
||
### In the backend | ||
|
||
We do not recommend overriding the admin backend in the same way, since some of the extensions you might be running (see below) depend on them having the HTML structure present in the version of Solidus they were built for. If you need to add custom functionality to Solidus' backend, we recommend using the `Deface` gem. Find it [here](https://github.com/spree/deface). Overriding backend views with Deface is tricky - be sure to have good tests! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we recommend the usage of Deface?
|
||
The Solidus configuration object from above has some getters and setters for classes as extension points. After evaluating whether you need to go down this route, take some time to study the standard implementation for the class you want to modify, and subclass or re-implement it. The service class extension points can be found [here](https://github.com/solidusio/solidus/blob/master/core/app/models/spree/app_configuration.rb#L277-L383). | ||
|
||
These extension points can alter Solidus' behaviour quite drastically. If you make mistakes when implementing them, your store will break. Good luck! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, this is too harsh. I think we can just remove this line
For example, if you want to add a method to the `Spree::Order` model, you would have a file called `app/models/spree/order_decorator.rb` with the following contents: | ||
|
||
``` | ||
module Spree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary to use the Spree
module
namespace and can even lead to strange issues.
Maybe just use none or module YourStore
end | ||
end | ||
|
||
Spree::Order.prepend Spree::OrderDecorator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great usage of Module.prepend
"No more class_eval
" 👌
Spree::Order.prepend Spree::OrderDecorator | ||
``` | ||
|
||
This creates a new module called `Spree::OrderDecorator` and will insert its methods so early in the method lookup chain that the decorator's methods overwrite the original order class's methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you don't need to explain Module.prepend
here. Maybe link to a good article?
|
||
From now on, every order, when asked for its total, will return the string "One Million Dollars". This particular decorator would, by the way, definitely break a large part of Solidus' functionality as `Spree::Order#total` is expected to return a `BigDecimal`, not a `String`. | ||
|
||
If you do this kind of thing, be very careful and test your new functionality very well. If you do upgrades, read extra carefully about changes in Solidus' core classes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also mark this as "tip" or "side note"?
0f9ea3b
to
6563204
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
Not mandatory, but syntax highlighting would be 🍨
|
||
If you do this kind of thing, be very careful and test your new functionality very well. If you do upgrades, read extra carefully about changes in Solidus' core classes. | ||
|
||
## Run a private fork (and submit us a Pull Request!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please remove the call for pull requests? This is a little bit too "loud" ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks the link at the top, as well.
This commit adds a very high-level guide to some of the ways it's possible to customize Solidus: * Configuration options * Overriding templates * Changing assets * Installing extensions * Custom service classes * Monkey-Patching Solidus * Run a private fork While we like some of these methods better than others, I think it's important for beginners to understand their options.
6563204
to
af608df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now 💯 🎯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
This commit adds a very high-level guide to some of the ways
it's possible to customize Solidus:
While we like some of these methods better than others, I think it's
important for beginners to understand their options.