Sha256: 93c7f717b73e2df4d02f7976b12ff06abde669e433aa005ea05d28744f4948e8

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

class TbCommerce::Api::ProductsController < TbCommerce::Api::BaseController
  
  before_action :load_product, :only => [:show, :options, :skus]

  def index
    @products = TbCommerce::Product.ordered
    if params[:category_id]
      @products = @products.where(:tb_commerce_category_id => params[:category_id])
    end
    render 'index'
  end

  def show
    render 'show'
  end

  # Get the skus for the current product
  #
  # Optionally pass an array of option ids, and get back only the SKUs that
  # have those options.
  #
  # ie,
  # /store/api/produdcts/1/skus.json?options[]=1&options[]=2
  #
  def skus
    @skus = @product.product_skus.includes(:images).ordered

    if params[:options]
      options = params[:options].map(&:to_i)
      @skus = @skus.with_option_ids(options)
    end

    render 'skus'
  end

  # Get a list of the available options, given a product and set of currently
  # selected options
  #
  def options
    # TODO: Return a list of possible configurations
  end

private

  def load_product
    @product = TbCommerce::Product.find_by!(:id => params[:id])
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tb_commerce-0.0.4 app/controllers/tb_commerce/api/products_controller.rb
tb_commerce-0.0.3 app/controllers/tb_commerce/api/products_controller.rb
tb_commerce-0.0.2 app/controllers/tb_commerce/api/products_controller.rb