From 082a5c3364139ddc4047ca508c29719caa627089 Mon Sep 17 00:00:00 2001 From: AurĂ©lio A. Heckert Date: Fri, 14 Jun 2013 19:02:13 -0300 Subject: [PATCH] Enable side blocks on product catalog --- app/controllers/my_profile/profile_design_controller.rb | 1 + app/controllers/public/catalog_controller.rb | 1 - app/helpers/application_helper.rb | 2 ++ app/helpers/catalog_helper.rb | 18 +++++++++++------- app/models/box.rb | 1 + app/models/product_categories_block.rb | 24 ++++++++++++++++++++++++ app/views/blocks/product_categories.html.erb | 12 ++++++++++++ app/views/catalog/index.rhtml | 17 ----------------- public/stylesheets/application.css | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- 9 files changed, 146 insertions(+), 58 deletions(-) create mode 100644 app/models/product_categories_block.rb create mode 100644 app/views/blocks/product_categories.html.erb diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index 69b7a62..280a6f0 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -32,6 +32,7 @@ class ProfileDesignController < BoxOrganizerController if profile.enterprise? blocks << DisabledEnterpriseMessageBlock blocks << HighlightsBlock + blocks << ProductCategoriesBlock blocks << FeaturedProductsBlock blocks << FansBlock blocks += plugins.dispatch(:extra_blocks, :type => Enterprise) diff --git a/app/controllers/public/catalog_controller.rb b/app/controllers/public/catalog_controller.rb index cd75f73..9998e84 100644 --- a/app/controllers/public/catalog_controller.rb +++ b/app/controllers/public/catalog_controller.rb @@ -1,6 +1,5 @@ class CatalogController < PublicController needs_profile - no_design_blocks before_filter :check_enterprise_and_environment diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1cfa75c..a732061 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -36,6 +36,8 @@ module ApplicationHelper include LayoutHelper + include CatalogHelper + def locale (@page && !@page.language.blank?) ? @page.language : FastGettext.locale end diff --git a/app/helpers/catalog_helper.rb b/app/helpers/catalog_helper.rb index b6c3da1..81e79e6 100644 --- a/app/helpers/catalog_helper.rb +++ b/app/helpers/catalog_helper.rb @@ -11,20 +11,24 @@ module CatalogHelper content_tag('div', all_items.join(' → '), :id => 'breadcrumb') end - def category_link(category, sub = false) + def category_link(category) count = profile.products.from_category(category).count name = truncate(category.name, :length => 22 - count.to_s.size) - link_name = sub ? name : content_tag('strong', name) - link = link_to(link_name, {:action => 'index', :level => category.id}, :title => category.name) - content_tag('li', "#{link} (#{count})") if count > 0 + link = link_to(name, {:controller => 'catalog', :action => 'index', :level => category.id}, :title => category.name) + content_tag('div', "#{link} #{count}") if count > 0 end - def category_sub_links(category) + def category_with_sub_list(category) + content_tag 'li', "#{category_link(category)}\n#{sub_category_list(category)}" + end + + def sub_category_list(category) sub_categories = [] category.children.order(:name).each do |sub_category| - sub_categories << category_link(sub_category, true) + cat_link = category_link sub_category + sub_categories << content_tag('li', cat_link) unless cat_link.nil? end - content_tag('ul', sub_categories) if sub_categories.size > 1 + content_tag('ul', sub_categories) if sub_categories.size > 0 end end diff --git a/app/models/box.rb b/app/models/box.rb index f8022a7..4b53130 100644 --- a/app/models/box.rb +++ b/app/models/box.rb @@ -61,6 +61,7 @@ class Box < ActiveRecord::Base MyNetworkBlock, PeopleBlock, ProductsBlock, + ProductCategoriesBlock, ProfileImageBlock, ProfileInfoBlock, ProfileSearchBlock, diff --git a/app/models/product_categories_block.rb b/app/models/product_categories_block.rb new file mode 100644 index 0000000..8ee5dc8 --- /dev/null +++ b/app/models/product_categories_block.rb @@ -0,0 +1,24 @@ +class ProductCategoriesBlock < Block + + def self.description + _('Product category menu') + end + + # the title of the block. Probably will be overriden in subclasses. + def default_title + _('Catalog') + end + + def help + _('Helps to filter the products catalog.') + end + + def content(args={}) + profile = owner + lambda do + categories = @categories || ProductCategory.on_level().order(:name) + render :file => 'blocks/product_categories', :locals => {:profile => profile, :categories => categories} + end + end + +end diff --git a/app/views/blocks/product_categories.html.erb b/app/views/blocks/product_categories.html.erb new file mode 100644 index 0000000..a17559c --- /dev/null +++ b/app/views/blocks/product_categories.html.erb @@ -0,0 +1,12 @@ +<%= link_to _('Catalog start'), profile.catalog_url, :class=>'catalog-home-link' %> +<% if categories.present? %> + +<% elsif @category.present? %> +
<%= _('There are no sub-categories for %s') % @category.name %>
+<% else %> +
<%= _('There are no categories available.') %>
+<% end %> diff --git a/app/views/catalog/index.rhtml b/app/views/catalog/index.rhtml index f5baa9f..27eab6d 100644 --- a/app/views/catalog/index.rhtml +++ b/app/views/catalog/index.rhtml @@ -5,23 +5,6 @@ <%= breadcrumb(@category) if params[:level] %> - -