Sha256: 3f8ef86bed8a86da8177b52ea5bc08088efef04d0cca5c9cdc1e98fbc3b16add
Contents?: true
Size: 1.15 KB
Versions: 27
Compression:
Stored size: 1.15 KB
Contents
module Spree class Promotion module Rules # A rule to apply to an order greater than (or greater than or equal to) # a specific amount class ItemTotal < PromotionRule preference :amount, :decimal, default: 100.00 preference :operator, :string, default: '>' OPERATORS = ['gt', 'gte'] def applicable?(promotable) promotable.is_a?(Spree::Order) end def eligible?(order, options = {}) item_total = order.item_total unless item_total.send(preferred_operator == 'gte' ? :>= : :>, BigDecimal.new(preferred_amount.to_s)) eligibility_errors.add(:base, ineligible_message) end eligibility_errors.empty? end private def formatted_amount Spree::Money.new(preferred_amount).to_s end def ineligible_message if preferred_operator == 'gte' eligibility_error_message(:item_total_less_than, amount: formatted_amount) else eligibility_error_message(:item_total_less_than_or_equal, amount: formatted_amount) end end end end end end
Version data entries
27 entries across 27 versions & 1 rubygems