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, biapar, Willr, Ingo, swaiba, simon_w

DataObject as Page sorting by categories


Reply


4 Posts   771 Views

Avatar
Bereusei

Community Member, 94 Posts

11 April 2012 at 9:33pm

Edited: 11/04/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.

Avatar
zenmonkey

Community Member, 528 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) %>
$Title
<% control Children %>
..product info..
<% end_control %>
<% end_control %>

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

Avatar
Bereusei

Community Member, 94 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">
                  <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.

Avatar
zenmonkey

Community Member, 528 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