Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi all,
I'm trying to list all products within a category the way they are sorted in uCommerce, but it seems like they are sorted by create date.
What I'm doing is this:
// Get a reference to the current category var currentCategory = SiteContext.Current.CatalogContext.CurrentCategory; <li class="dropdown"> <a href="@CatalogLibrary.GetNiceUrlForCategory(currentCategory)">@currentCategory.Name</a> <a data-toggle="dropdown" href="#"> <b class="caret"></b> </a> <ul class="dropdown-menu breadcrumb-dropdown"> @* Render products in current category *@ @foreach(var product in currentCategory.Products.Where(x => x.DisplayOnSite)) { <li> <a href="@CatalogLibrary.GetNiceUrlForProduct(product)">@product.Name</a> </li> } </ul> </li>
I tried to call .OrderBy(x => x...), but there's no sort order property on a product it seems :-) Have I missed something here?
Thanks in advance!
All the best,
Bo
You have to use the CategoryProductRelations to get the products sortOrder for the present category.
So something like:
var relations = category.CategoryProductRelations.OrderBy(x => x.SortOrder); return relations.Select(x => x.Product);
Genious, Nikolaj!
Thanks so much :-) Works like a charm!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
List products by sort order
Hi all,
I'm trying to list all products within a category the way they are sorted in uCommerce, but it seems like they are sorted by create date.
What I'm doing is this:
// Get a reference to the current category var currentCategory = SiteContext.Current.CatalogContext.CurrentCategory; <li class="dropdown"> <a href="@CatalogLibrary.GetNiceUrlForCategory(currentCategory)">@currentCategory.Name</a> <a data-toggle="dropdown" href="#"> <b class="caret"></b> </a> <ul class="dropdown-menu breadcrumb-dropdown"> @* Render products in current category *@ @foreach(var product in currentCategory.Products.Where(x => x.DisplayOnSite)) { <li> <a href="@CatalogLibrary.GetNiceUrlForProduct(product)">@product.Name</a> </li> } </ul> </li>I tried to call .OrderBy(x => x...), but there's no sort order property on a product it seems :-) Have I missed something here?
Thanks in advance!
All the best,
Bo
You have to use the CategoryProductRelations to get the products sortOrder for the present category.
So something like:
var relations = category.CategoryProductRelations.OrderBy(x => x.SortOrder); return relations.Select(x => x.Product);Genious, Nikolaj!
Thanks so much :-) Works like a charm!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.