Class: PromotionCredit

Inherits:
Adjustment
  • Object
show all
Defined in:
app/models/promotion_credit.rb

Instance Method Summary collapse

Instance Method Details

#applicable?Boolean

Checks if credit is still applicable to order If source of adjustment is credit, it checks if it’s still valid

Returns:

  • (Boolean)


10
11
12
# File 'app/models/promotion_credit.rb', line 10

def applicable?
  adjustment_source && adjustment_source.eligible?(order) && super
end

#calculate_adjustmentObject



4
5
6
# File 'app/models/promotion_credit.rb', line 4

def calculate_adjustment
  adjustment_source && calculate_coupon_credit
end

#calculate_coupon_creditObject

Calculates credit for the coupon.

If coupon amount exceeds the order item_total, credit is adjusted.

Always returns negative non positive.



19
20
21
22
23
24
# File 'app/models/promotion_credit.rb', line 19

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

#totalObject



26
27
28
# File 'app/models/promotion_credit.rb', line 26

def total
  map(&:amount).sum
end