Class: Spree::Admin::AddOnMakerVariantsController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/admin/add_on_maker_variants_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/spree/admin/add_on_maker_variants_controller.rb', line 32

def create
  @add_on_maker_variant = Spree::AddOnMakerVariant.new(add_on_maker_variant_params.merge(:variant_id => params[:variant_id]))
  respond_to do |format|
    if @add_on_maker_variant.save
      flash[:success] = t('add_on.notice_messages.admin_product_variant_add_on_maker_variant_created')
      format.html { redirect_to admin_product_variant_add_on_maker_variants_path }
      format.json { render action: 'index', status: :created, location: @add_on_maker_variant }
    else
      flash[:error] = t('add_on.notice_messages.admin_product_variant_add_on_maker_variant_has_error')
      format.html { render action: 'new' }
      format.json { render json: @add_on_maker_variant.errors }
    end
  end
end

#destroyObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/spree/admin/add_on_maker_variants_controller.rb', line 61

def destroy
  @variant = Spree::Variant.find(params[:id])
  if @variant.destroy
    flash[:success] = Spree.t('notice_messages.variant_deleted')
  else
    flash[:success] = Spree.t('notice_messages.variant_not_deleted')
  end

  respond_with(@variant) do |format|
    format.html { redirect_to admin_product_maker_variant_path(params[:product_id]) }
    format.js  { render_js_for_destroy }
  end
end

#editObject



25
26
27
28
29
30
# File 'app/controllers/spree/admin/add_on_maker_variants_controller.rb', line 25

def edit
  session[:return_to] = request.url
  @product = Spree::Product.find_by_permalink!(params[:product_id])
  @add_on_maker_variant = Spree::AddOnMakerVariant.where(:variant_id => params[:variant_id]).first_or_initialize
  render :edit
end

#indexObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/spree/admin/add_on_maker_variants_controller.rb', line 11

def index
  session[:return_to] = request.url
  @product = Spree::Product.where(:permalink => params[:product_id]).includes(:add_on_makers).first

  if @product.has_variants?
    @variant = @product.variants
  else
    @variant = Spree::Variant.where(:id => @product.master.id)
  end

  @add_on_maker_variant = Spree::AddOnMakerVariant.where(:variant_id => @variant).page(params[:page])
  render :index
end

#showObject



6
7
8
9
# File 'app/controllers/spree/admin/add_on_maker_variants_controller.rb', line 6

def show
  session[:return_to] ||= request.referer
  redirect_to( :action => :edit )
end

#updateObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/spree/admin/add_on_maker_variants_controller.rb', line 47

def update
  respond_to do |format|
    if @add_on_maker_variant.update(add_on_maker_variant_params)
      flash[:success] = t('add_on.notice_messages.admin_product_variant_add_on_maker_variant_updated')
      format.html { redirect_to :action => :index }
      format.json { head :no_content }
    else
      flash[:error] = t('add_on.notice_messages.admin_product_variant_add_on_maker_variant_has_error')
      format.html { render action: 'edit' }
      format.json { render json: @add_on_maker_variant.errors }
    end
  end
end