shop_bunny 0.7 → 0.7.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/config/initializers/add_cart_finder_to_controllers.rb +16 -0
- data/config/initializers/machinist.rb +19 -0
- data/config/initializers/shop_bunny.rb +24 -0
- data/config/routes.rb +63 -0
- metadata +8 -6
- data/db/development.sqlite3 +0 -0
- data/db/schema.rb +0 -57
- data/db/seeds.rb +0 -19
- data/db/test.sqlite3 +0 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActionController
|
2
|
+
class Base
|
3
|
+
protected
|
4
|
+
# The default behaviour is to map a Cart to a session variable 'cart_id'.
|
5
|
+
# You might want to overwrite this method to authorize a user.
|
6
|
+
# TODO This could result in a mass of empty carts. A Problem?
|
7
|
+
def find_cart
|
8
|
+
if session[:cart_id]
|
9
|
+
@cart = Cart.find(session[:cart_id])
|
10
|
+
else
|
11
|
+
@cart = Cart.create
|
12
|
+
session[:cart_id] = @cart.id
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Add other envs here e.g. cucumber
|
2
|
+
if Rails.env.test?
|
3
|
+
require 'machinist'
|
4
|
+
# require 'machinist/active_record'
|
5
|
+
|
6
|
+
def Machinist.clear!
|
7
|
+
Sham.clear
|
8
|
+
# ActiveRecord::Base.clear_blueprints!
|
9
|
+
end
|
10
|
+
|
11
|
+
def Machinist.load_blueprints
|
12
|
+
Dir[Rails.root.join("test/blueprints", "**", "*.rb")].each do |file|
|
13
|
+
load file
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Put Machinist.load_blueprints in the test_helper.rb
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This is where you can customize the innards of ShopBunny.
|
3
|
+
ShopBunny.setup do |config|
|
4
|
+
# ShopBunny.item_model_class_name should return the name of the class of
|
5
|
+
# which the items/products/things in your store are an instance of.
|
6
|
+
# The default is 'Item'
|
7
|
+
#
|
8
|
+
# config.item_model_class_name = 'Product'
|
9
|
+
|
10
|
+
# ShopBunny.shipping_cost_calculator should return a class or module that
|
11
|
+
# has a method 'costs_for(cart)' which returns a float (the shipping cost).
|
12
|
+
# Note: You may also customize this behaviour by overwriting
|
13
|
+
# Cart#shipping_cost_calculator
|
14
|
+
# The default is ShopBunny::ShippingCostCalculator
|
15
|
+
#
|
16
|
+
# config.shipping_cost_calculator = MyShippingCostCalculator
|
17
|
+
|
18
|
+
# ShopBunny.controller_enhancement is a module that is included into the
|
19
|
+
# CartsController. You can e.g. control which layout is used for rendering
|
20
|
+
# the cart or add filters. E.g. just drop a ShopBunnyEnhancements module in
|
21
|
+
# lib/shop_bunny_enhancements.rb and use it like this:
|
22
|
+
# require 'shop_bunny_enhancements'
|
23
|
+
# config.controller_enhancement = ShopBunnyEnhancements
|
24
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
resource :cart, :only => [:show, :update] do
|
3
|
+
get :add_item, :as => 'add_item_to'
|
4
|
+
get :remove_item, :as => 'remove_item_from'
|
5
|
+
end
|
6
|
+
|
7
|
+
# The priority is based upon order of creation:
|
8
|
+
# first created -> highest priority.
|
9
|
+
|
10
|
+
# Sample of regular route:
|
11
|
+
# match 'products/:id' => 'catalog#view'
|
12
|
+
# Keep in mind you can assign values other than :controller and :action
|
13
|
+
|
14
|
+
# Sample of named route:
|
15
|
+
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
16
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
17
|
+
|
18
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
19
|
+
# resources :products
|
20
|
+
|
21
|
+
# Sample resource route with options:
|
22
|
+
# resources :products do
|
23
|
+
# member do
|
24
|
+
# get 'short'
|
25
|
+
# post 'toggle'
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# collection do
|
29
|
+
# get 'sold'
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
|
33
|
+
# Sample resource route with sub-resources:
|
34
|
+
# resources :products do
|
35
|
+
# resources :comments, :sales
|
36
|
+
# resource :seller
|
37
|
+
# end
|
38
|
+
|
39
|
+
# Sample resource route with more complex sub-resources
|
40
|
+
# resources :products do
|
41
|
+
# resources :comments
|
42
|
+
# resources :sales do
|
43
|
+
# get 'recent', :on => :collection
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
|
47
|
+
# Sample resource route within a namespace:
|
48
|
+
# namespace :admin do
|
49
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
50
|
+
# # (app/controllers/admin/products_controller.rb)
|
51
|
+
# resources :products
|
52
|
+
# end
|
53
|
+
|
54
|
+
# You can have the root of your site routed with "root"
|
55
|
+
# just remember to delete public/index.html.
|
56
|
+
# root :to => "welcome#index"
|
57
|
+
|
58
|
+
# See how all your routes lay out with "rake routes"
|
59
|
+
|
60
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
61
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
62
|
+
# match ':controller(/:action(/:id(.:format)))'
|
63
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shop_bunny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 117
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
|
9
|
+
- 0
|
10
|
+
- 1
|
11
|
+
version: 0.7.0.1
|
10
12
|
platform: ruby
|
11
13
|
authors:
|
12
14
|
- kopfmaschine.com
|
@@ -40,8 +42,6 @@ files:
|
|
40
42
|
- app/models/item.rb
|
41
43
|
- app/controllers/application_controller.rb
|
42
44
|
- app/controllers/carts_controller.rb
|
43
|
-
- db/test.sqlite3
|
44
|
-
- db/schema.rb
|
45
45
|
- db/migrate/20100915162029_remove_owner_id_from_carts.rb
|
46
46
|
- db/migrate/20100915091059_create_coupons.rb
|
47
47
|
- db/migrate/20100915073016_create_items.rb
|
@@ -49,8 +49,10 @@ files:
|
|
49
49
|
- db/migrate/20100915093821_create_coupon_uses.rb
|
50
50
|
- db/migrate/20100916194407_set_default_column_value_for_cart_items_quantity.rb
|
51
51
|
- db/migrate/20100902115757_create_cart_items.rb
|
52
|
-
-
|
53
|
-
-
|
52
|
+
- config/initializers/add_cart_finder_to_controllers.rb
|
53
|
+
- config/initializers/shop_bunny.rb
|
54
|
+
- config/initializers/machinist.rb
|
55
|
+
- config/routes.rb
|
54
56
|
has_rdoc: true
|
55
57
|
homepage: http://kopfmaschine.com
|
56
58
|
licenses: []
|
data/db/development.sqlite3
DELETED
Binary file
|
data/db/schema.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# This file is auto-generated from the current state of the database. Instead
|
2
|
-
# of editing this file, please use the migrations feature of Active Record to
|
3
|
-
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
-
#
|
5
|
-
# Note that this schema.rb definition is the authoritative source for your
|
6
|
-
# database schema. If you need to create the application database on another
|
7
|
-
# system, you should be using db:schema:load, not running all the migrations
|
8
|
-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
-
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
-
#
|
11
|
-
# It's strongly recommended to check this file into your version control system.
|
12
|
-
|
13
|
-
ActiveRecord::Schema.define(:version => 20100916194407) do
|
14
|
-
|
15
|
-
create_table "cart_items", :force => true do |t|
|
16
|
-
t.integer "cart_id"
|
17
|
-
t.integer "item_id"
|
18
|
-
t.integer "quantity", :default => 0
|
19
|
-
t.datetime "created_at"
|
20
|
-
t.datetime "updated_at"
|
21
|
-
end
|
22
|
-
|
23
|
-
create_table "carts", :force => true do |t|
|
24
|
-
t.string "type"
|
25
|
-
t.datetime "created_at"
|
26
|
-
t.datetime "updated_at"
|
27
|
-
end
|
28
|
-
|
29
|
-
create_table "coupon_uses", :force => true do |t|
|
30
|
-
t.integer "cart_id"
|
31
|
-
t.integer "coupon_id"
|
32
|
-
t.datetime "created_at"
|
33
|
-
t.datetime "updated_at"
|
34
|
-
end
|
35
|
-
|
36
|
-
create_table "coupons", :force => true do |t|
|
37
|
-
t.boolean "removes_tax", :default => false
|
38
|
-
t.float "discount_percentage", :default => 1.0
|
39
|
-
t.float "discount_credit", :default => 0.0
|
40
|
-
t.boolean "removes_shipping_cost", :default => false
|
41
|
-
t.integer "bonus_article_id"
|
42
|
-
t.date "valid_from"
|
43
|
-
t.date "valid_until"
|
44
|
-
t.text "title"
|
45
|
-
t.string "code"
|
46
|
-
t.datetime "created_at"
|
47
|
-
t.datetime "updated_at"
|
48
|
-
end
|
49
|
-
|
50
|
-
create_table "items", :force => true do |t|
|
51
|
-
t.float "price"
|
52
|
-
t.string "title"
|
53
|
-
t.datetime "created_at"
|
54
|
-
t.datetime "updated_at"
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
data/db/seeds.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
-
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
-
#
|
4
|
-
# Examples:
|
5
|
-
#
|
6
|
-
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
-
# Mayor.create(:name => 'Daley', :city => cities.first)
|
8
|
-
|
9
|
-
# Dummy data for development
|
10
|
-
if Rails.env.development?
|
11
|
-
3.times { |i| Item.create! :price => i }
|
12
|
-
3.times { |i|
|
13
|
-
c = Coupon.new
|
14
|
-
c.code = "code#{i}"
|
15
|
-
c.title = "10% discount coupon #{i}"
|
16
|
-
c.discount_percentage = 0.9
|
17
|
-
c.save!
|
18
|
-
}
|
19
|
-
end
|
data/db/test.sqlite3
DELETED
Binary file
|