Files
openfoodnetwork/app/serializers/api/current_order_serializer.rb
Pau Perez 06345e9161 Serialize shipping_method_id from Shipments
As so far we're only returning a single shipping method id, we get it
from the last shipment in the order.
2017-07-03 18:53:02 +02:00

24 lines
686 B
Ruby

class Api::CurrentOrderSerializer < ActiveModel::Serializer
attributes :id, :item_total, :email, :shipping_method_id,
:display_total, :payment_method_id
has_one :bill_address, serializer: Api::AddressSerializer
has_one :ship_address, serializer: Api::AddressSerializer
has_many :line_items, serializer: Api::LineItemSerializer
has_many :finalised_line_items, serializer: Api::LineItemSerializer
def payment_method_id
object.payments.first.andand.payment_method_id
end
def display_total
object.display_total.money.to_f
end
def shipping_method_id
return unless object.shipments.any?
object.shipments.last.shipping_method_id
end
end