Commit 22eb134c865ce554c595dc048cfb8e72fd9bf054

Authored by Aurélio A. Heckert
1 parent f1bd3825

List root product categories if no sub-categories

ProductCategoriesBlock will be never empty
ActionItem896
app/models/product_categories_block.rb
@@ -16,8 +16,20 @@ class ProductCategoriesBlock < Block @@ -16,8 +16,20 @@ class ProductCategoriesBlock < Block
16 def content(args={}) 16 def content(args={})
17 profile = owner 17 profile = owner
18 lambda do 18 lambda do
19 - categories = @categories || ProductCategory.on_level().order(:name)  
20 - render :file => 'blocks/product_categories', :locals => {:profile => profile, :categories => categories} 19 + if @categories.nil? or @categories.length == 0
  20 + categories = ProductCategory.on_level().order(:name)
  21 + if @categories and @categories.length == 0
  22 + notice = _('There are no sub-categories for %s') % @category.name
  23 + end
  24 + else
  25 + categories = @categories
  26 + end
  27 + render :file => 'blocks/product_categories',
  28 + :locals => {
  29 + :profile => profile,
  30 + :categories => categories,
  31 + :notice => notice
  32 + }
21 end 33 end
22 end 34 end
23 35
app/views/blocks/product_categories.html.erb
1 <%= link_to _('Catalog start'), profile.catalog_url, :class=>'catalog-home-link' %> 1 <%= link_to _('Catalog start'), profile.catalog_url, :class=>'catalog-home-link' %>
2 -<% if categories.present? %>  
3 <ul class="catalog-categories-list"> 2 <ul class="catalog-categories-list">
4 <% categories.each do |category| %> 3 <% categories.each do |category| %>
5 <%= category_with_sub_list(category) %> 4 <%= category_with_sub_list(category) %>
6 <% end %> 5 <% end %>
7 </ul> 6 </ul>
8 -<% elsif @category.present? %>  
9 - <div class="catalog-categories-notice"><%= _('There are no sub-categories for %s') % @category.name %></div>  
10 -<% else %>  
11 - <div class="catalog-categories-notice"><%= _('There are no categories available.') %></div> 7 +<% if notice %>
  8 + <div class="catalog-categories-notice"><%= notice %></div>
12 <% end %> 9 <% end %>