Class: Spree::Admin::VariantsController

Inherits:
ResourceController show all
Defined in:
app/controllers/spree/admin/variants_controller.rb

Instance Attribute Summary

Attributes included from Core::ControllerHelpers

#title

Instance Method Summary collapse

Methods inherited from ResourceController

belongs_to, create, #create, destroy, #edit, #new, new_action, update, #update

Methods included from Core::ControllerHelpers

#access_forbidden, included

Instance Method Details

#destroyObject

override the destory method to set deleted_at value instead of actually deleting the product.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/spree/admin/variants_controller.rb', line 17

def destroy
  @variant = Variant.find(params[:id])

  @variant.deleted_at = Time.now()
  if @variant.save
    flash.notice = I18n.t('notice_messages.variant_deleted')
  else
    flash.notice = I18n.t('notice_messages.variant_not_deleted')
  end

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

#indexObject



8
9
10
11
12
13
# File 'app/controllers/spree/admin/variants_controller.rb', line 8

def index
  respond_with(collection) do |format|
    format.html
    format.json { render :json => json_data }
  end
end

#update_positionsObject



33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/spree/admin/variants_controller.rb', line 33

def update_positions
  params[:positions].each do |id, index|
    Variant.where(:id => id).update_all(:position => index)
  end

  respond_with(@variant) do |format|
    format.html { redirect_to admin_product_variants_url(params[:product_id]) }
    format.js  { render :text => 'Ok' }
  end
end