-
Notifications
You must be signed in to change notification settings - Fork 2
Home
We're going to create a new application called store.
In the console:
bcms new store
Alternatively, if you plan to use postgresql:
bcms new store -d postgresql
Next:
cd store
Open the application in your editor of choice.
In the Gemfile change the gem browsercms to the forked version (temporary):
gem 'browsercms', :git => 'https://github.com/britneywright/browsercms.git', :branch => 'master'
Add the bcms_spree gem to the gemfile
gem 'bcms_spree'
In the console, run the next two commands:
bundle install
rails g bcms_spree:install
In the Gemfile add:
gem 'spree_gateway', :git => 'https://github.com/spree/spree_gateway.git', :branch => '2-2-stable'
Note: If you see the bcms_spree gem referenced more than once in the Gemfile, remove one reference.
In the console:
bundle install
spree install
The spree install will generate a series of questions you must answer:
- Would you like to install the default gateways? (Recommended) (yes/no) [yes]
yes
- Would you like to install the default authentication system? (yes/no) [yes]
no
- What is the name of the class representing users within your application? [User]
Cms::User
- Would you like to run the migrations? (yes/no) [yes]
yes
- Would you like to load the seed data? (yes/no) [yes]
yes
- Would you like to load the sample data? (yes/no) [yes]
yes
The installation will now run the Spree migrations and seed data.
There's two more steps required to configure Spree attributes on the BrowserCMS User model.
In the console:
bundle exec rails g spree:custom_user Cms::User
In the lib/spree/authentication_helpers.rb file you'll need to customize the paths. Your file should be changed to match this (Note: There currently isn't signup functionality. This can be setup and a helper added here):
module Spree
module AuthenticationHelpers
def self.included(receiver)
receiver.send :helper_method, :spree_current_user
receiver.send :helper_method, :spree_login_path
receiver.send :helper_method, :spree_logout_path
end
def spree_current_user
current_cms_user
end
def spree_login_path
main_app.new_cms_user_session_path
end
def spree_logout_path
main_app.destroy_cms_user_session_path
end
end
end
ApplicationController.send :include, Spree::AuthenticationHelpers
In the console:
rake db:migrate
Debugging: You may run into an error that looks like this (though the specific timestamp will be different):
$ rake db:migrate
rake aborted!
ActiveRecord::DuplicateMigrationVersionError: Multiple migrations have the version number 20140929220828
If you do, Spree has inadvertently generated a duplicate migration number. Find the file named '20140929220878_add_spree_fields_to_custom_user_table.rb' and rename it to be a unique name.
Finally if desired you can mount Spree to a path in config/routes.rb, we recommend 'shop':
mount Spree::Core::Engine, :at => '/shop'
Be sure Spree is referenced before BrowserCMS in the routes file, otherwise BrowserCMS will override all other paths in the application.
If you'd like to have a user's shopping cart persist on BrowserCMS pages you can copy this into your app/views/layouts/templates/default.html.erb file:
In the head add:
<script src="/assets/spree.js?body=1"></script>
<script src="/assets/spree/frontend/cart.js?body=1"></script>
<script>
if (Spree === undefined) {
var Spree = {};
}
if (Spree.routes == undefined) {
Spree.routes = {};
}
Spree.routes.states_search = "/shop/api/states";
Spree.routes.apply_coupon_code = function(order_id) {
return "/shop/api/orders/" + order_id + "/apply_coupon_code";
}
Spree.routes.root = "/shop/";
</script>
<script>
Spree.routes.cart_link = "/shop/cart_link"
</script>
In the body:
<div id="link-to-cart" data-hook>
<noscript>
<%= link_to Spree.t(:cart), spree.cart_path %>
</noscript>
</div>
<script>Spree.fetch_cart()</script>
Final step, start your local server. In the console:
rails s
You're super awesome new store should be visible. To login in go to /cms or /login