spree_promo 0.50.0 → 0.50.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/promotion/rules/first_order.rb +1 -1
- data/app/models/promotion.rb +2 -1
- data/app/models/promotion_credit.rb +0 -1
- data/app/views/admin/promotions/rules/_product.html.erb +1 -1
- data/app/views/checkout/_coupon_code_field.html.erb +2 -0
- data/config/locales/en.yml +9 -0
- data/lib/spree_promo.rb +31 -14
- metadata +9 -9
data/app/models/promotion.rb
CHANGED
@@ -7,7 +7,7 @@ class Promotion < ActiveRecord::Base
|
|
7
7
|
accepts_nested_attributes_for :promotion_rules
|
8
8
|
alias_method :rules, :promotion_rules
|
9
9
|
|
10
|
-
validates :name, :
|
10
|
+
validates :name, :presence => true
|
11
11
|
|
12
12
|
# TODO: Remove that after fix for https://rails.lighthouseapp.com/projects/8994/tickets/4329-has_many-through-association-does-not-link-models-on-association-save
|
13
13
|
# is provided
|
@@ -20,6 +20,7 @@ class Promotion < ActiveRecord::Base
|
|
20
20
|
MATCH_POLICIES = %w(all any)
|
21
21
|
|
22
22
|
scope :automatic, where("code IS NULL OR code = ''")
|
23
|
+
scope :manual, where("code IS NOT NULL AND code <> ''")
|
23
24
|
|
24
25
|
def eligible?(order)
|
25
26
|
!expired? && rules_are_eligible?(order)
|
@@ -4,7 +4,7 @@
|
|
4
4
|
</p>
|
5
5
|
<p class="field products_rule_product_group">
|
6
6
|
<label><%= t('product_group') %><br />
|
7
|
-
<%= select_tag "#{param_prefix}[product_group_id]",
|
7
|
+
<%= select_tag "#{param_prefix}[product_group_id]", options_from_collection_for_select(ProductGroup.all, :id, :name, promotion_rule.product_group_id) %></label>
|
8
8
|
</p>
|
9
9
|
<p class="field products_rule_products">
|
10
10
|
<label>
|
data/config/locales/en.yml
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
---
|
2
2
|
en:
|
3
|
+
activerecord:
|
4
|
+
attributes:
|
5
|
+
promotion:
|
6
|
+
name: "Name"
|
7
|
+
description: "Description"
|
8
|
+
code: "Code"
|
9
|
+
usage_limit: "Usage limit"
|
10
|
+
starts_at: "Starts at"
|
11
|
+
expires_at: "Expires at"
|
3
12
|
add_rule_of_type: Add rule of type
|
4
13
|
coupon: Coupon
|
5
14
|
coupon_code: Coupon code
|
data/lib/spree_promo.rb
CHANGED
@@ -22,11 +22,11 @@ module SpreePromo
|
|
22
22
|
|
23
23
|
Order.class_eval do
|
24
24
|
|
25
|
-
has_many :promotion_credits, :conditions => "source_type='Promotion'"
|
25
|
+
has_many :promotion_credits, :conditions => "source_type='Promotion'", :dependent => :destroy
|
26
26
|
|
27
27
|
attr_accessible :coupon_code
|
28
28
|
attr_accessor :coupon_code
|
29
|
-
before_save :process_coupon_code, :if => "@coupon_code"
|
29
|
+
before_save :process_coupon_code, :if => "@coupon_code.present?"
|
30
30
|
|
31
31
|
def promotion_credit_exists?(credit)
|
32
32
|
promotion_credits.reload.detect { |c| c.source_id == credit.id }
|
@@ -61,19 +61,36 @@ module SpreePromo
|
|
61
61
|
|
62
62
|
|
63
63
|
def process_automatic_promotions
|
64
|
-
#
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
})
|
64
|
+
# recalculate amount
|
65
|
+
self.promotion_credits.each do |credit|
|
66
|
+
if credit.source.eligible?(self)
|
67
|
+
amount = -credit.source.calculator.compute(self).abs
|
68
|
+
if credit.amount != amount
|
69
|
+
# avoid infinite callbacks
|
70
|
+
PromotionCredit.update_all("amount = #{amount}", { :id => credit.id })
|
71
|
+
end
|
72
|
+
else
|
73
|
+
credit.destroy
|
75
74
|
end
|
76
|
-
end
|
75
|
+
end
|
76
|
+
|
77
|
+
current_promotions = self.promotion_credits.map(&:source)
|
78
|
+
# return if current promotions can not be combined
|
79
|
+
return if current_promotions.any? { |promotion| !promotion.combine? }
|
80
|
+
|
81
|
+
new_promotions = eligible_automatic_promotions - current_promotions
|
82
|
+
new_promotions.each do |promotion|
|
83
|
+
next if current_promotions.present? && !promotion.combine?
|
84
|
+
amount = promotion.calculator.compute(self).abs
|
85
|
+
amount = item_total if amount > item_total
|
86
|
+
if amount > 0
|
87
|
+
self.promotion_credits.create(
|
88
|
+
:source => promotion,
|
89
|
+
:amount => -amount,
|
90
|
+
:label => promotion.name
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
77
94
|
end
|
78
95
|
|
79
96
|
def eligible_automatic_promotions
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_promo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 213
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 50
|
9
|
-
-
|
10
|
-
version: 0.50.
|
9
|
+
- 1
|
10
|
+
version: 0.50.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David North
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-19 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - "="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 213
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
- 50
|
33
|
-
-
|
34
|
-
version: 0.50.
|
33
|
+
- 1
|
34
|
+
version: 0.50.1
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
description: Required dependancy for Spree
|
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
requirements:
|
117
117
|
- none
|
118
118
|
rubyforge_project: spree_promo
|
119
|
-
rubygems_version: 1.
|
119
|
+
rubygems_version: 1.4.2
|
120
120
|
signing_key:
|
121
121
|
specification_version: 3
|
122
122
|
summary: Promotion functionality for use with Spree.
|