Sha256: 10cc563670b822571e49ae14315441bdd16179258abace884cbea3806f814def

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module Spree
  module Api
    module V2
      class ProductsController < Spree::Api::V2::BaseController
        skip_before_action :authenticate_user, only: [:index, :show]

        def index
          render_collection products.includes :variants, :master, :taxons, :option_types, master: :images
        end

        def show
          if params[:price_id]
            render_instance Spree::Price.find(params[:price_id]).product
          elsif params[:variant_id]
            render_instance Spree::Variant.find(params[:variant_id]).product
          elsif params[:image_id]
            render_instance Spree::Image.variants.find(params[:image_id]).viewable.product
          else
            render_instance products.friendly.find(params[:id])
          end
        end

        private

        def products
          if params[:taxon_id].present?
            Spree::Taxon.find(params[:taxon_id]).products
          elsif params[:option_type_id]
            Spree::OptionType.find(params[:option_type_id]).products
          else
            Spree::Product
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_json_api-0.3.1 app/controllers/spree/api/v2/products_controller.rb
solidus_json_api-0.3.0 app/controllers/spree/api/v2/products_controller.rb