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

Methods included from Core::ControllerHelpers

included

Instance Method Details

#cloneObject



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

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

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
# File 'app/controllers/spree/admin/products_controller.rb', line 19

def destroy
  @product = Product.find_by_permalink!(params[:id])
  @product.update_attribute(:deleted_at, Time.now)

  @product.variants_including_master.update_all(:deleted_at => Time.now)

  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



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

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