Solidus autoloads any file in the
/app directory that has the suffix
_decorator.rb, just like any other Rails models or controllers. This allows
Solidus functionality for your store.
For example, if you want to add a method to the
Spree::Order model, you could
/app/models/mystore/order_decorator.rb with the following contents:
module MyStore::OrderDecorator def total super + BigDecimal(10.0) end Spree::Order.prepend self end
This creates a new module called
MyStore::OrderDecorator that prepends its
methods early in the method lookup chain. So, for method calls on
objects, the decorator's
total method would override the original
From now on, every order, when asked for its total, returns an inflated total by $10 (or whatever your currency is).
Decorators and Solidus upgrades
Decorators can complicate your Solidus upgrades. If you depend on decorators, ensure that you test them before upgrading in a production environment. Note that Solidus's core classes may change with each release.
Solidus is an open source platform supported by the community. We encourage everyone using Solius to contribute back to the documentation and the code.