Module: Spree::UserMethods
Instance Method Summary
collapse
#average_order_value, #lifetime_value, #order_count, #report_values_for
#money_methods
Instance Method Details
#available_store_credits(store) ⇒ Object
63
64
65
66
67
68
69
|
# File 'app/models/concerns/spree/user_methods.rb', line 63
def available_store_credits(store)
store ||= Store.default
store_credits.for_store(store).pluck(:currency).uniq.each_with_object([]) do |currency, arr|
arr << Spree::Money.new(total_available_store_credit(currency, store), currency: currency)
end
end
|
#default_wishlist_for_store(current_store) ⇒ Object
71
72
73
74
75
76
|
# File 'app/models/concerns/spree/user_methods.rb', line 71
def default_wishlist_for_store(current_store)
wishlists.find_or_create_by(is_default: true, store_id: current_store.id) do |wishlist|
wishlist.name = Spree.t(:default_wishlist_name)
wishlist.save
end
end
|
#last_incomplete_spree_order(store, options = {}) ⇒ Object
50
51
52
53
54
55
|
# File 'app/models/concerns/spree/user_methods.rb', line 50
def last_incomplete_spree_order(store, options = {})
orders.where(store: store).incomplete.
includes(options[:includes]).
order('created_at DESC').
first
end
|
#total_available_store_credit(currency = nil, store = nil) ⇒ Object
57
58
59
60
61
|
# File 'app/models/concerns/spree/user_methods.rb', line 57
def total_available_store_credit(currency = nil, store = nil)
store ||= Store.default
currency ||= store.default_currency
store_credits.for_store(store).where(currency: currency).reload.to_a.sum(&:amount_remaining)
end
|