5

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?

notapatch
  • 6,569
  • 6
  • 41
  • 45
Ashutosh
  • 4,371
  • 10
  • 59
  • 105

1 Answers1

4

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.
BenMorganIO
  • 2,036
  • 17
  • 37
  • Hi Ben, thanks for the explanation. I'm on a Windows machine. I started the server and checked the logs. The files are being rendered from the location: C:\RailsInstaller\Ruby2.1.0\lib\ruby\gems\2.1.0\gems\spree_frontend-3.0.4 Normally, all the files in other technologies used to be loaded from within your project folder. This is not the case with spree. It something like spree is being connected to my application. There are no images, css, js files from my rails project. The question is: If I want to change the UI of the page, should I do it by changing the files on above path? – Ashutosh Oct 12 '15 at 03:50
  • I'm meanwhile going through this: https://guides.spreecommerce.com/developer/asset.html – Ashutosh Oct 12 '15 at 03:52
  • I'm able to override the css, now looking for changing the HTML all together. I'll be reading more – Ashutosh Oct 12 '15 at 04:03
  • @Ashutosh I wouldn't recommend changing the HTML files in the ruby 2.1.0 folder. What if you bump to ruby 2.2.3; which I would recommend? Then you would have to copy your changes? What if you deploy your app to 5 servers? Then you would have to edit the files in every single server. The solution is to update the HTML file in its location. I would recommend using the chrome helper "Rails Panel" to help you locate the file path. Then make an html file with the same path and name as the view and code and update to your liking. – BenMorganIO Oct 12 '15 at 04:33
  • @BenMorganIO Thanks for recommending Solidus. The Spree team used Deface for adding components to protect developers' customizations from being obliterated when updating Spree; how does Solidus handle customization given that the team moved away from Spree's Deface/class_eval? – femmestem Dec 09 '15 at 23:45
  • So, how to modify HTML in Solidus after all? The Views / Controllers folders are empty.. – W.M. Jul 01 '16 at 21:55
  • 1
    @W.M. you'll probably want to check out the source code for the Solidus Frontend :). You'll find it here: https://github.com/solidusio/solidus/tree/master/frontend – BenMorganIO Jul 05 '16 at 09:19