Commit 278f8b8518cafd86c28f47880f7a53f756f18855

Authored by Caio Formiga
1 parent 3971931c

Enterprises's catalog loading category breadcomb only if necessary

Enterprises's catalog is loaded through helper class and uses different
loading strategy (loading category or doesn't loadindg) and css style on
different views (on enterprises/catalog show breadcomb; on
homepage doesn't show)

(!ActionItem2600)
app/controllers/public/catalog_controller.rb
... ... @@ -5,15 +5,14 @@ class CatalogController < PublicController
5 5 before_filter :check_enterprise_and_environment
6 6  
7 7 def index
8   - @category = params[:level] ? ProductCategory.find(params[:level]) : nil
9   - @products = @profile.products.from_category(@category).paginate(:order => 'available desc, highlighted desc, name asc', :per_page => 9, :page => params[:page])
10   - @categories = ProductCategory.on_level(params[:level])
  8 + extend CatalogHelper
  9 + catalog_load_index
11 10 end
12 11  
13 12 protected
14 13  
15 14 def check_enterprise_and_environment
16   - unless @profile.kind_of?(Enterprise) && !@profile.environment.enabled?('disable_products_for_enterprises')
  15 + unless profile.kind_of?(Enterprise) && !profile.environment.enabled?('disable_products_for_enterprises')
17 16 redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index'
18 17 end
19 18 end
... ...
app/helpers/catalog_helper.rb
... ... @@ -3,9 +3,18 @@ module CatalogHelper
3 3 include DisplayHelper
4 4 include ManageProductsHelper
5 5  
  6 + def catalog_load_index options = {:page => params[:page], :show_categories => true}
  7 + if options[:show_categories]
  8 + @category = params[:level] ? ProductCategory.find(params[:level]) : nil
  9 + @categories = ProductCategory.on_level(params[:level])
  10 + end
  11 +
  12 + @products = profile.products.from_category(@category).paginate(:order => 'available desc, highlighted desc, name asc', :per_page => 9, :page => options[:page])
  13 + end
  14 +
6 15 def breadcrumb(category)
7   - start = link_to(_('Start'), {:action => 'index'})
8   - ancestors = category.ancestors.map { |c| link_to(c.name, {:action => 'index', :level => c.id}) }.reverse
  16 + start = link_to(_('Start'), {:controller => :catalog, :action => 'index'})
  17 + ancestors = category.ancestors.map { |c| link_to(c.name, {:controller => :catalog, :action => 'index', :level => c.id}) }.reverse
9 18 current_level = content_tag('strong', category.name)
10 19 all_items = [start] + ancestors + [current_level]
11 20 content_tag('div', all_items.join(' → '), :id => 'breadcrumb')
... ... @@ -15,7 +24,7 @@ module CatalogHelper
15 24 count = profile.products.from_category(category).count
16 25 name = truncate(category.name, :length => 22 - count.to_s.size)
17 26 link_name = sub ? name : content_tag('strong', name)
18   - link = link_to(link_name, {:action => 'index', :level => category.id}, :title => category.name)
  27 + link = link_to(link_name, {:controller => :catalog, :action => 'index', :level => category.id}, :title => category.name)
19 28 content_tag('li', "#{link} (#{count})") if count > 0
20 29 end
21 30  
... ...
app/models/enterprise_homepage.rb
... ... @@ -20,7 +20,8 @@ class EnterpriseHomepage < Article
20 20 enterprise_homepage = self
21 21 lambda do
22 22 extend EnterpriseHomepageHelper
23   - @products = profile.products.paginate(:order => 'id asc', :per_page => 9, :page => 1)
  23 + extend CatalogHelper
  24 + catalog_load_index :page => 1, :show_categories => false
24 25 render :partial => 'content_viewer/enterprise_homepage', :object => enterprise_homepage
25 26 end
26 27 end
... ...
app/views/catalog/index.rhtml
... ... @@ -3,22 +3,24 @@
3 3  
4 4 <h1><%= _('Products/Services') %></h1>
5 5  
6   -<%= breadcrumb(@category) if params[:level] %>
7   -
8   -<div class='l-sidebar-left-bar'>
9   - <ul>
10   - <% if @categories.size > 0 %>
11   - <% @categories.each do |category| %>
12   - <%= category_link(category) %>
13   - <%= category_sub_links(category) %>
  6 +<% if @categories %>
  7 + <%= breadcrumb(@category) if params[:level] %>
  8 +
  9 + <div class='l-sidebar-left-bar'>
  10 + <ul>
  11 + <% if @categories.size > 0 %>
  12 + <% @categories.each do |category| %>
  13 + <%= category_link(category) %>
  14 + <%= category_sub_links(category) %>
  15 + <% end %>
  16 + <% else %>
  17 + <%= content_tag('li', _('There are no sub-categories for %s') % @category.name, :style => 'color: #555753; padding-bottom: 0.5em;') %>
14 18 <% end %>
15   - <% else %>
16   - <%= content_tag('li', _('There are no sub-categories for %s') % @category.name, :style => 'color: #555753; padding-bottom: 0.5em;') %>
17   - <% end %>
18   - </ul>
19   -</div>
  19 + </ul>
  20 + </div>
  21 +<% end %>
20 22  
21   -<ul id="product-list" class="l-sidebar-left-content">
  23 +<ul id="product-list" class="<%="l-sidebar-left-content" if @categories %>">
22 24 <% @products.each do |product| %>
23 25 <% extra_content = @plugins.dispatch(:catalog_item_extras, product).collect { |content| instance_eval(&content) } %>
24 26 <% extra_content_list = @plugins.dispatch(:catalog_list_item_extras, product).collect { |content| instance_eval(&content) } %>
... ...