spree_promo 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/controllers/spree/orders_controller_decorator.rb +1 -0
- data/app/controllers/spree/store_controller_decorator.rb +10 -10
- data/app/models/spree/calculator/percent_per_item.rb +7 -5
- data/app/models/spree/order_decorator.rb +22 -5
- data/app/models/spree/promotion.rb +7 -4
- data/app/models/spree/promotion/actions/create_line_items.rb +2 -0
- data/app/overrides/promo_admin_tabs.rb +1 -1
- data/app/views/spree/admin/promotions/_promotion_action.html.erb +2 -1
- data/app/views/spree/admin/promotions/_promotion_rule.html.erb +1 -0
- data/config/locales/en.yml +2 -2
- metadata +9 -16
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 40582bf42f5cd6675df3f3f3db1480808111213f
|
4
|
+
data.tar.gz: 2868fc07c91b0cecf867536dddcb1af9efaccda0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5c949e94bd1b46aaf8a9240ee90366068676fcce700b5081e7117699b2944823ed22df631707ee6c0670eddbafb9389bda7d8afa2459f9b8316b2f76a30ff6aa
|
7
|
+
data.tar.gz: e82b0b25514add622fa7645073a5a748aaaabb79ba8880f034531c774be28a64bf7ef1854f640624480d51e4fe3f0813505ddcf517acb4c5c523b6142ce4a5e5
|
@@ -15,6 +15,7 @@ Spree::OrdersController.class_eval do
|
|
15
15
|
respond_with(@order) do |format|
|
16
16
|
format.html do
|
17
17
|
if params.has_key?(:checkout)
|
18
|
+
@order.next_transition.run_callbacks if @order.cart?
|
18
19
|
redirect_to checkout_state_path(@order.checkout_steps.first)
|
19
20
|
else
|
20
21
|
redirect_to cart_path
|
@@ -4,37 +4,37 @@ Spree::StoreController.class_eval do
|
|
4
4
|
def apply_coupon_code
|
5
5
|
if @order.coupon_code.present?
|
6
6
|
# check if coupon code is already applied
|
7
|
-
if @order.
|
7
|
+
if @order.coupon_code_applied?
|
8
8
|
flash[:notice] = t(:coupon_code_already_applied)
|
9
9
|
true
|
10
10
|
else
|
11
11
|
event_name = "spree.checkout.coupon_code_added"
|
12
12
|
|
13
13
|
# TODO should restrict to payload's event name?
|
14
|
-
|
14
|
+
current_promotion = @order.find_promo_for_coupon_code
|
15
15
|
|
16
|
-
if
|
17
|
-
if
|
16
|
+
if current_promotion.present?
|
17
|
+
if current_promotion.expired?
|
18
18
|
flash[:error] = t(:coupon_code_expired)
|
19
19
|
return false
|
20
20
|
end
|
21
21
|
|
22
|
-
if
|
22
|
+
if current_promotion.usage_limit_exceeded?
|
23
23
|
flash[:error] = t(:coupon_code_max_usage)
|
24
24
|
return false
|
25
25
|
end
|
26
26
|
|
27
27
|
previous_promo = @order.adjustments.promotion.eligible.first
|
28
|
-
|
29
|
-
|
28
|
+
current_promotion.activate(:order => @order, :coupon_code => @order.coupon_code)
|
29
|
+
promo_adjustment = @order.find_adjustment_for_coupon_code
|
30
30
|
|
31
|
-
if
|
31
|
+
if promo_adjustment.present? and promo_adjustment.eligible
|
32
32
|
flash[:success] = t(:coupon_code_applied)
|
33
33
|
true
|
34
|
-
elsif previous_promo.present? and
|
34
|
+
elsif previous_promo.present? and promo_adjustment.present?
|
35
35
|
flash[:error] = t(:coupon_code_better_exists)
|
36
36
|
false
|
37
|
-
elsif
|
37
|
+
elsif promo_adjustment.present?
|
38
38
|
flash[:error] = t(:coupon_code_not_eligible)
|
39
39
|
false
|
40
40
|
else
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Spree
|
2
2
|
|
3
3
|
# A calculator for promotions that calculates a percent-off discount
|
4
|
-
# for all matching products in an order. This should not be used as a
|
4
|
+
# for all matching products in an order. This should not be used as a
|
5
5
|
# shipping calculator since it would be the same thing as a flat percent
|
6
6
|
# off the entire order.
|
7
|
-
|
7
|
+
|
8
8
|
class Calculator::PercentPerItem < Calculator
|
9
9
|
preference :percent, :decimal, :default => 0
|
10
10
|
|
@@ -23,10 +23,12 @@ module Spree
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
-
# Returns all products that match the promotion's rule.
|
26
|
+
# Returns all products that match the promotion's rule.
|
27
27
|
def matching_products
|
28
|
-
|
29
|
-
self.calculable.promotion.rules.map
|
28
|
+
if compute_on_promotion?
|
29
|
+
self.calculable.promotion.rules.map do |rule|
|
30
|
+
rule.respond_to?(:products) ? rule.products : []
|
31
|
+
end.flatten
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -1,10 +1,7 @@
|
|
1
1
|
Spree::Order.class_eval do
|
2
|
-
attr_accessible :coupon_code
|
3
|
-
attr_reader :coupon_code
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
attr_accessible :coupon_code
|
4
|
+
attr_accessor :coupon_code
|
8
5
|
|
9
6
|
# Tells us if there if the specified promotion is already associated with the order
|
10
7
|
# regardless of whether or not its currently eligible. Useful because generally
|
@@ -16,4 +13,24 @@ Spree::Order.class_eval do
|
|
16
13
|
def promo_total
|
17
14
|
adjustments.eligible.promotion.pluck(:amount).sum
|
18
15
|
end
|
16
|
+
|
17
|
+
def coupon_code_applied?
|
18
|
+
adjustments.promotion.eligible.detect do |p|
|
19
|
+
Spree::Promotion.normalize_coupon_code(p.originator.promotion.code) == normalized_coupon_code
|
20
|
+
end.present?
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_adjustment_for_coupon_code
|
24
|
+
adjustments.promotion.detect do |p|
|
25
|
+
Spree::Promotion.normalize_coupon_code(p.originator.promotion.code) == normalized_coupon_code
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_promo_for_coupon_code
|
30
|
+
Spree::Promotion.where("LOWER(code) = '#{normalized_coupon_code}'").first
|
31
|
+
end
|
32
|
+
|
33
|
+
def normalized_coupon_code
|
34
|
+
Spree::Promotion.normalize_coupon_code(coupon_code)
|
35
|
+
end
|
19
36
|
end
|
@@ -45,8 +45,9 @@ module Spree
|
|
45
45
|
return unless order_activatable? payload[:order]
|
46
46
|
|
47
47
|
if code.present?
|
48
|
-
|
49
|
-
|
48
|
+
normalized_submitted_code = Spree::Promotion.normalize_coupon_code(payload[:coupon_code])
|
49
|
+
normalized_expected_code = Spree::Promotion.normalize_coupon_code(self.code)
|
50
|
+
return unless normalized_submitted_code == normalized_expected_code
|
50
51
|
end
|
51
52
|
|
52
53
|
if path.present?
|
@@ -102,8 +103,10 @@ module Spree
|
|
102
103
|
credits.count
|
103
104
|
end
|
104
105
|
|
105
|
-
|
106
|
-
|
106
|
+
private
|
107
|
+
|
108
|
+
def self.normalize_coupon_code(code)
|
109
|
+
code.to_s.strip.downcase rescue ""
|
107
110
|
end
|
108
111
|
end
|
109
112
|
end
|
@@ -6,9 +6,11 @@ module Spree
|
|
6
6
|
accepts_nested_attributes_for :promotion_action_line_items
|
7
7
|
attr_accessible :promotion_action_line_items_attributes
|
8
8
|
|
9
|
+
delegate :eligible?, :to => :promotion
|
9
10
|
|
10
11
|
def perform(options = {})
|
11
12
|
return unless order = options[:order]
|
13
|
+
return unless eligible?(order)
|
12
14
|
promotion_action_line_items.each do |item|
|
13
15
|
current_quantity = order.quantity_of(item.variant)
|
14
16
|
if current_quantity < item.quantity
|
@@ -3,4 +3,4 @@ Deface::Override.new(:virtual_path => "spree/layouts/admin",
|
|
3
3
|
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
|
4
4
|
:text => "<%= tab(:promotions, :url => spree.admin_promotions_path, :icon => 'icon-bullhorn') %>",
|
5
5
|
:disabled => false,
|
6
|
-
:original => '
|
6
|
+
:original => '031652cf5a054796022506622082ab6d2693699f')
|
@@ -6,6 +6,7 @@
|
|
6
6
|
<% param_prefix = "promotion[promotion_actions_attributes][#{promotion_action.id}]" %>
|
7
7
|
<%= hidden_field_tag "#{param_prefix}[id]", promotion_action.id %>
|
8
8
|
|
9
|
+
<%= render :partial => "spree/shared/error_messages", :locals => { :target => promotion_action } %>
|
9
10
|
<%= render :partial => "spree/admin/promotions/actions/#{type_name}",
|
10
11
|
:locals => { :promotion_action => promotion_action, :param_prefix => param_prefix } %>
|
11
|
-
</div>
|
12
|
+
</div>
|
@@ -5,5 +5,6 @@
|
|
5
5
|
|
6
6
|
<% param_prefix = "promotion[promotion_rules_attributes][#{promotion_rule.id}]" %>
|
7
7
|
<%= hidden_field_tag "#{param_prefix}[id]", promotion_rule.id %>
|
8
|
+
<%= render :partial => "spree/shared/error_messages", :locals => { :target => promotion_rule } %>
|
8
9
|
<%= render :partial => "spree/admin/promotions/rules/#{type_name}", :locals => { :promotion_rule => promotion_rule, :param_prefix => param_prefix } %>
|
9
10
|
</div>
|
data/config/locales/en.yml
CHANGED
@@ -16,12 +16,12 @@ en:
|
|
16
16
|
add_rule_of_type: Add rule of type
|
17
17
|
back_to_promotions_list: "Back To Promotions List"
|
18
18
|
coupon: Coupon
|
19
|
-
coupon_code: Coupon code
|
19
|
+
coupon_code: Coupon code (NOT case sensitive)
|
20
20
|
coupon_code_applied: The coupon code was successfully applied to your order.
|
21
21
|
coupon_code_expired: The coupon code is expired
|
22
22
|
coupon_code_already_applied: The coupon code has already been applied to this order
|
23
23
|
coupon_code_better_exists: The previously applied coupon code results in a better deal
|
24
|
-
coupon_code_not_found: The coupon code you entered doesn't exist. Please try again.
|
24
|
+
coupon_code_not_found: The coupon code you entered doesn't exist. Please try again. Coupon codes are not case sensitive.
|
25
25
|
coupon_code_max_usage: Coupon code usage limit exceeded
|
26
26
|
coupon_code_not_eligible: This coupon code is not eligible for this order
|
27
27
|
editing_promotion: Editing Promotion
|
metadata
CHANGED
@@ -1,32 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_promo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
5
|
-
prerelease:
|
4
|
+
version: 1.3.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- David North
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-10-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: spree_core
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - '='
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.3.
|
19
|
+
version: 1.3.4
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - '='
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.3.
|
26
|
+
version: 1.3.4
|
30
27
|
description: Required dependency for Spree
|
31
28
|
email: david@spreecommerce.com
|
32
29
|
executables: []
|
@@ -105,30 +102,26 @@ files:
|
|
105
102
|
homepage: http://spreecommerce.com
|
106
103
|
licenses:
|
107
104
|
- BSD-3
|
105
|
+
metadata: {}
|
108
106
|
post_install_message:
|
109
107
|
rdoc_options: []
|
110
108
|
require_paths:
|
111
109
|
- lib
|
112
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
111
|
requirements:
|
115
|
-
- -
|
112
|
+
- - '>='
|
116
113
|
- !ruby/object:Gem::Version
|
117
114
|
version: 1.8.7
|
118
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
-
none: false
|
120
116
|
requirements:
|
121
|
-
- -
|
117
|
+
- - '>='
|
122
118
|
- !ruby/object:Gem::Version
|
123
119
|
version: '0'
|
124
|
-
segments:
|
125
|
-
- 0
|
126
|
-
hash: -2378760462746062854
|
127
120
|
requirements:
|
128
121
|
- none
|
129
122
|
rubyforge_project:
|
130
|
-
rubygems_version: 1.
|
123
|
+
rubygems_version: 2.1.0
|
131
124
|
signing_key:
|
132
|
-
specification_version:
|
125
|
+
specification_version: 4
|
133
126
|
summary: Promotion functionality for use with Spree.
|
134
127
|
test_files: []
|