Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 15, 2013 @ 15:54
    Bo Damgaard Mortensen
    0

    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

  • Nickolaj Lundgreen 233 posts 1132 karma points
    Jan 15, 2013 @ 16:05
    Nickolaj Lundgreen
    101

    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);

     

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 15, 2013 @ 16:11
    Bo Damgaard Mortensen
    0

    Genious, Nikolaj!

    Thanks so much :-) Works like a charm!

  • 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.

Please Sign in or register to post replies