spree_promo 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,36 @@
|
|
1
1
|
module Spree
|
2
2
|
class Promotion
|
3
3
|
module Actions
|
4
|
+
# Responsible for the creation and management of an adjustment since an
|
5
|
+
# an adjustment uses its originator to also update its eligiblity and amount
|
4
6
|
class CreateAdjustment < PromotionAction
|
5
7
|
calculated_adjustments
|
6
8
|
|
9
|
+
has_many :adjustments, :as => :originator, :dependent => :destroy
|
10
|
+
|
7
11
|
delegate :eligible?, :to => :promotion
|
8
12
|
|
9
13
|
before_validation :ensure_action_has_calculator
|
10
14
|
|
15
|
+
# Creates the adjustment related to a promotion for the order passed
|
16
|
+
# through options hash
|
11
17
|
def perform(options = {})
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
order.adjustments.promotion.reload.clear
|
17
|
-
order.update!
|
18
|
-
create_adjustment("#{I18n.t(:promotion)} (#{promotion.name})", order, order)
|
19
|
-
order.update!
|
18
|
+
order = options[:order]
|
19
|
+
return if order.promotion_credit_exists?(self.promotion)
|
20
|
+
|
21
|
+
self.create_adjustment("#{I18n.t(:promotion)} (#{promotion.name})", order, order)
|
20
22
|
end
|
21
23
|
|
22
|
-
#
|
23
|
-
# adjustments are added all the time. They will get their
|
24
|
-
# set to false if the amount is 0
|
24
|
+
# Override of CalculatedAdjustments#create_adjustment so promotional
|
25
|
+
# adjustments are added all the time. They will get their eligibility
|
26
|
+
# set to false if the amount is 0.
|
27
|
+
#
|
28
|
+
# Currently an adjustment is created even when its promotion is not eligible.
|
29
|
+
# This helps to figure out later which adjustments should be eligible
|
30
|
+
# as the order is being updated
|
31
|
+
#
|
32
|
+
# BTW The order is updated (through order#update) every time an adjustment
|
33
|
+
# is saved
|
25
34
|
def create_adjustment(label, target, calculable, mandatory=false)
|
26
35
|
amount = compute_amount(calculable)
|
27
36
|
params = { :amount => amount,
|
@@ -32,7 +41,8 @@ module Spree
|
|
32
41
|
target.adjustments.create(params, :without_protection => true)
|
33
42
|
end
|
34
43
|
|
35
|
-
# Ensure a negative amount which does not exceed the sum of the order's
|
44
|
+
# Ensure a negative amount which does not exceed the sum of the order's
|
45
|
+
# item_total and ship_total
|
36
46
|
def compute_amount(calculable)
|
37
47
|
[(calculable.item_total + calculable.ship_total), super.to_f.abs].min * -1
|
38
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_promo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: spree_core
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.2.
|
21
|
+
version: 1.2.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.2.
|
29
|
+
version: 1.2.4
|
30
30
|
description: Required dependency for Spree
|
31
31
|
email: david@spreecommerce.com
|
32
32
|
executables: []
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
segments:
|
134
134
|
- 0
|
135
|
-
hash:
|
135
|
+
hash: 4124392625263849039
|
136
136
|
requirements:
|
137
137
|
- none
|
138
138
|
rubyforge_project:
|