Module: Spree::UserReporting
- Extended by:
- DisplayMoney
- Included in:
- UserMethods
- Defined in:
- app/models/concerns/spree/user_reporting.rb
Instance Method Summary collapse
- #amount_spent_in(currency) ⇒ Object
- #average_order_value(**args) ⇒ Object
- #completed_orders_for_store(store) ⇒ Object
- #display_amount_spent_in(currency) ⇒ Object
- #lifetime_value(**args) ⇒ Object
- #order_count(store = nil) ⇒ Object
- #report_values_for(report_name, store) ⇒ Object
Methods included from DisplayMoney
Instance Method Details
#amount_spent_in(currency) ⇒ Object
34 35 36 |
# File 'app/models/concerns/spree/user_reporting.rb', line 34 def amount_spent_in(currency) completed_orders.where(currency: currency).sum(:total) end |
#average_order_value(**args) ⇒ Object
20 21 22 23 24 |
# File 'app/models/concerns/spree/user_reporting.rb', line 20 def average_order_value(**args) order_calculate(operation: :average, column: :total, **args) end |
#completed_orders_for_store(store) ⇒ Object
42 43 44 |
# File 'app/models/concerns/spree/user_reporting.rb', line 42 def completed_orders_for_store(store) orders.for_store(store).complete.order(currency: :desc) end |
#display_amount_spent_in(currency) ⇒ Object
38 39 40 |
# File 'app/models/concerns/spree/user_reporting.rb', line 38 def display_amount_spent_in(currency) Money.new(amount_spent_in(currency), currency: currency).to_html end |
#lifetime_value(**args) ⇒ Object
14 15 16 17 18 |
# File 'app/models/concerns/spree/user_reporting.rb', line 14 def lifetime_value(**args) order_calculate(operation: :sum, column: :total, **args) end |
#order_count(store = nil) ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/models/concerns/spree/user_reporting.rb', line 26 def order_count(store = nil) store ||= Store.default order_calculate(store: store, currency: store.supported_currencies.split(','), operation: :count, column: :all) end |
#report_values_for(report_name, store) ⇒ Object
6 7 8 9 10 11 12 |
# File 'app/models/concerns/spree/user_reporting.rb', line 6 def report_values_for(report_name, store) store ||= Store.default completed_orders_for_store(store).pluck(:currency).uniq.each_with_object([]) do |currency, arr| arr << send("display_#{report_name}", store: store, currency: currency) end end |