mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-22 00:57:26 +00:00
30 lines
856 B
Ruby
30 lines
856 B
Ruby
class Api::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
|