Commit 32510c0a5e907db1b4dfa4f9ba436ebe564fba21
1 parent
e69c983e
Exists in
master
and in
22 other branches
Sorting catalog categories by name
(ActionItem2606)
Showing
3 changed files
with
19 additions
and
2 deletions
Show diff stats
app/controllers/public/catalog_controller.rb
... | ... | @@ -7,7 +7,7 @@ class CatalogController < PublicController |
7 | 7 | def index |
8 | 8 | @category = params[:level] ? ProductCategory.find(params[:level]) : nil |
9 | 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]) | |
10 | + @categories = ProductCategory.on_level(params[:level]).order(:name) | |
11 | 11 | end |
12 | 12 | |
13 | 13 | protected | ... | ... |
app/helpers/catalog_helper.rb
... | ... | @@ -21,7 +21,7 @@ module CatalogHelper |
21 | 21 | |
22 | 22 | def category_sub_links(category) |
23 | 23 | sub_categories = [] |
24 | - category.children.each do |sub_category| | |
24 | + category.children.order(:name).each do |sub_category| | |
25 | 25 | sub_categories << category_link(sub_category, true) |
26 | 26 | end |
27 | 27 | content_tag('ul', sub_categories) if sub_categories.size > 1 | ... | ... |
test/functional/catalog_controller_test.rb
... | ... | @@ -224,4 +224,21 @@ class CatalogControllerTest < ActionController::TestCase |
224 | 224 | assert_tag :tag => 'li', :attributes => {:id => "product-#{p2.id}", :class => /not-available/} |
225 | 225 | end |
226 | 226 | |
227 | + should 'sort categories by name' do | |
228 | + environment = @enterprise.environment | |
229 | + environment.categories.destroy_all | |
230 | + pc1 = ProductCategory.create!(:name => "Drinks", :environment => environment) | |
231 | + pc2 = ProductCategory.create!(:name => "Bananas", :environment => environment) | |
232 | + pc3 = ProductCategory.create!(:name => "Sodas", :environment => environment) | |
233 | + pc4 = ProductCategory.create!(:name => "Pies", :environment => environment) | |
234 | + p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id) | |
235 | + p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id) | |
236 | + p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id) | |
237 | + p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) | |
238 | + | |
239 | + get :index, :profile => @enterprise.identifier | |
240 | + | |
241 | + assert_equal [pc2, pc1, pc4, pc3], assigns(:categories) | |
242 | + end | |
243 | + | |
227 | 244 | end | ... | ... |