Files
openfoodnetwork/app/serializers/spree/api/product_serializer.rb
Rohan Mitchell 29e49b67cc In BPE, rename producer and category JSON attrs to producer_id and category_id
Conflicts:

	spec/features/admin/bulk_product_update_spec.rb
2014-11-21 08:41:41 +11:00

27 lines
808 B
Ruby

class Spree::Api::ProductSerializer < ActiveModel::Serializer
attributes :id, :name, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand
attributes :on_hand, :price, :available_on, :permalink_live
has_one :supplier, key: :producer_id, embed: :id
has_one :primary_taxon, key: :category_id, embed: :id
has_many :variants, key: :variants, serializer: Spree::Api::VariantSerializer # embed: ids
has_one :master, serializer: Spree::Api::VariantSerializer
def on_hand
object.on_hand.nil? ? 0 : object.on_hand.to_f.finite? ? object.on_hand : "On demand"
end
def price
object.price.nil? ? '0.0' : object.price
end
def available_on
object.available_on.blank? ? "" : object.available_on.strftime("%F %T")
end
def permalink_live
object.permalink
end
end