Class: Kms::Catalog::VariantsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/kms/catalog/variants_controller.rb

Instance Method Summary collapse

Instance Method Details

#available_option_typesObject



32
33
34
35
36
37
# File 'app/controllers/kms/catalog/variants_controller.rb', line 32

def available_option_types
  @product = Product.find_by_id(params[:product_id])
  @variant = Variant.find_by_id(params[:id])
  @option_types = @product.option_types - @variant.option_values.map(&:option_type)
  render json: @option_types.to_json
end

#createObject



15
16
17
18
# File 'app/controllers/kms/catalog/variants_controller.rb', line 15

def create
  @variant = Variant.create(variant_params.merge({product_id: params[:product_id]}))
  render json: @variant.to_json
end

#destroyObject



26
27
28
29
30
# File 'app/controllers/kms/catalog/variants_controller.rb', line 26

def destroy
  @variant = Variant.find_by_id(params[:id])
  @variant.destroy
  render json: @variant.to_json
end

#indexObject



4
5
6
7
8
# File 'app/controllers/kms/catalog/variants_controller.rb', line 4

def index
  @product = Product.find_by_id(params[:product_id])
  @variants = @product.variants
  render json: @variants.to_json
end

#showObject



10
11
12
13
# File 'app/controllers/kms/catalog/variants_controller.rb', line 10

def show
  @variant = Variant.find_by_id(params[:id])
  render json: @variant.to_json
end

#updateObject



20
21
22
23
24
# File 'app/controllers/kms/catalog/variants_controller.rb', line 20

def update
  @variant = Variant.find(params[:id])
  @variant.update_attributes(variant_params)
  render json: @variant.to_json
end