spree_promo 1.3.2 → 1.3.3
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/assets/javascripts/admin/product_picker.js +25 -23
- data/app/assets/javascripts/admin/promotions.js +2 -2
- data/app/assets/javascripts/admin/user_picker.js +25 -23
- data/app/controllers/spree/orders_controller_decorator.rb +5 -0
- data/app/models/spree/calculator/percent_per_item.rb +1 -1
- data/app/models/spree/promotion.rb +4 -0
- data/app/models/spree/promotion/rules/first_order.rb +17 -10
- data/app/models/spree/promotion/rules/user.rb +1 -1
- data/app/models/spree/promotion/rules/user_logged_in.rb +1 -8
- data/app/overrides/promo_cart_coupon_code_field.rb +1 -1
- data/app/views/spree/checkout/_coupon_code_field.html.erb +1 -1
- data/app/views/spree/orders/_coupon_code_field.html.erb +2 -5
- data/config/routes.rb +1 -1
- metadata +5 -5
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
$.fn.productAutocomplete = function() {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
ajax: {
|
|
11
|
-
url: Spree.routes.product_search,
|
|
12
|
-
datatype: 'json',
|
|
13
|
-
data: function(term, page) {
|
|
14
|
-
return { q: term }
|
|
2
|
+
if (Spree.routes) {
|
|
3
|
+
this.select2({
|
|
4
|
+
minimumInputLength: 1,
|
|
5
|
+
multiple: true,
|
|
6
|
+
initSelection: function(element, callback) {
|
|
7
|
+
$.get(Spree.routes.product_search, { ids: element.val() }, function(data) {
|
|
8
|
+
callback(data)
|
|
9
|
+
})
|
|
15
10
|
},
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
ajax: {
|
|
12
|
+
url: Spree.routes.product_search,
|
|
13
|
+
datatype: 'json',
|
|
14
|
+
data: function(term, page) {
|
|
15
|
+
return { q: term }
|
|
16
|
+
},
|
|
17
|
+
results: function(data, page) {
|
|
18
|
+
return { results: data }
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
formatResult: function(product) {
|
|
22
|
+
return product.name;
|
|
23
|
+
},
|
|
24
|
+
formatSelection: function(product) {
|
|
25
|
+
return product.name;
|
|
18
26
|
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return product.name;
|
|
22
|
-
},
|
|
23
|
-
formatSelection: function(product) {
|
|
24
|
-
return product.name;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
$(document).ready(function () {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var initProductActions = function(){
|
|
2
2
|
|
|
3
3
|
// Add classes on promotion items for design
|
|
4
|
-
$(
|
|
4
|
+
$(document).on('mouseover mouseout', 'a.delete', function(event) {
|
|
5
5
|
if (event.type == 'mouseover') {
|
|
6
6
|
$(this).parent().addClass('action-remove');
|
|
7
7
|
} else {
|
|
@@ -9,7 +9,7 @@ var initProductActions = function(){
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
$(".variant_autocomplete").variantAutocomplete();
|
|
12
|
+
$('#promotion-filters').find(".variant_autocomplete").variantAutocomplete();
|
|
13
13
|
|
|
14
14
|
$('.calculator-fields').each(function(){
|
|
15
15
|
var $fields_container = $(this);
|
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
$.fn.userAutocomplete = function() {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
ajax: {
|
|
11
|
-
url: Spree.routes.user_search,
|
|
12
|
-
datatype: 'json',
|
|
13
|
-
data: function(term, page) {
|
|
14
|
-
return { q: term }
|
|
2
|
+
if (Spree.routes) {
|
|
3
|
+
this.select2({
|
|
4
|
+
minimumInputLength: 1,
|
|
5
|
+
multiple: true,
|
|
6
|
+
initSelection: function(element, callback) {
|
|
7
|
+
$.get(Spree.routes.user_search, { ids: element.val() }, function(data) {
|
|
8
|
+
callback(data)
|
|
9
|
+
})
|
|
15
10
|
},
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
ajax: {
|
|
12
|
+
url: Spree.routes.user_search,
|
|
13
|
+
datatype: 'json',
|
|
14
|
+
data: function(term, page) {
|
|
15
|
+
return { q: term }
|
|
16
|
+
},
|
|
17
|
+
results: function(data, page) {
|
|
18
|
+
return { results: data }
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
formatResult: function(user) {
|
|
22
|
+
return user.email;
|
|
23
|
+
},
|
|
24
|
+
formatSelection: function(user) {
|
|
25
|
+
return user.email;
|
|
18
26
|
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return user.email;
|
|
22
|
-
},
|
|
23
|
-
formatSelection: function(user) {
|
|
24
|
-
return user.email;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
$(document).ready(function () {
|
|
@@ -2,6 +2,11 @@ Spree::OrdersController.class_eval do
|
|
|
2
2
|
|
|
3
3
|
def update
|
|
4
4
|
@order = current_order
|
|
5
|
+
unless @order
|
|
6
|
+
flash[:error] = t(:order_not_found)
|
|
7
|
+
redirect_to root_path and return
|
|
8
|
+
end
|
|
9
|
+
|
|
5
10
|
if @order.update_attributes(params[:order])
|
|
6
11
|
render :edit and return unless apply_coupon_code
|
|
7
12
|
|
|
@@ -34,7 +34,7 @@ module Spree
|
|
|
34
34
|
# unless the product is included in the promotion rules.
|
|
35
35
|
def value_for_line_item(line_item)
|
|
36
36
|
if compute_on_promotion?
|
|
37
|
-
return 0 unless matching_products.include?(line_item.product)
|
|
37
|
+
return 0 unless matching_products.blank? or matching_products.include?(line_item.product)
|
|
38
38
|
end
|
|
39
39
|
line_item.price * line_item.quantity * preferred_percent
|
|
40
40
|
end
|
|
@@ -2,20 +2,27 @@ module Spree
|
|
|
2
2
|
class Promotion
|
|
3
3
|
module Rules
|
|
4
4
|
class FirstOrder < PromotionRule
|
|
5
|
+
attr_reader :user, :email
|
|
6
|
+
|
|
5
7
|
def eligible?(order, options = {})
|
|
6
|
-
user = order.try(:user) || options[:user]
|
|
7
|
-
|
|
8
|
-
return orders_by_email(user.email) == 0
|
|
9
|
-
elsif order.email
|
|
10
|
-
return orders_by_email(order.email) == 0
|
|
11
|
-
end
|
|
8
|
+
@user = order.try(:user) || options[:user]
|
|
9
|
+
@email = order.email
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
if user || email
|
|
12
|
+
completed_orders.blank? || (completed_orders.first == order)
|
|
13
|
+
else
|
|
14
|
+
false
|
|
15
|
+
end
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
private
|
|
19
|
+
def completed_orders
|
|
20
|
+
user ? user.orders.complete : orders_by_email
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def orders_by_email
|
|
24
|
+
Spree::Order.where(:email => email).complete
|
|
25
|
+
end
|
|
19
26
|
end
|
|
20
27
|
end
|
|
21
28
|
end
|
|
@@ -8,7 +8,7 @@ module Spree
|
|
|
8
8
|
has_and_belongs_to_many :users, :class_name => Spree.user_class.to_s, :join_table => 'spree_promotion_rules_users', :foreign_key => 'promotion_rule_id'
|
|
9
9
|
|
|
10
10
|
def eligible?(order, options = {})
|
|
11
|
-
users.
|
|
11
|
+
users.include?(order.user)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def user_ids_string
|
|
@@ -4,14 +4,7 @@ module Spree
|
|
|
4
4
|
class UserLoggedIn < PromotionRule
|
|
5
5
|
|
|
6
6
|
def eligible?(order, options = {})
|
|
7
|
-
|
|
8
|
-
# we need to rely on the controller already having done this for us.
|
|
9
|
-
|
|
10
|
-
# The thinking is that the controller should have some sense of what state
|
|
11
|
-
# we should be in before firing events,
|
|
12
|
-
# so the controller will have to set this field.
|
|
13
|
-
|
|
14
|
-
return options && options[:user_signed_in]
|
|
7
|
+
return order.try(:user).try(:anonymous?) == false
|
|
15
8
|
end
|
|
16
9
|
|
|
17
10
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Deface::Override.new(:virtual_path => "spree/orders/edit",
|
|
2
2
|
:name => "promo_cart_coupon_code_field",
|
|
3
|
-
:
|
|
3
|
+
:insert_top => "[data-hook='cart_buttons']",
|
|
4
4
|
:partial => "spree/orders/coupon_code_field",
|
|
5
5
|
:disabled => false,
|
|
6
6
|
:original => "c11d9a1996fb86e992aba19035074cf5f688dea2")
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
<% if Spree::Promotion.count > 0 %>
|
|
2
|
-
|
|
3
|
-
<%= order_form.label :coupon_code %><br />
|
|
4
|
-
<%= order_form.text_field :coupon_code, :size => 10 %>
|
|
1
|
+
<% if Spree::Promotion.with_code.count > 0 %>
|
|
2
|
+
<%= order_form.text_field :coupon_code, :size => 10, :placeholder => I18n.t(:coupon_code) %>
|
|
5
3
|
<%= order_form.submit I18n.t(:apply) %>
|
|
6
|
-
</div>
|
|
7
4
|
<% end %>
|
data/config/routes.rb
CHANGED
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.3
|
|
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-06-13 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.3
|
|
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.3
|
|
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: -2378760462746062854
|
|
127
127
|
requirements:
|
|
128
128
|
- none
|
|
129
129
|
rubyforge_project:
|