Created
December 28, 2012 15:53
-
-
Save michiels/4399048 to your computer and use it in GitHub Desktop.
Before code for OrganizationsController
This file contains hidden or 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
class OrganizationsController < ApplicationController | |
def show | |
@notification = notification_for_current_user | |
@categories = Category.top_level | |
@category = nil | |
if params[:category_id] | |
@category = Category.visible.find(params[:category_id]) | |
end | |
@categories = Category.top_level.visible.orderd_by_name.find(:all, :include => :visible_children) | |
category_translations = CategoryTranslation.find(:all, :conditions => {:category_id => @categories}) | |
sub_categories = Category.visible.ordered_by_name.find(:all, :conditions => {:category_id => @categories}) | |
@sub_categories_per_category = {} | |
sub_categories.each do |sub_category| | |
@sub_categories_per_category[sub_category.category_id] ||= [] | |
@sub_categories_per_category[sub_category.category_id] << sub_category | |
end | |
translations_by_category = {} | |
category_translations.each do |category_translation| | |
translations_by_category[category_translation.category_id] = category_translation | |
end | |
@categories.each do |category| | |
category.set_translation translations_by_category[category.id] | |
end | |
@products = Product.upcoming.active.includes(:product_prices).where('product_prices.active = 1').paginate :per_page => 50, :page => params[:page] | |
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 | |
respond_to do |format| | |
format.html do | |
if ENV["SITE_ALIAS"] | |
render :layout => ENV["SITE_ALIAS"]+ "/order_system" | |
else | |
render :layout => "order_system" | |
end | |
end | |
format.json do | |
json_products = [] | |
@products.each do |product| | |
json_products << {:name => product.name, :url => product_url(product), :thumbnail_url => product.image.url(:medium) } | |
end | |
render :json => json_products | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment