Sha256: e0c71d0eada5b8ada90b5e9fb62cda38eed2da259192d031e9ecb2d6ebc0fd82

Contents?: true

Size: 1.2 KB

Versions: 62

Compression:

Stored size: 1.2 KB

Contents

module Workarea
  class Storefront::UserViewModel < ApplicationViewModel
    delegate :display_number, :month, :year,
             to: :default_credit_card, prefix: true

    def has_default_addresses?
      addresses.present?
    end

    def default_credit_card
      @default_credit_card ||= payment.default_credit_card
    end

    def has_credit_card?
      !!default_credit_card
    end

    def credit_cards
      payment.credit_cards
    end

    def recent_orders
      @recent_orders ||= recent_order_models.map do |order|
        Storefront::OrderViewModel.new(
          order,
          fulfillment_status: fulfillment_statuses[order.id]
        )
      end
    end

    def email_signup?
      return @email_signup if defined?(@email_signup)
      @email_signup = Email.signed_up?(email)
    end

    private

    def recent_order_models
      @recent_order_models ||= Order.recent(
        model.id,
        Workarea.config.recent_order_count
      )
    end

    def fulfillment_statuses
      @fulfillment_statuses ||= Fulfillment.find_statuses(
        *recent_order_models.map(&:id)
      )
    end

    def payment
      @payment ||= Payment::Profile.lookup(PaymentReference.new(model))
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-storefront-3.5.27 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.5.26 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.4.45 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.5.25 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.5.23 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.4.44 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.5.22 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.4.43 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.5.21 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.4.42 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.5.20 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.4.41 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.5.19 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.4.40 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.5.18 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.4.39 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.5.17 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.4.38 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.5.16 app/view_models/workarea/storefront/user_view_model.rb
workarea-storefront-3.4.37 app/view_models/workarea/storefront/user_view_model.rb