Created
December 28, 2012 15:48
-
-
Save michiels/4399011 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index | |
@organization = current_user.organization || Organization.new | |
if params[:q] | |
page_number = params[:page] || 1 | |
per_page = 50 | |
@products = Product.search(params[:q]).active.includes(:product_prices).where('product_prices.active = 1', true) | |
if current_user.searches_are_not_logged == false | |
SearchResult.create(:keyword => params[:q], :user_id => current_user.id, :number_of_results => @products.size) | |
end | |
else # We are displaying products in a category. | |
raise ActiveRecord::RecordNotFound if @category.nil? | |
@sub_categories = @category.visible_children | |
category_ids = [@category] + @sub_categories | |
@products = Product.active.includes(:product_prices).where('product_prices.active = 1', true).joins(:category_labels).where(["categories_products.category_id IN (?)", category_ids]) | |
end | |
if params[:sort] == "product_name" | |
if params[:direction] == "desc" | |
@products = @products.order("products.name desc") | |
else | |
@products = @products.order("products.name asc") | |
end | |
elsif params[:sort] == "shop_code" | |
if params[:direction] == "desc" | |
@products = @products.order("products.final_article_number_cache desc") | |
else | |
@products = @products.order("products.final_article_number_cache asc") | |
end | |
else | |
if ENV['SITE_ALIAS'].nil? | |
# Sort based on product description for Stofzuigermarkt | |
@products = @products.order("products.name") | |
else | |
@products = @products.order('products.final_article_number_cache') | |
end | |
end | |
@products = @products.paginate :per_page => 50, :page => params[:page] | |
if request.xhr? | |
render :partial => "load_more", :layout => false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment