Sha256: 2ad6c82ed9b0d66e2cf73f6e5f1684e08534923cb889a6593af55d976a3e3f9b

Contents?: true

Size: 462 Bytes

Versions: 34

Compression:

Stored size: 462 Bytes

Contents

# frozen_string_literal: true

module Spree
  module UserReporting
    extend DisplayMoney
    money_methods :lifetime_value, :average_order_value

    def lifetime_value
      spree_orders.complete.pluck(:total).sum
    end

    def order_count
      BigDecimal(spree_orders.complete.count)
    end

    def average_order_value
      if order_count.to_i > 0
        lifetime_value / order_count
      else
        BigDecimal("0.00")
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
solidus_core-2.8.6 app/models/concerns/spree/user_reporting.rb
solidus_core-2.6.6 app/models/concerns/spree/user_reporting.rb
solidus_core-2.7.4 app/models/concerns/spree/user_reporting.rb
solidus_core-2.8.5 app/models/concerns/spree/user_reporting.rb
solidus_core-2.7.3 app/models/concerns/spree/user_reporting.rb
solidus_core-2.6.5 app/models/concerns/spree/user_reporting.rb
solidus_core-2.8.4 app/models/concerns/spree/user_reporting.rb
solidus_core-2.8.3 app/models/concerns/spree/user_reporting.rb
solidus_core-2.7.2 app/models/concerns/spree/user_reporting.rb
solidus_core-2.6.4 app/models/concerns/spree/user_reporting.rb
solidus_core-2.8.2 app/models/concerns/spree/user_reporting.rb
solidus_core-2.8.1 app/models/concerns/spree/user_reporting.rb
solidus_core-2.6.3 app/models/concerns/spree/user_reporting.rb
solidus_core-2.8.0 app/models/concerns/spree/user_reporting.rb
solidus_core-2.7.1 app/models/concerns/spree/user_reporting.rb
solidus_core-2.6.2 app/models/concerns/spree/user_reporting.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 app/models/concerns/spree/user_reporting.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 app/models/concerns/spree/user_reporting.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 app/models/concerns/spree/user_reporting.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 app/models/concerns/spree/user_reporting.rb