Search code examples
ruby-on-railsruby-on-rails-3spree

What's a good way to interact with Spree's cart/products from Rails app?


I'm bolting Spree onto an existing app. In my app's pages, to display a subset of products I'm currently using the taxon id to access Spree::Product. Same with orders: from the app code I do "Spree::Order.find(session[:order_id])" (so I can display # of items in cart outside of Spree pages)

This seems heavy handed... should I be customizing Spree instead (rewrite some pages), or spinning it up as a separate instance and making API calls, etc.?

Thanks!


Solution

  • Spree has a module called Spree::ControllerHelpers::CurrentOrder that you could include into your ApplicationController. This would make the current_order method available in all views for your application.