Class: Workarea::Search::OrderText
- Inherits:
-
Object
- Object
- Workarea::Search::OrderText
- Defined in:
- app/models/workarea/search/order_text.rb
Instance Method Summary collapse
- #addresses ⇒ Object
- #addresses_text ⇒ Object
-
#discount_text ⇒ String
Space-separated IDs for item-level and shipping-level discounts.
-
#initialize(order) ⇒ OrderText
constructor
A new instance of OrderText.
- #payment ⇒ Object
- #payment_text ⇒ Object
- #shipping_text ⇒ Object
- #shippings ⇒ Object
- #text ⇒ Object
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
#addresses ⇒ Object
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_text ⇒ Object
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_text ⇒ String
Space-separated IDs for item-level and shipping-level discounts.
34 35 36 |
# File 'app/models/workarea/search/order_text.rb', line 34 def discount_text (order_discounts + shipping_discounts).join(' ') end |
#payment ⇒ Object
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_text ⇒ Object
27 28 29 |
# File 'app/models/workarea/search/order_text.rb', line 27 def payment_text payment.try(:credit_card).try(:issuer) end |
#shipping_text ⇒ Object
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 |
#shippings ⇒ Object
64 65 66 |
# File 'app/models/workarea/search/order_text.rb', line 64 def shippings @shippings ||= Workarea::Shipping.where(order_id: @order.id) end |
#text ⇒ Object
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 |