Class: Workarea::Listrak::Models::OrderForm

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/listrak/models/order_form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ OrderForm

Returns a new instance of OrderForm.



7
8
9
# File 'app/services/workarea/listrak/models/order_form.rb', line 7

def initialize(order)
  @order = order
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



5
6
7
# File 'app/services/workarea/listrak/models/order_form.rb', line 5

def order
  @order
end

Instance Method Details

#as_json(_options) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/workarea/listrak/models/order_form.rb', line 11

def as_json(_options)
  {
    associateID: associate_id,
    billingAddress: billing_address,
    couponCode: coupon_code,
    customerNumber: customer_number,
    dateEntered: date_entered,
    discountTotal: discount_total,
    email: email,
    handlingTotal: handling_total,
    items: items,
    itemTotal: item_total,
    merchandiseDiscount: merchandise_discount,
    merchandiseDiscountDescription: merchandise_discount_description,
    merchandiseDiscountType: merchandise_discount_type,
    meta1: meta1,
    meta2: meta2,
    meta3: meta3,
    meta4: meta4,
    meta5: meta5,
    nonMerchandiseDiscount: non_merchandise_discount,
    nonMerchandiseDiscountDescription: non_merchandise_discount_description,
    nonMerchandiseDiscountType: non_merchandise_discount_type,
    orderNumber: order_number,
    orderTotal: order_total,
    shipDate: ship_date,
    shippingAddress: shipping_address,
    shippingMethod: shipping_method,
    shippingTotal: shipping_total,
    source: source,
    status: status,
    storeNumber: store_number,
    taxTotal: tax_total,
    trackingNumber: tracking_number
  }
end

#associate_idString

Associate ID of order

Returns:

  • (String)


51
52
# File 'app/services/workarea/listrak/models/order_form.rb', line 51

def associate_id
end

#billing_addressWorkarea::Listrak::Models::Address

Billing address of order



58
59
60
# File 'app/services/workarea/listrak/models/order_form.rb', line 58

def billing_address
  Workarea::Listrak::Models::Address.new payment.address
end

#coupon_codeString

Coupon code used with order

limited to 32 characters

Returns:

  • (String)


68
69
70
# File 'app/services/workarea/listrak/models/order_form.rb', line 68

def coupon_code
  order.promo_codes.first
end

#customer_numberString

Internal customer number

limited to 20 characters

Returns:

  • (String)


78
79
80
# File 'app/services/workarea/listrak/models/order_form.rb', line 78

def customer_number
  order.user_id.to_s
end

#date_enteredString

Timestamp of order date (ET)

Returns:

  • (String)

    DateTime in %FT%TZ



86
87
88
# File 'app/services/workarea/listrak/models/order_form.rb', line 86

def date_entered
  order.placed_at.strftime '%FT%TZ'
end

#discount_totalFloat

Total value of order discount

Returns:

  • (Float)


94
95
96
97
98
99
100
# File 'app/services/workarea/listrak/models/order_form.rb', line 94

def discount_total
  order.price_adjustments
    .select { |pa| pa.data['discount_value'].present? && pa.price != 'item' }
    .sum { |d| d.data['discount_value'] }
    .abs
    .try(:to_f)
end

#emailString

Email address of customer. This property is required for accounts that are not CRM enabled.

limited to 100 characters

Returns:

  • (String)


109
110
111
# File 'app/services/workarea/listrak/models/order_form.rb', line 109

def email
  order.email
end

#handling_totalFloat

Total handling costs

Returns:

  • (Float)


117
118
119
# File 'app/services/workarea/listrak/models/order_form.rb', line 117

def handling_total
  shipping.shipping_total.to_f
end

#item_totalFloat

Total cost of items ordered (subtotal)

Returns:

  • (Float)


135
136
137
# File 'app/services/workarea/listrak/models/order_form.rb', line 135

def item_total
  order.subtotal_price.to_f
end

#itemsArray<Workarea::Listrak::Models::OrderItem>

Order items



125
126
127
128
129
# File 'app/services/workarea/listrak/models/order_form.rb', line 125

def items
  @order_items ||= order.items.map do |order_item|
    Workarea::Listrak::Models::OrderItem.new order, order_item
  end
end

#merchandise_discountFloat

Discount applied to the merchandise of the order

Returns:

  • (Float)


143
144
145
146
147
148
149
# File 'app/services/workarea/listrak/models/order_form.rb', line 143

def merchandise_discount
  order.price_adjustments
    .select { |pa| pa.data['discount_value'].present? && pa.price == 'item' }
    .sum { |d| d.data['discount_value'] }
    .abs
    .try(:to_f)
end

#merchandise_discount_descriptionString

Description of the discount applied to the merchandise of the order

Returns:

  • (String)


155
156
# File 'app/services/workarea/listrak/models/order_form.rb', line 155

def merchandise_discount_description
end

#merchandise_discount_typeString

Type of discount applied to the merchandise of the order

