Class: Spree::Shipstation::Export::OrderPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/spree/shipstation/export/order_presenter.rb

Overview

Shapes a single Spree::Shipment into the values ShipStation's export XML expects, keeping data-massaging logic out of the Builder template.

Note: ShipStation models one "Order" per shipment, so most order-level fields are derived from shipment.order while identifiers come from the shipment itself (mirroring the = shipment.number contract).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shipment) ⇒ OrderPresenter

Returns a new instance of OrderPresenter.



15
16
17
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 15

def initialize(shipment)
  @shipment = shipment
end

Instance Attribute Details

#shipmentObject (readonly)

Returns the value of attribute shipment.



13
14
15
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 13

def shipment
  @shipment
end

Instance Method Details

#bill_addressObject



67
68
69
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 67

def bill_address
  order.bill_address
end

#custom_field_1Object



59
60
61
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 59

def custom_field_1
  order.number
end

#customer_codeObject



63
64
65
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 63

def customer_code
  order.email&.slice(0, 50)
end

#itemsObject



75
76
77
78
79
80
81
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 75

def items
  shipment.inventory_units.group_by(&:line_item).filter_map do |line_item, units|
    next unless line_item.variant

    ItemPresenter.new(line_item, units)
  end
end

#last_modifiedObject



39
40
41
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 39

def last_modified
  format_date([order.completed_at, shipment.updated_at].compact.max)
end

#orderObject



19
20
21
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 19

def order
  shipment.order
end

#order_dateObject



35
36
37
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 35

def order_date
  format_date(order.completed_at)
end

#order_idObject



23
24
25
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 23

def order_id
  shipment.id
end

#order_numberObject



27
28
29
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 27

def order_number
  shipment.number
end

#order_statusObject



31
32
33
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 31

def order_status
  shipment.state
end

#order_totalObject



47
48
49
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 47

def order_total
  order.total
end

#ship_addressObject



71
72
73
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 71

def ship_address
  order.ship_address
end

#ship_totalObject



55
56
57
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 55

def ship_total
  order.ship_total
end

#shipping_method_nameObject



43
44
45
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 43

def shipping_method_name
  shipment.shipping_method&.name
end

#tax_totalObject



51
52
53
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 51

def tax_total
  order.tax_total
end