Sha256: 0910e71c9c0902e214f01d4b3e6c6f62e6c334f4610a8f995493769b537fe553

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

class Spree::Admin::PartsController < Spree::Admin::BaseController
  before_filter :find_product

  def index
    @parts = @product.parts
  end

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

  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

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

  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

  private
    def find_product
      @product = Spree::Product.find_by(slug: params[:product_id])
    end

    def model_class
      Spree::AssembliesPart
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_product_assembly-1.0.0 app/controllers/spree/admin/parts_controller.rb