Class: Spree::Admin::ProductsController

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

Instance Method Summary collapse

Methods inherited from ResourceController

belongs_to, create, #create, destroy, #edit, #new, new_action, 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

#cloneObject



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

def clone
  @new = @product.duplicate

  if @new.save
    flash.notice = I18n.t('notice_messages.product_cloned')
  else
    flash.notice = I18n.t('notice_messages.product_not_cloned')
  end

  respond_with(@new) { |format| format.html { redirect_to edit_admin_product_url(@new) } }
end

#destroyObject



37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/spree/admin/products_controller.rb', line 37

def destroy
  @product = Product.find_by_permalink!(params[:id])
  @product.delete

  flash.notice = I18n.t('notice_messages.product_deleted')

  respond_with(@product) do |format|
    format.html { redirect_to collection_url }
    format.js  { render_js_for_destroy }
  end
end

#indexObject



16
17
18
19
# File 'app/controllers/spree/admin/products_controller.rb', line 16

def index
  session[:return_to] = request.url
  respond_with(@collection)
end

#searchObject



21
22
23
24
25
26
27
28
# File 'app/controllers/spree/admin/products_controller.rb', line 21

def search
  if params[:ids]
    @products = Spree::Product.where(:id => params[:ids].split(","))
  else
    search_params = { :name_cont => params[:q], :sku_cont => params[:q] }
    @products = Spree::Product.ransack(search_params.merge(:m => 'or')).result
  end
end

#showObject



11
12
13
14
# File 'app/controllers/spree/admin/products_controller.rb', line 11

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

#updateObject



30
31
32
33
34
35
# File 'app/controllers/spree/admin/products_controller.rb', line 30

def update
  if params[:product][:taxon_ids].present?
    params[:product][:taxon_ids] = params[:product][:taxon_ids].split(',')
  end
  super
end