spree_payment_calculator 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -9,7 +9,7 @@ Basic Installation
9
9
 
10
10
  1. Add the following to your Gemfile
11
11
  <pre>
12
- gem 'spree_payment_calculator', '~> 1.0.1'
12
+ gem 'spree_payment_calculator', '~> 1.1.0'
13
13
  </pre>
14
14
  2. Run `bundle install`
15
15
  3. Go to Payment Method in the Admin panel and add a calculator for each type of payment you prefer
@@ -19,7 +19,7 @@ module Spree
19
19
  private
20
20
 
21
21
  def rate
22
- rate = self.calculable
22
+ self.calculable
23
23
  end
24
24
 
25
25
  def compute_order(order)
@@ -3,6 +3,8 @@ require_dependency 'spree/calculator'
3
3
  module Spree
4
4
  class PaymentCalculator::FlatPercentItemTotal < Calculator
5
5
  preference :flat_percent, :decimal, :default => 0
6
+
7
+ attr_accessible :preferred_flat_percent
6
8
 
7
9
  attr_accessible :preferred_flat_percent
8
10
 
@@ -3,6 +3,7 @@ require_dependency 'spree/calculator'
3
3
  module Spree
4
4
  class PaymentCalculator::FlatRate < Calculator
5
5
  preference :amount, :decimal, :default => 0
6
+ attr_accessible :preferred_amount
6
7
 
7
8
  attr_accessible :preferred_amount
8
9
 
@@ -13,7 +13,27 @@ module Spree
13
13
  def compute(object=nil)
14
14
  return 0 if object.nil?
15
15
  self.preferred_amount * object.line_items.reduce(0) do |sum, value|
16
- sum + value.quantity
16
+ if !matching_products || matching_products.include?(value.product)
17
+ value_to_add = value.quantity
18
+ else
19
+ value_to_add = 0
20
+ end
21
+ sum + value_to_add
22
+ end
23
+ end
24
+
25
+ # Returns all products that match this calculator, but only if the calculator
26
+ # is attached to a promotion. If attached to a ShippingMethod, nil is returned.
27
+ def matching_products
28
+ # Regression check for #1596
29
+ # Calculator::PerItem can be used in two cases.
30
+ # The first is in a typical promotion, providing a discount per item of a particular item
31
+ # The second is a ShippingMethod, where it applies to an entire order
32
+ #
33
+ # Shipping methods do not have promotions attached, but promotions do
34
+ # Therefore we must check for promotions
35
+ if self.calculable.respond_to?(:promotion)
36
+ self.calculable.promotion.rules.map(&:products).flatten
17
37
  end
18
38
  end
19
39
  end
@@ -1,5 +1,5 @@
1
1
  Spree::Payment.class_eval do
2
- has_one :adjustment, :as => :source
2
+ has_one :adjustment, :as => :source, :dependent => :destroy
3
3
  before_save :remove_old_adjustment
4
4
  after_save :ensure_correct_adjustment, :update_order, :if => Proc.new {|p| !p.payment_method.calculator.blank?}
5
5
 
@@ -26,6 +26,7 @@ module SpreePaymentCalculator
26
26
  end
27
27
  app.config.spree.calculators.add_class('billing_integrations')
28
28
  app.config.spree.calculators.billing_integrations = [
29
+ Spree::PaymentCalculator::DefaultTax,
29
30
  Spree::PaymentCalculator::PriceSack,
30
31
  Spree::PaymentCalculator::FlatPercentItemTotal,
31
32
  Spree::PaymentCalculator::FlatRate,
@@ -38,6 +39,7 @@ module SpreePaymentCalculator
38
39
  app.config.spree.calculators.add_class('gateways')
39
40
 
40
41
  app.config.spree.calculators.payment_methods = [
42
+ Spree::PaymentCalculator::DefaultTax,
41
43
  Spree::PaymentCalculator::PriceSack,
42
44
  Spree::PaymentCalculator::FlatPercentItemTotal,
43
45
  Spree::PaymentCalculator::FlatRate,
@@ -46,6 +48,7 @@ module SpreePaymentCalculator
46
48
  ]
47
49
 
48
50
  app.config.spree.calculators.gateways = [
51
+ Spree::PaymentCalculator::DefaultTax,
49
52
  Spree::PaymentCalculator::PriceSack,
50
53
  Spree::PaymentCalculator::FlatPercentItemTotal,
51
54
  Spree::PaymentCalculator::FlatRate,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_payment_calculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: