mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
Moving spree namespaced serializers into admin
This commit is contained in:
@@ -65,7 +65,7 @@ Spree::Api::ProductsController.class_eval do
|
||||
end
|
||||
|
||||
def render_paged_products(products)
|
||||
render text: { products: ActiveModel::ArraySerializer.new(products, each_serializer: Spree::Api::ProductSerializer), pages: products.num_pages }.to_json
|
||||
render text: { products: ActiveModel::ArraySerializer.new(products, each_serializer: Api::Admin::ProductSerializer), pages: products.num_pages }.to_json
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -47,7 +47,7 @@ module Admin
|
||||
end
|
||||
|
||||
def admin_inject_products
|
||||
admin_inject_json_ams_array "ofn.admin", "products", @products, Spree::Api::ProductSerializer
|
||||
admin_inject_json_ams_array "ofn.admin", "products", @products, Api::Admin::ProductSerializer
|
||||
end
|
||||
|
||||
def admin_inject_taxons
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
class Spree::Api::ProductSerializer < ActiveModel::Serializer
|
||||
class Api::Admin::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
|
||||
has_many :variants, key: :variants, serializer: Api::Admin::VariantSerializer # embed: ids
|
||||
has_one :master, serializer: Api::Admin::VariantSerializer
|
||||
|
||||
def on_hand
|
||||
object.on_hand.nil? ? 0 : object.on_hand.to_f.finite? ? object.on_hand : "On demand"
|
||||
@@ -1,4 +1,4 @@
|
||||
class Spree::Api::VariantSerializer < ActiveModel::Serializer
|
||||
class Api::Admin::VariantSerializer < ActiveModel::Serializer
|
||||
attributes :id, :options_text, :unit_value, :unit_description, :unit_to_display, :on_demand, :display_as, :display_name, :name_to_display
|
||||
attributes :on_hand, :price
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
describe Spree::Api::ProductSerializer do
|
||||
describe Api::Admin::ProductSerializer do
|
||||
let(:product) { create(:simple_product) }
|
||||
it "serializes a product" do
|
||||
serializer = Spree::Api::ProductSerializer.new product
|
||||
serializer = Api::Admin::ProductSerializer.new product
|
||||
serializer.to_json.should match product.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
describe Spree::Api::VariantSerializer do
|
||||
describe Api::Admin::VariantSerializer do
|
||||
let(:variant) { create(:variant) }
|
||||
it "serializes a variant" do
|
||||
serializer = Spree::Api::VariantSerializer.new variant
|
||||
serializer = Api::Admin::VariantSerializer.new variant
|
||||
serializer.to_json.should match variant.options_text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user