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 +1 -1
- data/app/model/spree/payment_calculator/default_tax.rb +1 -1
- data/app/model/spree/payment_calculator/flat_percent_item_total.rb +2 -0
- data/app/model/spree/payment_calculator/flat_rate.rb +1 -0
- data/app/model/spree/payment_calculator/per_item.rb +21 -1
- data/app/model/spree/payment_decorator.rb +1 -1
- data/lib/spree_payment_calculator/engine.rb +3 -0
- metadata +1 -1
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
|
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
|
@@ -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
|
-
|
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,
|