“NotSet” “PriceOverride” “PriceRule” “Promotion” “SeniorCitizen” “Markdown” “Coupon” “QuantityDiscount” “Rebate” “CashDiscount” “TradeDiscount” “TradeInKind” “PromptPaymentDiscount” “GeneralDiscount” “GiftVoucher” “FlexibleDiscount” “RewardProgram” “ManufacturerReward” “CreditCardReward”

Returns:

  • (String)


164
165
# File 'app/services/workarea/listrak/models/order_form.rb', line 164

def merchandise_discount_type
end

#meta1String

Additional meta information

limited to 500 characters

Returns:

  • (String)


173
174
# File 'app/services/workarea/listrak/models/order_form.rb', line 173

def meta1
end

#meta2String

Additional meta information

limted to 500 characters

Returns:

  • (String)


182
183
# File 'app/services/workarea/listrak/models/order_form.rb', line 182

def meta2
end

#meta3String

Additional meta information

limted to 500 characters

Returns:

  • (String)


191
192
# File 'app/services/workarea/listrak/models/order_form.rb', line 191

def meta3
end

#meta4String

Additional meta information

limted to 500 characters

Returns:

  • (String)


200
201
# File 'app/services/workarea/listrak/models/order_form.rb', line 200

def meta4
end

#meta5String

Additional meta information

limted to 500 characters

Returns:

  • (String)


209
210
# File 'app/services/workarea/listrak/models/order_form.rb', line 209

def meta5
end

#non_merchandise_discountFloat

Discounts applied to the order that is not related to the merchandise

Returns:

  • (Float)


216
217
# File 'app/services/workarea/listrak/models/order_form.rb', line 216

def non_merchandise_discount
end

#non_merchandise_discount_descriptionString

Description of the discount applied to the order not related to the merchandise

Returns:

  • (String)


223
224
# File 'app/services/workarea/listrak/models/order_form.rb', line 223

def non_merchandise_discount_description
end

#non_merchandise_discount_typeString

Type of discount applied to the order not related to the merchandise

“NotSet” “PriceOverride” “PriceRule” “Promotion” “SeniorCitizen” “Markdown” “Coupon” “QuantityDiscount” “Rebate” “CashDiscount” “TradeDiscount” “TradeInKind” “PromptPaymentDiscount” “GeneralDiscount” “GiftVoucher” “FlexibleDiscount” “RewardProgram” “ManufacturerReward” “CreditCardReward”

Returns:

  • (String)


232
233
# File 'app/services/workarea/listrak/models/order_form.rb', line 232

def non_merchandise_discount_type
end

#order_numberString

Unique order number

limited to 50 characters

Returns:

  • (String)


241
242
243
# File 'app/services/workarea/listrak/models/order_form.rb', line 241

def order_number
  order.id.to_s
end

#order_totalObject

Total value of order

return [Float]



249
250
251
# File 'app/services/workarea/listrak/models/order_form.rb', line 249

def order_total
  order.total_value.to_f
end

#ship_dateString

Timestamp when entire order shipped (ET)

Returns:

  • (String)


257
258
# File 'app/services/workarea/listrak/models/order_form.rb', line 257

def ship_date
end

#shipping_addressWorkarea::Listrak::Models::Address

Shipping address of order



264
265
266
# File 'app/services/workarea/listrak/models/order_form.rb', line 264

def shipping_address
  Workarea::Listrak::Models::Address.new shipping.address
end

#shipping_methodString

Shipping method (e.g. UPS Ground)

limted to 32 characters

Returns:

  • (String)


274
275
276
# File 'app/services/workarea/listrak/models/order_form.rb', line 274

def shipping_method
  shipping.shipping_service&.name
end

#shipping_totalFloat

Total shipping costs

Returns:

  • (Float)


282
283
284
# File 'app/services/workarea/listrak/models/order_form.rb', line 282

def shipping_total
  order.shipping_total.to_f
end

#sourceString

Describes the source at which the order was placed (online, POS, etc.)

limted to 25 characters

Returns:

  • (String)


292
293
294
# File 'app/services/workarea/listrak/models/order_form.rb', line 292

def source
  'web'
end

#statusString

Status indicator

“NotSet” “Misc” “PreOrder” “BackOrder” “Pending” “Hold” “Processing” “Shipped” “Completed” “Returned” “Canceled” “Unknown” “Closed”

Returns:

  • (String)


302
303
304
# File 'app/services/workarea/listrak/models/order_form.rb', line 302

def status
  order.status
end

#store_numberString

Brick and mortar store location

limited to 100 characters

Returns:

  • (String)


312
313
# File 'app/services/workarea/listrak/models/order_form.rb', line 312

def store_number
end

#tax_totalFloat

Total sales tax charged

Returns:

  • (Float)


319
320
321
# File 'app/services/workarea/listrak/models/order_form.rb', line 319

def tax_total
  order.tax_total.to_f
end

#tracking_numberString

Shipment tracking number

limited to 32 characters

Returns:

  • (String)


329
330
# File 'app/services/workarea/listrak/models/order_form.rb', line 329

def tracking_number
end