Class: Admin::ProductsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/products_controller.rb

Instance Method Summary collapse

Instance Method Details

#activateObject



81
82
83
# File 'app/controllers/admin/products_controller.rb', line 81

def activate
  render :text => @product.activate
end

#createObject

Create a Product

Params

  • id = ProductParent’s id

  • product = Hash of Product’s attributes



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

def create
  if @product.save && manage_dynamic_attributes
    flash[:notice] = I18n.t('product.create.success').capitalize
    redirect_to([forgeos_commerce, :edit, :admin, @product])
  else
    flash[:error] = I18n.t('product.create.failed').capitalize
    render :new
  end
end

#destroyObject

Destroy a Product

Params

  • id = Product’s id



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/admin/products_controller.rb', line 61

def destroy
  @deleted = @product.deleted? ? @product.destroy : @product.update_attribute(:deleted, true)

  if @deleted
    flash[:notice] = I18n.t('product.destroy.success').capitalize
  else
    flash[:error] = I18n.t('product.destroy.failed').capitalize
  end
  respond_to do |wants|
    wants.html do
      redirect_to([forgeos_commerce, :admin, :products])
    end
    wants.js
  end
end

#duplicateObject



26
27
28
29
# File 'app/controllers/admin/products_controller.rb', line 26

def duplicate
  @product = @product.clone
  render :action => 'new'
end

#editObject



45
46
# File 'app/controllers/admin/products_controller.rb', line 45

def edit
end

#get_cross_selling_idObject



91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/admin/products_controller.rb', line 91

def get_cross_selling_id
  product = Product.find_by_id(params[:product_id])
  cross_sellings = product.cross_sellings
  index = product.cross_sellings.count + 1
  cross_selling = Product.find_by_id(params[:cross_selling_id])
  cross_sellings.push(cross_selling)
  if product.update_attributes(:cross_sellings => cross_sellings)
    render :partial => 'cross_sell_tr', :locals => { :index => index, :pack => product, :product => cross_selling, :_class => params[:class]} 
  end
end

#indexObject



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

def index
  respond_to do |format|
    format.html
    format.json do
      sort
      render :layout => false
    end
  end
end

#newObject



23
24
# File 'app/controllers/admin/products_controller.rb', line 23

def new
end

#showObject



20
21
# File 'app/controllers/admin/products_controller.rb', line 20

def show
end

#updateObject



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

def update
  if @product.update_attributes(params[:product]) && manage_dynamic_attributes
    flash[:notice] = I18n.t('product.update.success').capitalize
    redirect_to([forgeos_commerce, :edit, :admin, @product])
  else
    flash[:error] = I18n.t('product.update.failed').capitalize
    render :action => 'edit'
  end
end

#update_attributes_listObject



85
86
87
88
89
# File 'app/controllers/admin/products_controller.rb', line 85

def update_attributes_list
  product_type = ProductType.find_by_id(params[:product_type_id])
  product = Product.find_by_id(params[:id])
  render :partial => 'attributes', :locals => { :product_type => product_type, :product => product }
end

#urlObject



77
78
79
# File 'app/controllers/admin/products_controller.rb', line 77

def url
  render :text => Forgeos::url_generator(params[:url])
end