Class: Spree::Shipstation::Export::OrderPresenter
- Inherits:
-
Object
- Object
- Spree::Shipstation::Export::OrderPresenter
- 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
Instance Attribute Summary collapse
-
#shipment ⇒ Object
readonly
Returns the value of attribute shipment.
Instance Method Summary collapse
- #bill_address ⇒ Object
- #custom_field_1 ⇒ Object
- #customer_code ⇒ Object
-
#initialize(shipment) ⇒ OrderPresenter
constructor
A new instance of OrderPresenter.
- #items ⇒ Object
- #last_modified ⇒ Object
- #order ⇒ Object
- #order_date ⇒ Object
- #order_id ⇒ Object
- #order_number ⇒ Object
- #order_status ⇒ Object
- #order_total ⇒ Object
- #ship_address ⇒ Object
- #ship_total ⇒ Object
- #shipping_method_name ⇒ Object
- #tax_total ⇒ Object
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
#shipment ⇒ Object (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_address ⇒ Object
67 68 69 |
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 67 def bill_address order.bill_address end |
#custom_field_1 ⇒ Object
59 60 61 |
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 59 def custom_field_1 order.number end |
#customer_code ⇒ Object
63 64 65 |
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 63 def customer_code order.email&.slice(0, 50) end |
#items ⇒ Object
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_modified ⇒ Object
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 |
#order ⇒ Object
19 20 21 |
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 19 def order shipment.order end |
#order_date ⇒ Object
35 36 37 |
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 35 def order_date format_date(order.completed_at) end |
#order_id ⇒ Object
23 24 25 |
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 23 def order_id shipment.id end |
#order_number ⇒ Object
27 28 29 |
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 27 def order_number shipment.number end |
#order_status ⇒ Object
31 32 33 |
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 31 def order_status shipment.state end |
#order_total ⇒ Object
47 48 49 |
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 47 def order_total order.total end |
#ship_address ⇒ Object
71 72 73 |
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 71 def ship_address order.ship_address end |
#ship_total ⇒ Object
55 56 57 |
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 55 def ship_total order.ship_total end |
#shipping_method_name ⇒ Object
43 44 45 |
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 43 def shipping_method_name shipment.shipping_method&.name end |
#tax_total ⇒ Object
51 52 53 |
# File 'app/presenters/spree/shipstation/export/order_presenter.rb', line 51 def tax_total order.tax_total end |