Class: SolidusFriendlyPromotions::Calculators::TieredPercent
- Inherits:
-
Spree::Calculator
- Object
- Spree::Calculator
- SolidusFriendlyPromotions::Calculators::TieredPercent
show all
- Includes:
- PromotionCalculator
- Defined in:
- app/models/solidus_friendly_promotions/calculators/tiered_percent.rb
Instance Method Summary
collapse
#description
Instance Method Details
#compute_item(object) ⇒ Object
Also known as:
compute_shipment, compute_line_item
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'app/models/solidus_friendly_promotions/calculators/tiered_percent.rb', line 29
def compute_item(object)
order = object.order
_base, percent = preferred_tiers.sort.reverse.detect do |value, _|
order.item_total >= value
end
if preferred_currency.casecmp(order.currency).zero?
currency_exponent = ::Money::Currency.find(preferred_currency).exponent
(object.amount * (percent || preferred_base_percent) / 100).round(currency_exponent)
else
0
end
end
|