4

I'm stuck on building a new e-commerce site using Spree. I've tried overriding the admin view but I don't know how to make an admin account and so I can't log in.

I also wanted to try to edit the gem itself. I tried doing "bundle open spree_frontend" on my terminal and got back "To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR" I edited the .bash_profile to have "export EDITOR="subl -w" export BUNDLER_EDITOR="subl" " but I still get the same response.

I've been trying to read the documentation but I'm stuck. Can anyone give me any advice or help?

Edit: I figured out how to make myself an Admin but I still can't figure out how to completely customize the index.html.erb or other views.

Eric Doyle
  • 53
  • 5
  • 1
    Did you restart your terminal after making those changes to the config files? – Ryan Bigg May 30 '16 at 21:25
  • I just did and I still get the same response. I put this export EDITOR="subl -w" export BUNDLER_EDITOR="subl" on the bottom of the .bash_profile and restarted the terminal and it still didn't work. – Eric Doyle May 30 '16 at 22:21

2 Answers2

5

I'm not quite sure if you need to know how to change just the admin root index page, or whether you want to customize any view. So, here are both answers.

Instructions on how to customize any view:

The thing to remember is that Spree is just a rails engine. All rails engine views can be overwritten by adding a view in the same location on the main rails application. The confusing part of spree is how the project is structured.

If you look at the Spree project on github, you will see it is broken into four parts: core, frontend, backend, and api. Each of those parts acts like a little rails engine itself. So, the backend section uses the app/views/spree/admin folder for all the admin views.

The secret is to copy the view you want to customize, put it in the right location in your application, and then update it.

So, if you are trying to customize the admin products index page, go to github and copy the code at backend/spree/app/views/admin/products/index.html.erb and paste it into your project at app/views/spree/admin/products/index.html.erb

I have a little more detailed instructions over on quora, specifically about a Version 2.3 frontend update, if you think some images might help.

How to customize the admin root index view:

Version 2.4 or later

If you are trying to change the root path for the admin index, you will need to create a controller decorator for the admin root controller, and overwrite the index action, then build a view at app/views/spree/admin/root/index.html.erb to make it look like you want.

app/controllers/spree/admin/root_controller_decorator.rb

module Spree
  module Admin
    RootController.class_eval do

      def index
        # add any custom controller code here you need
        # it will load the view at app/views/spree/admin/root/index.html.erb
        # by convention
      end
    end
  end
end

Version 2.3 or less

Earlier versions of spree just rely on the routes file to redirect orders#index. Just add a new entry in your routes file to where you want to direct the traffic, then build a controller#action and view to serve the content.

Frankly, you could do the same for Version 2.4 and up, but the newer versions incorporate authentication into the root controller, so no need to reinvent the wheel.

Dan Williams
  • 3,769
  • 1
  • 18
  • 26
  • 1
    This was exceptionally helpful! I've been looking and all I can find is updating certain sections of the view (which normally makes sense) with Deface. This has been the best answer so far. – beckah May 24 '17 at 18:07
  • 1
    Glad to help @beckah! – Dan Williams May 25 '17 at 20:53
0

In regards to trying to make an admin

user = User.find_by(email: "master@example.com")
user.spree_roles << Spree::Role.find_or_create_by(name: "admin")

http://guides.spreecommerce.org/developer/authentication.html#the-user-model-1

Ropeney
  • 1,065
  • 8
  • 10