Sha256: 95612ab7b2a48505e1e3f02312b1268f03cb9d2dc7790dd4a14bcd0034bc4d31
Contents?: true
Size: 1.32 KB
Versions: 36
Compression:
Stored size: 1.32 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 :currency, :string, default: ->{ Spree::Config[:currency] } preference :operator, :string, default: '>' OPERATORS = ['gt', 'gte'] def applicable?(promotable) promotable.is_a?(Spree::Order) end def eligible?(order, _options = {}) return false unless order.currency == preferred_currency 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, currency: preferred_currency).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
36 entries across 36 versions & 1 rubygems