Class: Spree::Calculator::PriceSack
- Inherits:
-
Spree::Calculator
- Object
- ApplicationRecord
- Base
- Spree::Calculator
- Spree::Calculator::PriceSack
- Defined in:
- app/models/spree/calculator/price_sack.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#compute(object) ⇒ Object
as object we always get line items, as calculable we have Coupon, ShippingMethod.
Methods inherited from Spree::Calculator
#available?, calculators, #description, #to_s
Methods inherited from Base
belongs_to_required_by_default, page, spree_base_scopes
Methods included from Preferences::Preferable
#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Class Method Details
.description ⇒ Object
10 11 12 |
# File 'app/models/spree/calculator/price_sack.rb', line 10 def self.description Spree.t(:price_sack) end |
Instance Method Details
#compute(object) ⇒ Object
as object we always get line items, as calculable we have Coupon, ShippingMethod
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/spree/calculator/price_sack.rb', line 15 def compute(object) base = if object.is_a?(Array) object.map { |o| o.respond_to?(:amount) ? o.amount : BigDecimal(o.to_s) }.sum else object.respond_to?(:amount) ? object.amount : BigDecimal(object.to_s) end if base < preferred_minimal_amount preferred_normal_amount else preferred_discount_amount end end |