Decorators

Solidus autoloads any file in the /app directory that has the suffix _decorator.rb, just like any other Rails models or controllers. This allows you to monkey patch Solidus functionality for your store.

For example, if you want to add a method to the Spree::Order model, you could create /app/models/mystore/order_decorator.rb with the following contents:

Ruby
    
      module MyStore
  module OrderDecorator
    def total
      super + BigDecimal(10.0)
    end
  end
end

Spree::Order.prepend MyStore::OrderDecorator

    
  

This creates a new module called MyStore::OrderDecorator that prepends its methods early in the method lookup chain. So, for method calls on Spree::Order objects, the decorator's total method would override the original total method.

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.

Feedback

Solidus is an open source platform supported by the community. We encourage everyone using Solius to contribute back to the documentation and the code.

If you’re interested in contributing to the docs, get started with the contributing guidelines. If you see something that needs fixing and can’t do it yourself, please send us an email.