Class: Spree::Admin::VariantsController

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

Instance Method Summary collapse

Methods inherited from ResourceController

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

Methods included from Core::ControllerHelpers::Common

included

Methods included from Core::ControllerHelpers::Auth

#current_ability, included, #redirect_back_or_default, #store_location, #try_spree_current_user, #unauthorized

Instance Method Details

#destroyObject

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



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

def destroy
  @variant = Variant.find(params[:id])
  @variant.deleted_at = Time.now()
  if @variant.save
    flash[:success] = I18n.t('notice_messages.variant_deleted')
  else
    flash[:success] = 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
# File 'app/controllers/spree/admin/variants_controller.rb', line 8

def index
  respond_with(collection)
end

#searchObject



12
13
14
15
# File 'app/controllers/spree/admin/variants_controller.rb', line 12

def search
  search_params = { :product_name_cont => params[:q], :sku_cont => params[:q] }
  @variants = Spree::Variant.ransack(search_params.merge(:m => 'or')).result
end