spree_promo 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,10 +4,13 @@ module Spree
4
4
  class CreateLineItems < PromotionAction
5
5
  has_many :promotion_action_line_items, :foreign_key => :promotion_action_id
6
6
 
7
+ delegate :eligible?, :to => :promotion
8
+
7
9
  attr_accessor :line_items_string
8
10
 
9
11
  def perform(options = {})
10
12
  return unless order = options[:order]
13
+ return unless eligible?(order)
11
14
  promotion_action_line_items.each do |item|
12
15
  current_quantity = order.quantity_of(item.variant)
13
16
  if current_quantity < item.quantity
@@ -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
- if user
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
- return false
11
+ if user || email
12
+ completed_orders.blank? || (completed_orders.first == order)
13
+ else
14
+ false
15
+ end
14
16
  end
15
17
 
16
- def orders_by_email(email)
17
- Spree::Order.where(:email => email).count
18
- end
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
@@ -4,14 +4,7 @@ module Spree
4
4
  class UserLoggedIn < PromotionRule
5
5
 
6
6
  def eligible?(order, options = {})
7
- # this is tricky. We couldn't use any of the devise methods since we aren't in the controller.
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
data/config/routes.rb CHANGED
@@ -1,4 +1,4 @@
1
- Spree::Core::Engine.routes.prepend do
1
+ Spree::Core::Engine.routes.draw do
2
2
  namespace :admin do
3
3
  resources :promotions do
4
4
  resources :promotion_rules
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
4
+ version: 1.2.5
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-02-04 00:00:00.000000000 Z
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.2.4
21
+ version: 1.2.5
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.4
29
+ version: 1.2.5
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: 4124392625263849039
135
+ hash: -1350861266024134315
136
136
  requirements:
137
137
  - none
138
138
  rubyforge_project: