Class: Workarea::Storefront::OrderViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Includes:
OrderPricing
Defined in:
app/view_models/workarea/storefront/order_view_model.rb

Defined Under Namespace

Classes: CancelledItem, PendingItem

Instance Method Summary collapse

Methods included from OrderPricing

#advance_payment_amount, #order_balance, #store_credit?, #total_adjustments

Instance Method Details

#billing_addressObject



28
29
30
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 28

def billing_address
  payment.address
end

#canceled_itemsObject



105
106
107
108
109
110
111
112
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 105

def canceled_items
  @canceled_items ||= fulfillment.canceled_items.map do |fulfillment_item|
    next unless order_item = items
      .detect { |i| i.id.to_s == fulfillment_item.order_item_id }

    FulfillmentItemViewModel.new(order_item, quantity: fulfillment_item.quantity_canceled)
  end.compact
end

#fulfillment_statusObject



85
86
87
88
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 85

def fulfillment_status
  return if fulfillment_status_slug == 'not_available'
  fulfillment_status_slug.titleize
end

#full_nameObject



40
41
42
43
44
45
46
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 40

def full_name
  if billing_address.present?
    "#{billing_address.last_name}, #{billing_address.first_name}"
  elsif shipping_address.present?
    "#{shipping_address.last_name}, #{shipping_address.first_name}"
  end
end

#itemsObject



48
49
50
51
52
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 48

def items
  @items ||= model.items.by_newest.map do |item|
    Storefront::OrderItemViewModel.new(item)
  end
end

#packagesObject



90
91
92
93
94
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 90

def packages
  @packages ||= fulfillment.packages.map do |package|
    Storefront::PackageViewModel.wrap(package, order: self)
  end
end


69
70
71
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 69

def paid_amount
  total_price - store_credit_amount
end

#pending_itemsObject



96
97
98
99
100
101
102
103
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 96

def pending_items
  @pending_items ||= fulfillment.pending_items.map do |fulfillment_item|
    next unless order_item = items
      .detect { |i| i.id.to_s == fulfillment_item.order_item_id }

    FulfillmentItemViewModel.new(order_item, quantity: fulfillment_item.quantity_pending)
  end.compact
end

#recommendationsWorkarea::Storefront::CartRecommendationsViewModel

Returns recommendations for the order. The view model it returns behave like Enumerable.



119
120
121
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 119

def recommendations
  @recommendations ||= CartRecommendationsViewModel.new(model)
end

#refundsObject



73
74
75
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 73

def refunds
  @refunds ||= RefundViewModel.wrap(payment.refunds, options)
end

#render_signup_form?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 20

def 
  User.find_by_email(model.email).blank?
end

#shipping_addressObject



32
33
34
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 32

def shipping_address
  shipping.try(:address)
end

#shipping_serviceObject



36
37
38
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 36

def shipping_service
  shipping.try(:shipping_service).try(:name)
end

#shippingsObject



54
55
56
57
58
59
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 54

def shippings
  @shippings ||= Storefront::ShippingViewModel.wrap(
    Shipping.by_order(model.id).to_a,
    options.merge(order: model)
  )
end

#statusObject



77
78
79
80
81
82
83
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 77

def status
  if fulfillment_status_slug.in?(%w(open not_available))
    model.status.to_s.titleize
  else
    fulfillment_status
  end
end

#store_credit_amountObject



61
62
63
64
65
66
67
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 61

def store_credit_amount
  if store_credit.present?
    store_credit.amount
  else
    0.to_m
  end
end

#userObject



24
25
26
# File 'app/view_models/workarea/storefront/order_view_model.rb', line 24

def user
  @user ||= User.find(model.user_id) if model.user_id.present?
end