Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

DataObject as Page sorting by categories

Go to End

4 Posts   1117 Views


Community Member, 96 Posts

11 April 2012 at 9:33pm

Edited: 11/04/2012 9:48pm

He guys,

I´ve made an product catalogue following this tutorial:

Now I have an Page where all products from all categories are listed. My problem is, I can´t figure out how to sort my products on the CategoryPage by categories and then by the title of the product, so that the products from one category are standing together.
I try to modify the getProductsList-function like this:

public function getProductsList()
return $this->Products(Null, 'Category.Title ASC, Title ASC');

I can´t figure out, how to call the category from the products.

Does anyone have a solution? I hope the problem is clear.


Community Member, 545 Posts

12 April 2012 at 2:14am

Are you using the DataObjectAsPage Module? It simplifies some of the work.

But if you're already looping though your products in the template you can do the sort right in the template by using the built in GroupedBy.

<% control Products.GroupedBy(Category)  %>
<% control Children %>
..product info..
<% end_control %>
<% end_control %>

and I'm pretty sure you can <% control Children.SortBy() %> in the template as well


Community Member, 96 Posts

12 April 2012 at 8:03am

Thanks for reply. No, I don´t use the module. Start working on the project before the module came out.
I followed the tutorial and used that code.

GroupBy(Category) and SortBy(Category) doesn´t work:
<% control Products.GroupBy(Category) %>
<div class="produktthumb">
<a href="$Link">
<span class="price">$Price</span>
<div class="clear"></div>
<% end_control %>

<% control Products.GroupBy(Category) %> and <% control Products.SortBy(Category) %> only returns nothing.
<% control Products.GroupedBy(CategoryPage) %> and <% control Products.GroupedBy(Categories.ID) %> returns only one product.


Community Member, 545 Posts

12 April 2012 at 8:13am

You need a <% control Children %> control inside your GroupBy. The function creates a new DataObjectSet. You can use $Debug inside a control to help you determine what available to you