Class: ShipmentSerializer
- Inherits:
-
ActiveModel::Serializer
- Object
- ActiveModel::Serializer
- ShipmentSerializer
- Defined in:
- app/serializers/shipment_serializer.rb
Instance Method Summary collapse
- #channel ⇒ Object
- #cost ⇒ Object
- #email ⇒ Object
- #id ⇒ Object
- #items ⇒ Object
- #order_id ⇒ Object
- #placed_on ⇒ Object
- #shipped_at ⇒ Object
- #shipping_method ⇒ Object
- #shipping_method_code ⇒ Object
- #status ⇒ Object
- #stock_location ⇒ Object
- #totals ⇒ Object
- #updated_at ⇒ Object
Instance Method Details
#channel ⇒ Object
23 24 25 |
# File 'app/serializers/shipment_serializer.rb', line 23 def channel object.order.channel || 'spree' end |
#cost ⇒ Object
27 28 29 |
# File 'app/serializers/shipment_serializer.rb', line 27 def cost object.cost.to_f end |
#email ⇒ Object
19 20 21 |
# File 'app/serializers/shipment_serializer.rb', line 19 def email object.order.email end |
#id ⇒ Object
11 12 13 |
# File 'app/serializers/shipment_serializer.rb', line 11 def id object.number end |
#items ⇒ Object
82 83 84 85 86 87 88 |
# File 'app/serializers/shipment_serializer.rb', line 82 def items i = [] object.inventory_units.each do |inventory_unit| i << InventoryUnitSerializer.new(inventory_unit, root: false) end i end |
#order_id ⇒ Object
15 16 17 |
# File 'app/serializers/shipment_serializer.rb', line 15 def order_id object.order.number end |
#placed_on ⇒ Object
55 56 57 58 59 60 61 |
# File 'app/serializers/shipment_serializer.rb', line 55 def placed_on if object.order.completed_at? object.order.completed_at.getutc.try(:iso8601) else '' end end |
#shipped_at ⇒ Object
63 64 65 |
# File 'app/serializers/shipment_serializer.rb', line 63 def shipped_at object.shipped_at.try(:iso8601) end |
#shipping_method ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/serializers/shipment_serializer.rb', line 39 def shipping_method if object.shipping_method.try(:name) if object.shipping_method.try(:name).include?('Standard') || object.shipping_method.try(:name).include?('Free') '' elsif object.shipping_method.try(:name).include?('Expedited') object.shipping_method.try(:code) end else '' end end |
#shipping_method_code ⇒ Object
51 52 53 |
# File 'app/serializers/shipment_serializer.rb', line 51 def shipping_method_code object.shipping_method.try(:code) end |
#status ⇒ Object
31 32 33 |
# File 'app/serializers/shipment_serializer.rb', line 31 def status object.state end |
#stock_location ⇒ Object
35 36 37 |
# File 'app/serializers/shipment_serializer.rb', line 35 def stock_location object.stock_location.name end |
#totals ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'app/serializers/shipment_serializer.rb', line 67 def totals { item: object.order.display_item_total.to_s, adjustment: object.order.display_adjustment_total.to_s, #adjustment_total.to_s, tax: object.order.display_tax_total.to_s, #tax_total.to_s, shipping: object.order.display_ship_total.to_s, #shipping_total.to_s payment: object.order.payments.completed.sum(:amount).to_s, order: object.order.display_total.to_s } end |
#updated_at ⇒ Object
78 79 80 |
# File 'app/serializers/shipment_serializer.rb', line 78 def updated_at object.updated_at.iso8601 end |