Class: SolidusPromotions::Calculators::Percent
- Inherits:
-
Spree::Calculator
- Object
- Spree::Calculator
- SolidusPromotions::Calculators::Percent
- Includes:
- PromotionCalculator
- Defined in:
- app/models/solidus_promotions/calculators/percent.rb
Overview
A calculator that applies a percentage-based discount.
This calculator computes the discount as a percentage of the item’s discountable amount, rounded to the appropriate currency precision.
Instance Method Summary collapse
-
#compute_item(object, _options = {}) ⇒ BigDecimal
(also: #compute_line_item, #compute_shipment, #compute_shipping_rate, #compute_price)
Computes the percentage-based discount for an item.
Methods included from PromotionCalculator
Instance Method Details
#compute_item(object, _options = {}) ⇒ BigDecimal Also known as: compute_line_item, compute_shipment, compute_shipping_rate, compute_price
Computes the percentage-based discount for an item.
Calculates the discount by applying the preferred percentage to the item’s discountable amount, then rounds the result to the appropriate precision for the order’s currency.
45 46 47 48 |
# File 'app/models/solidus_promotions/calculators/percent.rb', line 45 def compute_item(object, = {}) currency = object.respond_to?(:currency) ? object.currency : object.order.currency round_to_currency(object.discountable_amount * preferred_percent / 100, currency) end |