Sha256: f2314af3c3885a5845615b06029e1ca3a12de37874d5c377a5914f1b3e6a4f37

Contents?: true

Size: 1.73 KB

Versions: 10

Compression:

Stored size: 1.73 KB

Contents

module Spree
  module V2
    module Storefront
      class ProductSerializer < BaseSerializer
        include ::Spree::Api::V2::DisplayMoneyHelper

        set_type :product

        attributes :name, :description, :available_on, :slug, :meta_description, :meta_keywords, :updated_at

        attribute :purchasable do |product|
          product.purchasable?
        end

        attribute :in_stock do |product|
          product.in_stock?
        end

        attribute :backorderable do |product|
          product.backorderable?
        end

        attribute :available do |product|
          product.available?
        end

        attribute :currency do |_product, params|
          params[:currency]
        end

        attribute :price do |product, params|
          price(product, params[:currency])
        end

        attribute :display_price do |product, params|
          display_price(product, params[:currency])
        end

        attribute :compare_at_price do |product, params|
          compare_at_price(product, params[:currency])
        end

        attribute :display_compare_at_price do |product, params|
          display_compare_at_price(product, params[:currency])
        end

        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

10 entries across 10 versions & 1 rubygems

Version Path
spree_api-4.2.7 app/serializers/spree/v2/storefront/product_serializer.rb
spree_api-4.2.6 app/serializers/spree/v2/storefront/product_serializer.rb
spree_api-4.2.5 app/serializers/spree/v2/storefront/product_serializer.rb
spree_api-4.2.4 app/serializers/spree/v2/storefront/product_serializer.rb
spree_api-4.2.3.1 app/serializers/spree/v2/storefront/product_serializer.rb
spree_api-4.2.3 app/serializers/spree/v2/storefront/product_serializer.rb
spree_api-4.2.2 app/serializers/spree/v2/storefront/product_serializer.rb
spree_api-4.2.1 app/serializers/spree/v2/storefront/product_serializer.rb
spree_api-4.2.0 app/serializers/spree/v2/storefront/product_serializer.rb
spree_api-4.2.0.rc5 app/serializers/spree/v2/storefront/product_serializer.rb