Sha256: 043f7ea62f0717fd8145a5645fa520f18db613decfb6342edf892169da21a58b

Contents?: true

Size: 450 Bytes

Versions: 99

Compression:

Stored size: 450 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
      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

99 entries across 99 versions & 1 rubygems

Version Path
solidus_core-4.4.2 app/models/concerns/spree/user_reporting.rb
solidus_core-4.4.1 app/models/concerns/spree/user_reporting.rb
solidus_core-4.4.0 app/models/concerns/spree/user_reporting.rb
solidus_core-4.3.4 app/models/concerns/spree/user_reporting.rb
solidus_core-4.2.4 app/models/concerns/spree/user_reporting.rb
solidus_core-4.1.5 app/models/concerns/spree/user_reporting.rb
solidus_core-4.3.3 app/models/concerns/spree/user_reporting.rb
solidus_core-4.3.2 app/models/concerns/spree/user_reporting.rb
solidus_core-4.1.4 app/models/concerns/spree/user_reporting.rb
solidus_core-4.3.1 app/models/concerns/spree/user_reporting.rb
solidus_core-4.3.0 app/models/concerns/spree/user_reporting.rb
solidus_core-4.2.3 app/models/concerns/spree/user_reporting.rb
solidus_core-4.1.3 app/models/concerns/spree/user_reporting.rb
solidus_core-4.0.4 app/models/concerns/spree/user_reporting.rb
solidus_core-3.4.6 app/models/concerns/spree/user_reporting.rb
solidus_core-4.0.3 app/models/concerns/spree/user_reporting.rb
solidus_core-4.1.2 app/models/concerns/spree/user_reporting.rb
solidus_core-4.2.2 app/models/concerns/spree/user_reporting.rb
solidus_core-3.4.5 app/models/concerns/spree/user_reporting.rb
solidus_core-4.2.1 app/models/concerns/spree/user_reporting.rb