Class: PiggybakBundleDiscounts::BundleDiscount
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PiggybakBundleDiscounts::BundleDiscount
- Defined in:
- app/models/piggybak_bundle_discounts/bundle_discount.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.applicable_bundle_discounts(sellables) ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/models/piggybak_bundle_discounts/bundle_discount.rb', line 25 def self.applicable_bundle_discounts(sellables) # Selecting applicable bundle discounts bundle_discounts = self.active.select { |bd| bd.sellables_match_bundle_discount?(sellables) } # Returning max bundle discount bundle_discounts.present? ? bundle_discounts.sort_by(&:discount).last : nil end |
Instance Method Details
#sellables_match_bundle_discount?(sellables_to_match) ⇒ Boolean
16 17 18 19 20 21 22 23 |
# File 'app/models/piggybak_bundle_discounts/bundle_discount.rb', line 16 def sellables_match_bundle_discount?(sellables_to_match) if sellables.empty? return nil else #Do the bundle's sellables match the order's sellables (sellables - sellables_to_match).empty? end end |