Sha256: 889c776439200f72ca1c81d7ad5521cc71398273057fece61159fcb2fc17f2d5
Contents?: true
Size: 820 Bytes
Versions: 12
Compression:
Stored size: 820 Bytes
Contents
class PromotionCredit < ::Adjustment scope :with_order, :conditions => "order_id IS NOT NULL" def calculate_adjustment adjustment_source && calculate_coupon_credit end # Checks if credit is still applicable to order # If source of adjustment is credit, it checks if it's still valid def applicable? adjustment_source && adjustment_source.eligible?(order) && super end # Calculates credit for the coupon. # # If coupon amount exceeds the order item_total, credit is adjusted. # # Always returns negative non positive. def calculate_coupon_credit return 0 if order.line_items.empty? amount = adjustment_source.calculator.compute(order.line_items).abs amount = order.item_total if amount > order.item_total -1 * amount end def total map(&:amount).sum end end
Version data entries
12 entries across 12 versions & 2 rubygems