spree_promo 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/app/models/spree/order_decorator.rb +1 -1
- data/app/models/spree/product_decorator.rb +1 -1
- data/app/models/spree/promotion/actions/create_adjustment.rb +38 -16
- data/app/models/spree/promotion.rb +2 -4
- data/app/views/spree/admin/promotion_actions/create.js.erb +2 -1
- data/app/views/spree/admin/promotions/_form.html.erb +3 -3
- metadata +5 -5
data/LICENSE
CHANGED
@@ -2,7 +2,7 @@ Spree::Product.class_eval do
|
|
2
2
|
has_and_belongs_to_many :promotion_rules, :join_table => :spree_products_promotion_rules
|
3
3
|
|
4
4
|
def possible_promotions
|
5
|
-
promotion_ids = promotion_rules.
|
5
|
+
promotion_ids = promotion_rules.pluck(:activator_id).uniq
|
6
6
|
Spree::Promotion.advertised.where(:id => promotion_ids).reject(&:expired?)
|
7
7
|
end
|
8
8
|
end
|
@@ -1,27 +1,37 @@
|
|
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
|
10
|
+
|
7
11
|
delegate :eligible?, :to => :promotion
|
8
12
|
|
9
13
|
before_validation :ensure_action_has_calculator
|
14
|
+
before_destroy :deals_with_adjustments
|
10
15
|
|
16
|
+
# Creates the adjustment related to a promotion for the order passed
|
17
|
+
# through options hash
|
11
18
|
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!
|
19
|
+
order = options[:order]
|
20
|
+
return if order.promotion_credit_exists?(self.promotion)
|
21
|
+
|
22
|
+
self.create_adjustment("#{I18n.t(:promotion)} (#{promotion.name})", order, order)
|
20
23
|
end
|
21
24
|
|
22
|
-
#
|
23
|
-
# adjustments are added all the time. They will get their
|
24
|
-
# set to false if the amount is 0
|
25
|
+
# Override of CalculatedAdjustments#create_adjustment so promotional
|
26
|
+
# adjustments are added all the time. They will get their eligibility
|
27
|
+
# set to false if the amount is 0.
|
28
|
+
#
|
29
|
+
# Currently an adjustment is created even when its promotion is not eligible.
|
30
|
+
# This helps to figure out later which adjustments should be eligible
|
31
|
+
# as the order is being updated
|
32
|
+
#
|
33
|
+
# BTW The order is updated (through order#update) every time an adjustment
|
34
|
+
# is saved
|
25
35
|
def create_adjustment(label, target, calculable, mandatory=false)
|
26
36
|
amount = compute_amount(calculable)
|
27
37
|
params = { :amount => amount,
|
@@ -32,16 +42,28 @@ module Spree
|
|
32
42
|
target.adjustments.create(params, :without_protection => true)
|
33
43
|
end
|
34
44
|
|
35
|
-
# Ensure a negative amount which does not exceed the sum of the order's
|
45
|
+
# Ensure a negative amount which does not exceed the sum of the order's
|
46
|
+
# item_total and ship_total
|
36
47
|
def compute_amount(calculable)
|
37
48
|
[(calculable.item_total + calculable.ship_total), super.to_f.abs].min * -1
|
38
49
|
end
|
39
50
|
|
40
51
|
private
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
52
|
+
def ensure_action_has_calculator
|
53
|
+
return if self.calculator
|
54
|
+
self.calculator = Calculator::FlatPercentItemTotal.new
|
55
|
+
end
|
56
|
+
|
57
|
+
def deals_with_adjustments
|
58
|
+
self.adjustments.each do |adjustment|
|
59
|
+
if adjustment.adjustable.complete?
|
60
|
+
adjustment.originator = nil
|
61
|
+
adjustment.save
|
62
|
+
else
|
63
|
+
adjustment.destroy
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
45
67
|
end
|
46
68
|
end
|
47
69
|
end
|
@@ -71,9 +71,7 @@ module Spree
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def order_activatable?(order)
|
74
|
-
order &&
|
75
|
-
created_at.to_i < order.created_at.to_i &&
|
76
|
-
!UNACTIVATABLE_ORDER_STATES.include?(order.state)
|
74
|
+
order && !UNACTIVATABLE_ORDER_STATES.include?(order.state)
|
77
75
|
end
|
78
76
|
|
79
77
|
# Products assigned to all product rules
|
@@ -93,7 +91,7 @@ module Spree
|
|
93
91
|
end
|
94
92
|
|
95
93
|
def credits
|
96
|
-
Adjustment.promotion.where(:originator_id => actions.
|
94
|
+
Adjustment.promotion.where(:originator_id => actions.pluck(:id))
|
97
95
|
end
|
98
96
|
|
99
97
|
def credits_count
|
@@ -2,10 +2,11 @@ $('#actions').append('<%= escape_javascript( render(:partial => 'spree/admin/pro
|
|
2
2
|
$('#actions .no-objects-found').hide();
|
3
3
|
$(document).ready(function(){
|
4
4
|
$(".variant_autocomplete").variantAutocomplete();
|
5
|
+
//enable select2 functions for recently added box
|
6
|
+
$('.type-select.select2').last().select2();
|
5
7
|
});
|
6
8
|
initProductActions();
|
7
9
|
|
8
|
-
$('.type-select.select2').select2();
|
9
10
|
|
10
11
|
$('#<%= dom_id @promotion_action %>').hide();
|
11
12
|
$('#<%= dom_id @promotion_action %>').fadeIn();
|
@@ -45,12 +45,12 @@
|
|
45
45
|
|
46
46
|
<div id="starts_at_field" class="field">
|
47
47
|
<%= f.label :starts_at %>
|
48
|
-
<%= f.text_field :starts_at, :class => 'datepicker datepicker-from fullwidth' %>
|
48
|
+
<%= f.text_field :starts_at, :value => datepicker_field_value(@promotion.starts_at), :class => 'datepicker datepicker-from fullwidth' %>
|
49
49
|
</div>
|
50
50
|
|
51
51
|
<div id="expires_at_field" class="field">
|
52
52
|
<%= f.label :expires_at %>
|
53
|
-
<%= f.text_field :expires_at, :class => 'datepicker datepicker-
|
54
|
-
</div>
|
53
|
+
<%= f.text_field :expires_at, :value => datepicker_field_value(@promotion.expires_at), :class => 'datepicker datepicker-to fullwidth' %>
|
54
|
+
</div>
|
55
55
|
</div>
|
56
56
|
</div>
|
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.3.
|
4
|
+
version: 1.3.2
|
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.3.
|
21
|
+
version: 1.3.2
|
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.3.
|
29
|
+
version: 1.3.2
|
30
30
|
description: Required dependency for Spree
|
31
31
|
email: david@spreecommerce.com
|
32
32
|
executables: []
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
segments:
|
125
125
|
- 0
|
126
|
-
hash:
|
126
|
+
hash: 4289978919037252357
|
127
127
|
requirements:
|
128
128
|
- none
|
129
129
|
rubyforge_project:
|