spree_promo 0.30.2 → 0.40.0

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.
@@ -5,7 +5,7 @@ class Calculator::FreeShipping < ::Calculator
5
5
  end
6
6
 
7
7
  def self.register
8
- super
8
+ super
9
9
  Promotion.register_calculator(self)
10
10
  end
11
11
 
@@ -6,14 +6,13 @@ class Promotion < ActiveRecord::Base
6
6
  has_many :promotion_rules
7
7
  accepts_nested_attributes_for :promotion_rules
8
8
  alias_method :rules, :promotion_rules
9
-
9
+
10
10
  validates :name, :code, :presence => true
11
11
 
12
12
  MATCH_POLICIES = %w(all any)
13
13
 
14
14
  scope :automatic, where("code IS NULL OR code = ''")
15
15
 
16
-
17
16
  def eligible?(order)
18
17
  !expired? && rules_are_eligible?(order)
19
18
  end
@@ -21,7 +20,11 @@ class Promotion < ActiveRecord::Base
21
20
  def expired?
22
21
  starts_at && Time.now < starts_at ||
23
22
  expires_at && Time.now > expires_at ||
24
- usage_limit && promotion_credits.with_order.count >= usage_limit
23
+ usage_limit && credits_count >= usage_limit
24
+ end
25
+
26
+ def credits_count
27
+ credits.with_order.count
25
28
  end
26
29
 
27
30
  def rules_are_eligible?(order)
@@ -34,7 +37,7 @@ class Promotion < ActiveRecord::Base
34
37
  end
35
38
 
36
39
  def create_discount(order)
37
- return if order.promotion_credits.reload.detect { |credit| credit.source_id == self.id }
40
+ return if order.promotion_credit_exists?(self)
38
41
  if eligible?(order) and amount = calculator.compute(order)
39
42
  amount = order.item_total if amount > order.item_total
40
43
  order.promotion_credits.reload.clear unless combine? and order.promotion_credits.all? { |credit| credit.source.combine? }
@@ -4,4 +4,4 @@ class Promotion::Rules::FirstOrder < PromotionRule
4
4
  order.user && order.user.orders.checkout_complete.count == 0
5
5
  end
6
6
 
7
- end
7
+ end
@@ -3,12 +3,11 @@ class Promotion::Rules::ItemTotal < PromotionRule
3
3
 
4
4
  preference :amount, :decimal, :default => 100.00
5
5
  preference :operator, :string, :default => '>'
6
-
6
+
7
7
  OPERATORS = ['gt', 'gte']
8
-
9
-
8
+
10
9
  def eligible?(order)
11
10
  order.item_total.send(preferred_operator == 'gte' ? :>= : :>, preferred_amount)
12
11
  end
13
12
 
14
- end
13
+ end
@@ -16,11 +16,10 @@ class Promotion::Rules::Product < PromotionRule
16
16
 
17
17
  def eligible?(order)
18
18
  return true if eligible_products.empty?
19
- order_products = order.line_items.map{|li| li.variant.product}
20
19
  if preferred_match_policy == 'all'
21
- eligible_products.all? {|p| order_products.include?(p) }
20
+ eligible_products.all? {|p| order.products.include?(p) }
22
21
  else
23
- order_products.any? {|p| eligible_products.include?(p) }
22
+ order.products.any? {|p| eligible_products.include?(p) }
24
23
  end
25
24
  end
26
25
 
@@ -38,4 +37,4 @@ class Promotion::Rules::Product < PromotionRule
38
37
  self.product_ids = s.to_s.split(',').map(&:strip)
39
38
  end
40
39
 
41
- end
40
+ end
@@ -1,12 +1,11 @@
1
1
  class Promotion::Rules::User < PromotionRule
2
2
  belongs_to :user
3
3
  has_and_belongs_to_many :users, :class_name => '::User', :join_table => 'promotion_rules_users', :foreign_key => 'promotion_rule_id'
4
-
4
+
5
5
  def eligible?(order)
6
6
  users.none? or users.include?(order.user)
7
7
  end
8
8
 
9
-
10
9
  def user_ids_string
11
10
  user_ids.join(',')
12
11
  end
@@ -15,4 +14,4 @@ class Promotion::Rules::User < PromotionRule
15
14
  self.user_ids = s.to_s.split(',').map(&:strip)
16
15
  end
17
16
 
18
- end
17
+ end
data/lib/spree_promo.rb CHANGED
@@ -28,6 +28,10 @@ module SpreePromo
28
28
  attr_accessor :coupon_code
29
29
  before_save :process_coupon_code, :if => "@coupon_code"
30
30
 
31
+ def promotion_credit_exists?(credit)
32
+ promotion_credits.reload.detect { |c| c.source_id == credit.id }
33
+ end
34
+
31
35
  def process_coupon_code
32
36
  coupon = Promotion.find(:first, :conditions => ["UPPER(code) = ?", @coupon_code.upcase])
33
37
  if coupon
@@ -11,7 +11,6 @@ namespace :spree_promo do
11
11
  task :migrations do
12
12
  source = File.join(File.dirname(__FILE__), '..', '..', 'db')
13
13
  destination = File.join(Rails.root, 'db')
14
- puts "INFO: Mirroring assets from #{source} to #{destination}"
15
14
  Spree::FileUtilz.mirror_files(source, destination)
16
15
  end
17
16
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_promo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 99
5
- prerelease:
4
+ hash: 191
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 30
9
- - 2
10
- version: 0.30.2
8
+ - 40
9
+ - 0
10
+ version: 0.40.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David North
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-23 00:00:00 Z
18
+ date: 2010-12-22 00:00:00 -05:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: spree_core
@@ -25,12 +26,12 @@ dependencies:
25
26
  requirements:
26
27
  - - "="
27
28
  - !ruby/object:Gem::Version
28
- hash: 99
29
+ hash: 191
29
30
  segments:
30
31
  - 0
31
- - 30
32
- - 2
33
- version: 0.30.2
32
+ - 40
33
+ - 0
34
+ version: 0.40.0
34
35
  type: :runtime
35
36
  version_requirements: *id001
36
37
  description: Required dependancy for Spree
@@ -81,6 +82,7 @@ files:
81
82
  - db/migrate/20100923095305_update_calculable_type_for_promotions.rb
82
83
  - public/javascripts/admin/promotions.js
83
84
  - public/stylesheets/admin/promotions.css
85
+ has_rdoc: true
84
86
  homepage: http://spreecommerce.com
85
87
  licenses: []
86
88
 
@@ -112,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
114
  requirements:
113
115
  - none
114
116
  rubyforge_project: spree_promo
115
- rubygems_version: 1.8.10
117
+ rubygems_version: 1.3.7
116
118
  signing_key:
117
119
  specification_version: 3
118
120
  summary: Promotion functionality for use with Spree.