Ashutosh
Ashutosh

Reputation: 4675

How to customize spree commerce?

I have installed Spree on a Windows machine, added sample data and accessed the admin.

But now what?

How do I create a new page or URL?

I don't find any controllers or files in my rails project folder. Do I have to change the location where Spree is downloaded?

Upvotes: 5

Views: 4096

Answers (1)

BenMorganIO
BenMorganIO

Reputation: 2046

But now what?

Spree is "developer friendly", which means you'll need to use the developers mindset as you're building your application. To create a new page, you'll have to follow the Rails-Way. If you run bin/rake routes you'll see all of the routes generated for you.

To generate a path in Spree, you need to call something like spree.root_path. If you have the same path named in your main application, then you'll have to call main_app.root_path. This way rails knows you want your own root path, not Spree's.

For some best practices, you should checkout this blog post: http://blog.benmorgan.io/post/102924399166/customizing-spree-some-best-practices. (My blog also has a lot of Spree content in it.)

I don't find any controllers or files in my rails project folder. Do I have to modify the location where the spree is downloaded?

Bundler installs Spree which is then stored via rvm or rbenv in its appropriate location. All you have to do is add:

gem 'spree', github: 'spree', branch: '3-0-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '3-0-stable'

Or you could use Solidus which I'm now using instead of Spree; currently moving all active Spree projects over to this one.

What I recommend:

  • Don't use the Spree Frontend. Understanding how the models work should be enough for you to get started. Making a new Spree::Order object should be quite simple. Then its just Spree::Order.next! and you can start checking things out. To add products to an order, you just order.contents.add Spree::Variant.first, 1 and you've got a new line item in the DB.
  • Read the source code. Spree is, honestly, ~4 rails applications. 1 for the models (core), 1 for the storefront (frontend), 1 for the admin (backend), and 1 for the API.
  • Use the V2 API. Spree 4 is aiming to have a new, revamped API that follows the JSON API spec and fully Ember compatible. For more information, please see the JSON API spec. The Spree V2 API is located here.

Upvotes: 4

Related Questions