spree-dependencies

Installation
SKILL.md

Spree Dependencies (swapping whole classes)

Commands use the Spree CLI (spree …). On a classic Rails app without the CLI, run bin/rails … / bundle exec rake … from the app root. Paths assume the Rails app lives in server/.

Spree.dependencies lets you replace a core class — a service, a workflow, a policy, a serializer — with your own. Spree's code calls Spree.cart_add_item_workflow.call(...), never Spree::Carts::AddItem.call(...), so your replacement runs everywhere: Store API, Admin API, dashboard, jobs, imports.

First: do you actually need to replace the class?

Replacing a class means you own a copy that must be re-synced with every Spree release. Most reasons people swap a class are covered by a workflow hook, which survives upgrades:

You want to… Use instead of a swap
Block add-to-cart / checkout / a cancel / a return validate hook — Spree.hooks.register('carts.add_item.validate', 'MyStore::Rule')
Add data to tax or promotion calculation Context hook (carts.recalculate_totals.set_tax_line_context, carts.recalculate.set_promotion_context)
Write rows alongside the change, atomically Lifecycle hook (carts.add_item.after_item_added, carts.complete.after_finalize)
Sync to ERP / send email / reindex Event subscriber (spree-events-webhooks)
Add a checkout requirement Spree::Checkout::Registry.add_requirement (spree-checkout)
Add a field to an API response Subclass the serializer (below) — a small, legitimate swap
Installs
269
GitHub Stars
10
First Seen
Jun 11, 2026