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

Version Path
spree_promo-0.50.4 app/models/promotion_credit.rb
spree_promo-0.60.4 app/models/promotion_credit.rb
spree_promo-0.50.3 app/models/promotion_credit.rb
spree_promo-0.60.3 app/models/promotion_credit.rb
spree_promo-0.60.2 app/models/promotion_credit.rb
spree_bushido_promo-0.80.28 app/models/promotion_credit.rb
spree_bushido_promo-0.80.27 app/models/promotion_credit.rb
spree_promo-0.60.1 app/models/promotion_credit.rb
spree_promo-0.60.0 app/models/promotion_credit.rb
spree_promo-0.60.0.RC1 app/models/promotion_credit.rb
spree_promo-0.50.2 app/models/promotion_credit.rb
spree_promo-0.50.1 app/models/promotion_credit.rb