Sha256: cac803ce38bbfe5aaabda4be8dddaed081f6e246946bf48f4e04683e46106a90

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

class ProductsController < Spree::BaseController
  before_filter :setup_admin_user

  resource_controller
  helper :taxons  
  before_filter :load_data, :only => :show
  actions :show, :index

  index do
    before do
      @product_cols = 3
    end
  end

  def change_image
    @product = Product.available.find_by_param(params[:id])
    img = Image.find(params[:image_id])
    render :partial => 'image', :locals => {:image => img}
  end

  private
  def setup_admin_user
    return if admin_created?
    flash[:notice] = I18n.t(:please_create_user)
    redirect_to signup_url
  end
  
  def load_data    
    return unless permalink = params[:taxon_path]
    @taxon = Taxon.find_by_permalink(params[:taxon_path].join("/") + "/")
  end
  
  def collection
    if params[:taxon]
      @taxon = Taxon.find(params[:taxon])
      
      @search = Product.active.scoped(:conditions =>
                                        ["products.id in (select product_id from products_taxons where taxon_id in (" +
                                          @taxon.descendents.inject( @taxon.id.to_s) { |clause, t| clause += ', ' + t.id.to_s} + "))"
                                        ]).new_search(params[:search])
    else
      @search = Product.active.new_search(params[:search])
    end

    @search.per_page = Spree::Config[:products_per_page]
    @search.include = :images

    @product_cols = 3
    @products ||= @search.all
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spree-0.8.5 app/controllers/products_controller.rb