Class: Workarea::Admin::OrderViewModel
- Inherits:
-
ApplicationViewModel
- Object
- ApplicationViewModel
- Workarea::Admin::OrderViewModel
show all
- Includes:
- CommentableViewModel
- Defined in:
- app/view_models/workarea/admin/order_view_model.rb
Instance Method Summary
collapse
#comment_count, #comments, #has_comments?, #new_comments_for?, #subscribed_users
Instance Method Details
#billing_address ⇒ Object
79
80
81
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 79
def billing_address
payment.address
end
|
#can_cancel? ⇒ Boolean
25
26
27
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 25
def can_cancel?
model.placed? && !canceled?
end
|
#checkout_by ⇒ Object
29
30
31
32
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 29
def checkout_by
return nil unless model.checkout_by_id.present?
@checkout_by ||= User.where(id: model.checkout_by_id).first
end
|
#fulfillment ⇒ Object
102
103
104
105
106
107
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 102
def fulfillment
@fulfillment ||= FulfillmentViewModel.wrap(
Fulfillment.find_or_initialize_by(id: model.id),
order: self
)
end
|
#fulfillment_status ⇒ Object
109
110
111
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 109
def fulfillment_status
options['source'].try(:dig, 'facets', 'fulfillment_status').try(:to_sym)
end
|
#full_name ⇒ Object
13
14
15
16
17
18
19
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 13
def full_name
if billing_address.present?
"#{billing_address.first_name} #{billing_address.last_name}"
elsif shipping_address.present?
"#{shipping_address.first_name} #{shipping_address.last_name}"
end
end
|
#items ⇒ Object
21
22
23
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 21
def items
@items ||= model.items.by_newest.map { |item| OrderItemViewModel.new(item) }
end
|
#packages ⇒ Object
113
114
115
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 113
def packages
fulfillment.packages
end
|
#payment ⇒ Object
83
84
85
86
87
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 83
def payment
@payment ||= PaymentViewModel.wrap(
Payment.find_or_initialize_by(id: model.id)
)
end
|
#payment_status ⇒ Object
93
94
95
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 93
def payment_status
options['source'].try(:dig, 'facets', 'payment_status').try(:to_sym)
end
|
#segments ⇒ Object
43
44
45
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 43
def segments
@segments ||= Segment.in(id: model.segment_ids).to_a
end
|
#shipping ⇒ Object
60
61
62
63
64
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 60
def shipping
@shipping ||=
shippings.detect { |s| s.id.to_s == options[:shipping_id].to_s } ||
shippings.first
end
|
#shipping_address ⇒ Object
52
53
54
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 52
def shipping_address
shipping.try(:address)
end
|
#shipping_service ⇒ Object
56
57
58
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 56
def shipping_service
shipping.try(:shipping_service)
end
|
#shipping_subtotal ⇒ Object
70
71
72
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 70
def shipping_subtotal
shippings.sum { |s| s.price_adjustments.first.try(:amount) || 0.to_m }
end
|
#shippings ⇒ Object
66
67
68
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 66
def shippings
@shippings ||= Shipping.by_order(model.id).to_a
end
|
#timeline ⇒ Object
34
35
36
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 34
def timeline
@timeline ||= OrderTimelineViewModel.wrap(self, options)
end
|
#total_adjustments ⇒ Object
89
90
91
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 89
def total_adjustments
@total_adjustments ||= price_adjustments.reduce_by_description('order')
end
|
#updated_at ⇒ Object
38
39
40
41
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 38
def updated_at
options['source'].try(:[], 'updated_at').try(:to_datetime) ||
model.updated_at
end
|
#user ⇒ Object
8
9
10
11
|
# File 'app/view_models/workarea/admin/order_view_model.rb', line 8
def user
return nil unless model.user_id.present?
@user ||= User.where(id: model.user_id).first
end
|