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, #edit, #new, #update_positions

Instance Method Details

#cloneObject



57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/spree/admin/products_controller.rb', line 57

def clone
  @new = @product.duplicate

  if @new.save
    flash[:success] = t('spree.notice_messages.product_cloned')
  else
    flash[:error] = t('spree.notice_messages.product_not_cloned')
  end

  redirect_to edit_admin_product_url(@new)
end

#destroyObject



45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/spree/admin/products_controller.rb', line 45

def destroy
  @product = Spree::Product.friendly.find(params[:id])
  @product.discard

  flash[:success] = t('spree.notice_messages.product_deleted')

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

#indexObject



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

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

#showObject



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

def show
  redirect_to action: :edit
end

#updateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/spree/admin/products_controller.rb', line 22

def update
  if updating_variant_property_rules?
    params[:product][:variant_property_rules_attributes].each do |_index, param_attrs|
      param_attrs[:option_value_ids] = param_attrs[:option_value_ids].split(',')
    end
  end
  invoke_callbacks(:update, :before)
  if @object.update(permitted_resource_params)
    invoke_callbacks(:update, :after)
    flash[:success] = flash_message_for(@object, :successfully_updated)
    respond_with(@object) do |format|
      format.html { redirect_to location_after_save }
      format.js   { render layout: false }
    end
  else
    # Stops people submitting blank slugs, causing errors when they try to
    # update the product again
    @product.slug = @product.slug_was if @product.slug.blank?
    invoke_callbacks(:update, :fails)
    respond_with(@object)
  end
end