Spree is a complete open source ecommerce solution for Ruby on Rails.
Links:
Contents:
$ gem install rails -v 5.0.2
$ gem install bundler
$ bundler -v
Bundler version 1.15.1
$ brew -v
Homebrew 1.2.3
Homebrew/homebrew-core (git revision 0818; last commit 2017-06-19)
$ brew update
$ brew install imagemagick
Installed version 7.0.6-0 of imagemagick
$ mysql --version
mysql Ver 14.14 Distrib 5.7.16, for osx10.11 (x86_64) using EditLine wrapper
$ rails _5.0.2_ new mystore -d mysql
$ cd mystore
Add following to Gemfile:
gem 'spree', '~> 3.2.1'
gem 'spree_auth_devise', '~> 3.2.0'
gem 'spree_gateway', '~> 3.2.0'
Run bundle install
.
$ rake db:create
$ rails g spree:install
Admin User Email: spree@example.com
Admin User Password: spree123
$ rails g spree:auth:install
$ rails g spree_gateway:install
$ rails server
Now visit http://localhost:3000 to view the product store and http://localhost:3000/admin to access the admin end.
We will install spree extension spree_i18n
for an example here.
# Gemfile
gem 'spree_i18n', github: 'spree-contrib/spree_i18n', branch: ‘master'
Run bundle install
.
$ bundle exec rails g spree_i18n:install
Go to directory outside your Spree application.
We are creating an extension named spree_simple_sales
here.
$ spree extension simple_sales
$ cd spree_simple_sales
$ bundle install
$ bundle exec rails g migration add_sale_price_to_spree_variants sale_price:decimal # OR whatever
# app/models/spree/variant_decorator.rb
module Spree
Variant.class_eval do
end
end
# app/controllers/spree/home_controller_decorator.rb
module Spree
HomeController.class_eval do
def sale
end
end
end
# config/routes.rb
Spree::Core::Engine.routes.draw do
get '/sale' => 'home#sale'
end
Create file app/views/spree/home/sale.html.erb and add the view content.
# app/overrides/add_sale_price_to_product_edit.rb
Deface::Override.new(virtual_path: 'spree/admin/products/_form',
name: 'add_sale_price_to_product_edit',
insert_after: "erb[loud]:contains('text_field :price')",
text: "
<%= f.field_container :sale_price do %>
<%= f.label :sale_price, raw(Spree.t(:sale_price) + content_tag(:span, ' *')) %>
<%= f.text_field :sale_price, value:
number_to_currency(@product.sale_price, unit: '') %>
<%= f.error_message_on :sale_price %>
<% end %>
")
Add the following to Gemfile and run bundle install
:
gem 'spree_simple_sales', path: 'path/to/extension’
$ rails g spree_simple_sales:install
Visit http://localhost:3000/sale and you should see the new page created in the extension.
$ cd spree/guides/
$ bundle install
$ nanoc autocompile
Now, spree guides will be available at http://localhost:3000/.