Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

More reporting methods for User class

Damian Legawiec8408d58b794f
diff --git a/core/app/models/concerns/spree/user_reporting.rb b/core/app/models/concerns/spree/user_reporting.rb
index ff36e8e6d8..f53019f914 100644
--- a/core/app/models/concerns/spree/user_reporting.rb
+++ b/core/app/models/concerns/spree/user_reporting.rb
@@ -6,7 +6,7 @@ module Spree
def report_values_for(report_name, store)
store ||= Store.default
- completed_orders(store).pluck(:currency).uniq.each_with_object([]) do |currency, arr|
+ 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
@@ -31,16 +31,24 @@ module Spree
column: :all)
end
+ def amount_spent_in(currency)
+ completed_orders.where(currency: currency).sum(:total)
+ end
+
+ def display_amount_spent_in(currency)
+ Money.new(amount_spent_in(currency), currency: currency).to_html
+ end
+
private
def order_calculate(operation:, column:, store: nil, currency: nil)
store ||= Store.default
currency ||= store.default_currency
- completed_orders(store).where(currency: currency).calculate(operation, column) || BigDecimal('0.00')
+ completed_orders_for_store(store).where(currency: currency).calculate(operation, column) || BigDecimal('0.00')
end
- def completed_orders(store)
+ def completed_orders_for_store(store)
orders.for_store(store).complete.order(currency: :desc)
end
end