Module: Spree::Order::StoreCredit
- Included in:
- Spree::Order
- Defined in:
- app/models/spree/order/store_credit.rb
Instance Method Summary collapse
- #add_store_credit_payments(amount = nil) ⇒ Object
-
#available_store_credits ⇒ Array<Spree::StoreCredit>
Returns the available store credits for the user associated with the order.
- #could_use_store_credit? ⇒ Boolean
- #covered_by_store_credit? ⇒ Boolean (also: #covered_by_store_credit)
- #display_order_total_after_store_credit ⇒ Object
- #display_store_credit_remaining_after_capture ⇒ Object
- #display_total_applicable_store_credit ⇒ Object
- #display_total_applied_store_credit ⇒ Object
- #display_total_available_store_credit ⇒ Object
- #display_total_minus_store_credits ⇒ Object
-
#order_total_after_store_credit ⇒ BigDecimal
Returns the total amount of the order minus the total amount of store credits applied to the order.
- #remove_store_credit_payments ⇒ Object
- #total_applicable_store_credit ⇒ Object
-
#total_applied_store_credit ⇒ BigDecimal
Returns the total amount of store credits applied to the order.
-
#total_available_store_credit ⇒ BigDecimal
Returns the total amount of store credits available to the user associated with the order.
-
#total_minus_store_credits ⇒ BigDecimal
Returns the total amount of the order minus the total amount of store credits applied to the order.
-
#using_store_credit? ⇒ Boolean
Returns true if the order is using store credit.
Instance Method Details
#add_store_credit_payments(amount = nil) ⇒ Object
4 5 6 |
# File 'app/models/spree/order/store_credit.rb', line 4 def add_store_credit_payments(amount = nil) Spree::Dependencies.checkout_add_store_credit_service.constantize.call(order: self, amount: amount) end |
#available_store_credits ⇒ Array<Spree::StoreCredit>
Returns the available store credits for the user associated with the order.
30 31 32 33 34 |
# File 'app/models/spree/order/store_credit.rb', line 30 def available_store_credits return Spree::StoreCredit.none if user.nil? user.store_credits.for_store(store).where(currency: currency).available.sort_by(&:amount_remaining).reverse end |
#could_use_store_credit? ⇒ Boolean
36 37 38 39 40 |
# File 'app/models/spree/order/store_credit.rb', line 36 def could_use_store_credit? return false if store.payment_methods.store_credit.available.empty? total_available_store_credit > 0 end |
#covered_by_store_credit? ⇒ Boolean Also known as: covered_by_store_credit
12 13 14 |
# File 'app/models/spree/order/store_credit.rb', line 12 def covered_by_store_credit? user.present? && total_applied_store_credit.positive? && total_applied_store_credit >= total end |
#display_order_total_after_store_credit ⇒ Object
86 87 88 |
# File 'app/models/spree/order/store_credit.rb', line 86 def display_order_total_after_store_credit Spree::Money.new(order_total_after_store_credit, currency: currency) end |
#display_store_credit_remaining_after_capture ⇒ Object
94 95 96 |
# File 'app/models/spree/order/store_credit.rb', line 94 def display_store_credit_remaining_after_capture Spree::Money.new(total_available_store_credit - total_applicable_store_credit, currency: currency) end |
#display_total_applicable_store_credit ⇒ Object
78 79 80 |
# File 'app/models/spree/order/store_credit.rb', line 78 def display_total_applicable_store_credit Spree::Money.new(-total_applicable_store_credit, currency: currency) end |
#display_total_applied_store_credit ⇒ Object
82 83 84 |
# File 'app/models/spree/order/store_credit.rb', line 82 def display_total_applied_store_credit Spree::Money.new(-total_applied_store_credit, currency: currency) end |
#display_total_available_store_credit ⇒ Object
90 91 92 |
# File 'app/models/spree/order/store_credit.rb', line 90 def display_total_available_store_credit Spree::Money.new(total_available_store_credit, currency: currency) end |
#display_total_minus_store_credits ⇒ Object
98 99 100 |
# File 'app/models/spree/order/store_credit.rb', line 98 def display_total_minus_store_credits Spree::Money.new(total_minus_store_credits, currency: currency) end |
#order_total_after_store_credit ⇒ BigDecimal
Returns the total amount of the order minus the total amount of store credits applied to the order.
45 46 47 |
# File 'app/models/spree/order/store_credit.rb', line 45 def order_total_after_store_credit total - total_applicable_store_credit end |
#remove_store_credit_payments ⇒ Object
8 9 10 |
# File 'app/models/spree/order/store_credit.rb', line 8 def remove_store_credit_payments Spree::Dependencies.checkout_remove_store_credit_service.constantize.call(order: self) end |
#total_applicable_store_credit ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/models/spree/order/store_credit.rb', line 56 def total_applicable_store_credit if payment? || confirm? || complete? total_applied_store_credit else [total, user.try(:total_available_store_credit) || 0.0].min end end |
#total_applied_store_credit ⇒ BigDecimal
Returns the total amount of store credits applied to the order.
67 68 69 |
# File 'app/models/spree/order/store_credit.rb', line 67 def total_applied_store_credit payments.store_credits.valid.sum(:amount) end |
#total_available_store_credit ⇒ BigDecimal
Returns the total amount of store credits available to the user associated with the order. Returns only store credit for this store and same currency as order
21 22 23 24 25 |
# File 'app/models/spree/order/store_credit.rb', line 21 def total_available_store_credit return 0.0 unless user user.total_available_store_credit(currency, store) end |
#total_minus_store_credits ⇒ BigDecimal
Returns the total amount of the order minus the total amount of store credits applied to the order.
52 53 54 |
# File 'app/models/spree/order/store_credit.rb', line 52 def total_minus_store_credits total - total_applied_store_credit end |
#using_store_credit? ⇒ Boolean
Returns true if the order is using store credit.
74 75 76 |
# File 'app/models/spree/order/store_credit.rb', line 74 def using_store_credit? total_applied_store_credit > 0 end |