Class: Workarea::Search::Admin::Order

Inherits:
Workarea::Search::Admin show all
Defined in:
app/models/workarea/search/admin/order.rb

Instance Method Summary collapse

Methods inherited from Workarea::Search::Admin

#created_at, for, #id, jump_to, #jump_to_param, #jump_to_route_helper, #jump_to_search_text, #releasable?, #sanitized_keywords, #status, #type

Methods included from Elasticsearch::Document

all, #as_bulk_document, current_index_prefix, #destroy, #initialize, #save

Instance Method Details

#as_documentObject



44
45
46
47
48
49
# File 'app/models/workarea/search/admin/order.rb', line 44

def as_document
  super.merge(
    total_price: model.total_price.to_f,
    placed_at: model.placed_at
  )
end

#facetsObject



35
36
37
38
39
40
41
42
# File 'app/models/workarea/search/admin/order.rb', line 35

def facets
  super.merge(
    order_status: order_status,
    payment_status: payment.status,
    fulfillment_status: fulfillment.status,
    traffic_referrer: traffic_referrer
  )
end

#fulfillmentObject



68
69
70
# File 'app/models/workarea/search/admin/order.rb', line 68

def fulfillment
  @fulfillment ||= Fulfillment.find_or_initialize_by(id: model.id)
end

#jump_to_positionObject



27
28
29
# File 'app/models/workarea/search/admin/order.rb', line 27

def jump_to_position
  2
end

#jump_to_textObject



19
20
21
22
23
24
25
# File 'app/models/workarea/search/admin/order.rb', line 19

def jump_to_text
  if model.placed?
    "#{model.id} - Placed @ #{model.placed_at.to_s(:short)}"
  else
    "#{model.id} - #{model.status.to_s.titleize}"
  end
end

#keywordsObject



15
16
17
# File 'app/models/workarea/search/admin/order.rb', line 15

def keywords
  super + [model.email] + fulfillment.packages.map(&:tracking_number)
end

#nameObject



5
6
7
8
9
# File 'app/models/workarea/search/admin/order.rb', line 5

def name
  if payment.address.present?
    "#{payment.address.last_name} #{payment.address.first_name}"
  end
end

#order_statusObject



51
52
53
# File 'app/models/workarea/search/admin/order.rb', line 51

def order_status
  model.status
end

#paymentObject



64
65
66
# File 'app/models/workarea/search/admin/order.rb', line 64

def payment
  @payment ||= Payment.find_or_initialize_by(id: model.id)
end

#search_textObject



11
12
13
# File 'app/models/workarea/search/admin/order.rb', line 11

def search_text
  OrderText.new(model).text
end

#should_be_indexed?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/models/workarea/search/admin/order.rb', line 31

def should_be_indexed?
  model.placed? || model.fraud_suspected?
end

#traffic_referrerObject



55
56
57
58
# File 'app/models/workarea/search/admin/order.rb', line 55

def traffic_referrer
  source = model.traffic_referrer&.medium || 'direct'
  I18n.t('workarea.order.traffic_referrer')[source]
end

#updated_atObject



60
61
62
# File 'app/models/workarea/search/admin/order.rb', line 60

def updated_at
  [model, payment, fulfillment].map(&:updated_at).compact.max
end