Sha256: d059c7088386c8a71f87a5d29c8e87c1009ec37bb06a75a46b7ebd668b984eec

Contents?: true

Size: 1.75 KB

Versions: 20

Compression:

Stored size: 1.75 KB

Contents

module Spree
  class Order < Spree::Base
    module StoreCredit
      def covered_by_store_credit?
        return false unless user

        user.total_available_store_credit >= total
      end
      alias covered_by_store_credit covered_by_store_credit?

      def total_available_store_credit
        return 0.0 unless user

        user.total_available_store_credit(currency, store)
      end

      def could_use_store_credit?
        return false if Spree::PaymentMethod::StoreCredit.available.empty?

        total_available_store_credit > 0
      end

      def order_total_after_store_credit
        total - total_applicable_store_credit
      end

      def total_applicable_store_credit
        if payment? || confirm? || complete?
          total_applied_store_credit
        else
          [total, (user.try(:total_available_store_credit) || 0.0)].min
        end
      end

      def total_applied_store_credit
        payments.store_credits.valid.sum(:amount)
      end

      def using_store_credit?
        total_applied_store_credit > 0
      end

      def display_total_applicable_store_credit
        Spree::Money.new(-total_applicable_store_credit, currency: currency)
      end

      def display_total_applied_store_credit
        Spree::Money.new(-total_applied_store_credit, currency: currency)
      end

      def display_order_total_after_store_credit
        Spree::Money.new(order_total_after_store_credit, currency: currency)
      end

      def display_total_available_store_credit
        Spree::Money.new(total_available_store_credit, currency: currency)
      end

      def display_store_credit_remaining_after_capture
        Spree::Money.new(total_available_store_credit - total_applicable_store_credit, currency: currency)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
spree_core-4.7.1 app/models/spree/order/store_credit.rb
spree_core-4.6.4 app/models/spree/order/store_credit.rb
spree_core-4.7.0 app/models/spree/order/store_credit.rb
spree_core-4.6.3 app/models/spree/order/store_credit.rb
spree_core-4.6.2 app/models/spree/order/store_credit.rb
spree_core-4.6.1 app/models/spree/order/store_credit.rb
spree_core-4.6.0 app/models/spree/order/store_credit.rb
spree_core-4.5.3 app/models/spree/order/store_credit.rb
spree_core-4.5.2 app/models/spree/order/store_credit.rb
spree_core-4.5.1 app/models/spree/order/store_credit.rb
spree_core-4.5.0 app/models/spree/order/store_credit.rb
spree_core-4.3.2 app/models/spree/order/store_credit.rb
spree_core-4.4.0 app/models/spree/order/store_credit.rb
spree_core-4.4.0.rc2 app/models/spree/order/store_credit.rb
spree_core-4.3.1 app/models/spree/order/store_credit.rb
spree_core-4.4.0.rc1 app/models/spree/order/store_credit.rb
spree_core-4.3.0 app/models/spree/order/store_credit.rb
spree_core-4.3.0.rc3 app/models/spree/order/store_credit.rb
spree_core-4.3.0.rc2 app/models/spree/order/store_credit.rb
spree_core-4.3.0.rc1 app/models/spree/order/store_credit.rb