Class: Workarea::Search::OrderText

Inherits:
Object
  • Object
show all
Defined in:
app/models/workarea/search/order_text.rb

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ OrderText

Returns a new instance of OrderText.



4
5
6
# File 'app/models/workarea/search/order_text.rb', line 4

def initialize(order)
  @order = order
end

Instance Method Details

#addressesObject



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

def addresses
  (shippings.map(&:address) + [payment.try(:address)]).reject(&:blank?)
end

#addresses_textObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/workarea/search/order_text.rb', line 8

def addresses_text
  addresses.map do |address|
    [
      address.first_name,
      address.last_name,
      address.company,
      address.street,
      address.street_2,
      address.city,
      address.region,
      address.region_name,
      address.postal_code,
      address.country.name,
      address.country.alpha2,
      address.phone_number
    ]
  end.flatten.join(' ')
end

#discount_textString

Space-separated IDs for item-level and shipping-level discounts.

Returns:



34
35
36
# File 'app/models/workarea/search/order_text.rb', line 34

def discount_text
  (order_discounts + shipping_discounts).join(' ')
end

#paymentObject



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

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

#payment_textObject



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

def payment_text
  payment.try(:credit_card).try(:issuer)
end

#shipping_textObject



38
39
40
41
42
43
# File 'app/models/workarea/search/order_text.rb', line 38

def shipping_text
  shippings
    .map(&:shipping_service)
    .map { |sm| sm.try(:name) }
    .reject(&:blank?)
end

#shippingsObject



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

def shippings
  @shippings ||= Workarea::Shipping.where(order_id: @order.id)
end

#textObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/workarea/search/order_text.rb', line 45

def text
  [
    'order',
    @order.id,
    @order.email,
    @order.promo_codes,
    @order.token,
    @order.items.map { |i| "#{i.product_id} #{i.sku}" },
    addresses_text,
    payment_text,
    shipping_text,
    discount_text
  ].flatten.join(' ')
end