Dependencies
Overview
With Dependencies, you can easily replace parts of Spree internals with your custom classes. You can replace Services, Abilities, and Serializers. More will come in the future.Controller level customization
To replace serializers or Services in a specific API endpoint you can create a simple decorator: Create aapp/controllers/spree/cart_controller_decorator.rb
MyNewAwesomeCartSerializer
and also it will swap the default add_item_service
to MyNewAwesomeAddItemToCart
.
Different API endpoints can have different dependency injection points. You can review their source code to see what you can configure.
API level customization
Storefront and Platform APIs have separate Dependencies injection points so you can easily customize one without touching the other. In your Spree initializer (config/initializers/spree.rb
) please add:
Application (global) customization
You can also inject classes globally into the entire Spree stack. Be careful about this though as this touches every aspect of the application (both APIs, Admin Panel, and default Rails frontend if you’re using it).AnotherAddItemToCart
and the rest of the application will use MyNewAwesomeAddItemToCart
Values set in the initializer have to be strings, eg. 'MyNewAwesomeAddItemToCart'