Class: Spree::Admin::PartsController

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

Instance Method Summary collapse

Instance Method Details

#availableObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/spree/admin/parts_controller.rb', line 22

def available
  if params[:q].blank?
    @available_products = []
  else
    query = "%#{params[:q]}%"
    @available_products = Spree::Product.search_can_be_part(query).distinct
  end
  respond_to do |format|
    format.html { render layout: false }
    format.js { render layout: false }
  end
end

#createObject



35
36
37
38
39
40
# File 'app/controllers/spree/admin/parts_controller.rb', line 35

def create
  @part = Spree::Variant.find(params[:part_id])
  qty = params[:part_count].to_i
  @product.add_part(@part, qty) if qty > 0
  render 'spree/admin/parts/update_parts_table'
end

#indexObject



6
7
8
# File 'app/controllers/spree/admin/parts_controller.rb', line 6

def index
  @parts = @product.parts
end

#removeObject



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

def remove
  @part = Spree::Variant.find(params[:id])
  @product.remove_part(@part)
  render 'spree/admin/parts/update_parts_table'
end

#set_countObject



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

def set_count
  @part = Spree::Variant.find(params[:id])
  @product.set_part_count(@part, params[:count].to_i)
  render 'spree/admin/parts/update_parts_table'
end