shop_bunny 0.7.4.10 → 0.7.4.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/app/models/coupon.rb
CHANGED
|
@@ -11,6 +11,9 @@ class Coupon < ActiveRecord::Base
|
|
|
11
11
|
|
|
12
12
|
# TODO Add self destruction when coupon has expired?
|
|
13
13
|
|
|
14
|
+
scope :valid, lambda {{:conditions => ['(coupons.valid_from IS NULL OR coupons.valid_from <= ?) AND (coupons.valid_until IS NULL OR coupons.valid_until >= ?)', Time.now, Time.now]}}
|
|
15
|
+
scope :automatically_added_over, lambda {|value| {:conditions => ['value_of_automatic_add <= ?', value]}}
|
|
16
|
+
|
|
14
17
|
def expired?
|
|
15
18
|
not_yet_valid? || has_expired?
|
|
16
19
|
end
|
|
@@ -59,6 +59,10 @@ module ShopBunny
|
|
|
59
59
|
cart_item = self.cart_items.find_or_create_by_item_id(item.id)
|
|
60
60
|
cart_item.quantity += options[:quantity]
|
|
61
61
|
cart_item.save!
|
|
62
|
+
|
|
63
|
+
update_automatic_coupons!
|
|
64
|
+
|
|
65
|
+
self.save!
|
|
62
66
|
self.reload
|
|
63
67
|
cart_item
|
|
64
68
|
end
|
|
@@ -74,6 +78,9 @@ module ShopBunny
|
|
|
74
78
|
self.reload
|
|
75
79
|
end
|
|
76
80
|
end
|
|
81
|
+
|
|
82
|
+
update_automatic_coupons!
|
|
83
|
+
|
|
77
84
|
cart_item
|
|
78
85
|
end
|
|
79
86
|
|
|
@@ -102,6 +109,16 @@ module ShopBunny
|
|
|
102
109
|
cart_items.empty?
|
|
103
110
|
end
|
|
104
111
|
|
|
112
|
+
# Remove all items from the cart
|
|
113
|
+
def clear!
|
|
114
|
+
cart_items.each {|i| i.destroy}
|
|
115
|
+
cart_items.clear
|
|
116
|
+
|
|
117
|
+
coupon_uses.each {|u| u.destroy}
|
|
118
|
+
coupon_uses.clear
|
|
119
|
+
coupons.clear
|
|
120
|
+
end
|
|
121
|
+
|
|
105
122
|
# Make
|
|
106
123
|
def as_json(options={})
|
|
107
124
|
{
|
|
@@ -120,6 +137,19 @@ module ShopBunny
|
|
|
120
137
|
|
|
121
138
|
protected
|
|
122
139
|
|
|
140
|
+
def update_automatic_coupons!
|
|
141
|
+
coupon_uses.each do |use|
|
|
142
|
+
use.destroy if use.coupon.value_of_automatic_add
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
save!
|
|
146
|
+
reload
|
|
147
|
+
|
|
148
|
+
Coupon.valid.automatically_added_over(item_sum).each do |coupon|
|
|
149
|
+
coupons << coupon
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
123
153
|
def update_coupons
|
|
124
154
|
Array(@coupon_code).each { |code|
|
|
125
155
|
coupon = Coupon.find_by_code(code)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shop_bunny
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 113
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 7
|
|
9
9
|
- 4
|
|
10
|
-
-
|
|
11
|
-
version: 0.7.4.
|
|
10
|
+
- 11
|
|
11
|
+
version: 0.7.4.11
|
|
12
12
|
platform: ruby
|
|
13
13
|
authors:
|
|
14
14
|
- kopfmaschine.com
|
|
@@ -16,7 +16,7 @@ autorequire:
|
|
|
16
16
|
bindir: bin
|
|
17
17
|
cert_chain: []
|
|
18
18
|
|
|
19
|
-
date: 2010-11-
|
|
19
|
+
date: 2010-11-25 00:00:00 +01:00
|
|
20
20
|
default_executable:
|
|
21
21
|
dependencies: []
|
|
22
22
|
|
|
@@ -30,32 +30,33 @@ extensions: []
|
|
|
30
30
|
extra_rdoc_files: []
|
|
31
31
|
|
|
32
32
|
files:
|
|
33
|
-
- lib/generators/shop_bunny/templates/shopbunny_model_template.rb
|
|
34
|
-
- lib/generators/shop_bunny/templates/shopbunny_controller_template.rb
|
|
35
33
|
- lib/generators/shop_bunny/install_generator.rb
|
|
36
|
-
- lib/shop_bunny.rb
|
|
34
|
+
- lib/generators/shop_bunny/templates/shopbunny_controller_template.rb
|
|
35
|
+
- lib/generators/shop_bunny/templates/shopbunny_model_template.rb
|
|
37
36
|
- lib/shop_bunny/cart_controller_module.rb
|
|
38
37
|
- lib/shop_bunny/cart_module.rb
|
|
39
|
-
- lib/shop_bunny/shipping_cost_calculator.rb
|
|
40
38
|
- lib/shop_bunny/engine.rb
|
|
41
|
-
-
|
|
39
|
+
- lib/shop_bunny/shipping_cost_calculator.rb
|
|
40
|
+
- lib/shop_bunny.rb
|
|
41
|
+
- app/controllers/application_controller.rb
|
|
42
|
+
- app/controllers/carts_controller.rb
|
|
42
43
|
- app/models/cart.rb
|
|
43
|
-
- app/models/coupon_use.rb
|
|
44
44
|
- app/models/cart_item.rb
|
|
45
45
|
- app/models/coupon.rb
|
|
46
|
+
- app/models/coupon_use.rb
|
|
46
47
|
- app/models/item.rb
|
|
47
|
-
- app/
|
|
48
|
-
- app/controllers/carts_controller.rb
|
|
49
|
-
- db/migrate/20100915162029_remove_owner_id_from_carts.rb
|
|
50
|
-
- db/migrate/20100915091059_create_coupons.rb
|
|
51
|
-
- db/migrate/20100915073016_create_items.rb
|
|
48
|
+
- app/views/carts/show.html.erb
|
|
52
49
|
- db/migrate/20100902115627_create_carts.rb
|
|
50
|
+
- db/migrate/20100902115757_create_cart_items.rb
|
|
51
|
+
- db/migrate/20100915073016_create_items.rb
|
|
52
|
+
- db/migrate/20100915091059_create_coupons.rb
|
|
53
53
|
- db/migrate/20100915093821_create_coupon_uses.rb
|
|
54
|
+
- db/migrate/20100915162029_remove_owner_id_from_carts.rb
|
|
54
55
|
- db/migrate/20100916194407_set_default_column_value_for_cart_items_quantity.rb
|
|
55
|
-
- db/migrate/
|
|
56
|
+
- db/migrate/20101125140137_add_value_of_automatic_add_to_coupons.rb
|
|
56
57
|
- config/initializers/add_cart_finder_to_controllers.rb
|
|
57
|
-
- config/initializers/shop_bunny.rb
|
|
58
58
|
- config/initializers/machinist.rb
|
|
59
|
+
- config/initializers/shop_bunny.rb
|
|
59
60
|
- config/routes.rb
|
|
60
61
|
has_rdoc: true
|
|
61
62
|
homepage: http://kopfmaschine.com
|