This is a simple Ruby on Rails plugin based on Rails Engine.
Add this line to your application's Gemfile:
gem 'shopping_cart', git: 'git://github.com/gremax/shopping_cart'And then execute:
$ bundle
Edit your app/controller/application_controller.rb and add a current_user method, unless you are using the Devise gem.
Mount the shopping_cart engine in your config/routes.rb:
mount ShoppingCart::Engine, at: '/shopping_cart'Create database structure:
rake shopping_cart:install:migrations
rake db:migrateAdd to your User model:
class User < ActiveRecord::Base
...
acts_as_customer
endAdd to your product models:
class Book < ActiveRecord::Base
...
acts_as_product
endclass Pen < ActiveRecord::Base
...
acts_as_product
endAlso you need to fill delivery types:
ShoppingCart::Delivery.create!([
{
name: 'UPS Ground',
price: 5.00
},
{
name: 'UPS Two Day',
price: 10.00
},
{
name: 'UPS One Day',
price: 15.00
}])For notification messages add to app/views/layout/application.html.erb:
<%= notice %>Add a book to the cart:
= button_to 'Add to cart', shopping_cart.order_items_path(book_id: book)Add a pen to the cart:
= button_to 'Add to cart', shopping_cart.order_items_path(pen_id: pen)Add a link to the cart:
= link_to 'Cart', shopping_cart.cart_pathAdd a link to the orders history:
= link_to 'Orders', shopping_cart.orders_pathYou can generate views for customization to app/views/shopping_cart:
$ rails generate shopping_cart:views
$ bundle exec rspec
- Fork it ( https://github.com/gremax/shopping_cart/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request