mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-24 01:13:21 +00:00
32 lines
910 B
Ruby
32 lines
910 B
Ruby
module Api
|
|
class OrderSerializer < ActiveModel::Serializer
|
|
attributes :number, :completed_at, :total, :state, :shipment_state, :payment_state, :outstanding_balance, :payments, :path
|
|
|
|
has_many :payments, serializer: Api::PaymentSerializer
|
|
|
|
def completed_at
|
|
object.completed_at.blank? ? "" : I18n.l(object.completed_at, format: :long) #.to_formatted_s(:long_ordinal)
|
|
end
|
|
|
|
def total
|
|
object.total.to_money.to_s
|
|
end
|
|
|
|
def shipment_state
|
|
object.shipment_state ? object.shipment_state.humanize : nil # Or a call to t() here?
|
|
end
|
|
|
|
def payment_state
|
|
object.payment_state ? object.payment_state.humanize : nil # Or a call to t() here?
|
|
end
|
|
|
|
def state
|
|
object.state ? object.state.humanize : nil # Or a call to t() here?
|
|
end
|
|
|
|
def path
|
|
Spree::Core::Engine.routes_url_helpers.order_url(object.number, only_path: true)
|
|
end
|
|
end
|
|
end
|