7911 Posts in 1354 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » DataObject as Page sorting by categories
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 458 Views |
-
DataObject as Page sorting by categories

11 April 2012 at 9:33pm Last edited: 11 April 2012 9:48pm
He guys,
I´ve made an product catalogue following this tutorial: http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-2-using-model-admin-and-url-segments-to-create-a-product-catalogue/
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.
-
Re: DataObject as Page sorting by categories

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) %>
$Title
<% control Children %>
..product info..
<% end_control %>
<% end_control %>and I'm pretty sure you can <% control Children.SortBy() %> in the template as well
-
Re: DataObject as Page sorting by categories

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">
<h2>$Title</h2>
<span class="price">$Price</span>
<div class="clear"></div>
$Image.CroppedImage(250,175)
</a>
</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. -
Re: DataObject as Page sorting by categories

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
| 458 Views | ||
|
Page:
1
|
Go to Top |


