Sha256: 62ee2cbfb8bf632793eb208609c4a801ab457b9445d0d008c79c8817e40410eb

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

module Spree
  module V2
    module Storefront
      class ProductSerializer < BaseSerializer
        set_type :product

        attributes :name, :description, :price, :currency, :display_price,
                   :compare_at_price, :display_compare_at_price, :available_on,
                   :slug, :meta_description, :meta_keywords, :updated_at

        attribute :purchasable,   &:purchasable?
        attribute :in_stock,      &:in_stock?
        attribute :backorderable, &:backorderable?
        attribute :available,     &:available?

        has_many :variants
        has_many :option_types
        has_many :product_properties
        has_many :taxons

        # all images from all variants
        has_many :images,
          object_method_name: :variant_images,
          id_method_name: :variant_image_ids,
          record_type: :image,
          serializer: :image

        has_one  :default_variant,
          object_method_name: :default_variant,
          id_method_name: :default_variant_id,
          record_type: :variant,
          serializer: :variant
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spree_api-4.2.0.rc2 app/serializers/spree/v2/storefront/product_serializer.rb
spree_api-4.2.0.rc1 app/serializers/spree/v2/storefront/product_serializer.rb
spree_api-4.2.0.beta app/serializers/spree/v2/storefront/product_serializer.rb