Class: PromotionCredit
- Inherits:
-
Adjustment
- Object
- Adjustment
- PromotionCredit
- Defined in:
- app/models/promotion_credit.rb
Instance Method Summary collapse
-
#applicable? ⇒ Boolean
Checks if credit is still applicable to order If source of adjustment is credit, it checks if it’s still valid.
- #calculate_adjustment ⇒ Object
-
#calculate_coupon_credit ⇒ Object
Calculates credit for the coupon.
- #total ⇒ Object
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
10 11 12 |
# File 'app/models/promotion_credit.rb', line 10 def applicable? adjustment_source && adjustment_source.eligible?(order) && super end |
#calculate_adjustment ⇒ Object
4 5 6 |
# File 'app/models/promotion_credit.rb', line 4 def calculate_adjustment adjustment_source && calculate_coupon_credit end |
#calculate_coupon_credit ⇒ Object
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 |
#total ⇒ Object
26 27 28 |
# File 'app/models/promotion_credit.rb', line 26 def total map(&:amount).sum end |