Module: Spree::Order::LoyaltyPoints
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/spree/order/loyalty_points.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #award_loyalty_points ⇒ Object
- #create_credit_transaction(points) ⇒ Object
- #create_debit_transaction(points) ⇒ Object
- #loyalty_points_awarded? ⇒ Boolean
- #loyalty_points_total ⇒ Object
- #loyalty_points_used? ⇒ Boolean
Instance Method Details
#award_loyalty_points ⇒ Object
12 13 14 15 16 17 |
# File 'app/models/concerns/spree/order/loyalty_points.rb', line 12 def award_loyalty_points loyalty_points_earned = loyalty_points_for(item_total) if !loyalty_points_used? create_credit_transaction(loyalty_points_earned) end end |
#create_credit_transaction(points) ⇒ Object
39 40 41 |
# File 'app/models/concerns/spree/order/loyalty_points.rb', line 39 def create_credit_transaction(points) user.loyalty_points_credit_transactions.create(source: self, loyalty_points: points) end |
#create_debit_transaction(points) ⇒ Object
43 44 45 |
# File 'app/models/concerns/spree/order/loyalty_points.rb', line 43 def create_debit_transaction(points) user.loyalty_points_debit_transactions.create(source: self, loyalty_points: points) end |
#loyalty_points_awarded? ⇒ Boolean
19 20 21 |
# File 'app/models/concerns/spree/order/loyalty_points.rb', line 19 def loyalty_points_awarded? loyalty_points_credit_transactions.count > 0 end |
#loyalty_points_total ⇒ Object
8 9 10 |
# File 'app/models/concerns/spree/order/loyalty_points.rb', line 8 def loyalty_points_total loyalty_points_credit_transactions.sum(:loyalty_points) - loyalty_points_debit_transactions.sum(:loyalty_points) end |
#loyalty_points_used? ⇒ Boolean
23 24 25 |
# File 'app/models/concerns/spree/order/loyalty_points.rb', line 23 def loyalty_points_used? payments.any_with_loyalty_points? end |