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.

  • Rob Smith 34 posts 165 karma points
    Nov 21, 2013 @ 16:05
    Rob Smith
    0

    Sorting variants on the front end

    I am building a site which makes use of variants and shows them all in a nice big table on the shop.

    I had set up all the product definitions in Ucommerce and then had to change the ordering of them for the client in the back end to make it easier for them to edit. - nice and easy :)

    I checked the front end to the website and it hadn't replicated the new ordering there :(

    I have managed to change the headings for the table using the following:

    var uniqueVariants = from v in product.Variants.SelectMany(p => p.ProductProperties)
                         where v.ProductDefinitionField.DisplayOnSite
                         group v by v.ProductDefinitionField into g
                         orderby g.Key.SortOrder
                         select g;
    

    However I use the following for getting the variant data and putting it into a table which now means the column headers don't match the data as it isn't sorted.

    var product = SiteContext.Current.CatalogContext.CurrentProduct;
    
    @foreach (var prod in product.Variants)
    {
        <tr>
            @*
            Need to add some kind of orderby to the variants below
            *@
    
            @foreach (var b in prod.ProductProperties) {
                <td>@b.Value</td>
            }                                                           
        </tr>
    }
    

    I'm guessing i need to do someting like:

    @foreach (var b in prod.ProductProperties.Orderby(x = > "THE SORT ORDER OF THE BACKEND")) {
    

    But no idea as all I can get it do do is show an error page

    Has anybody got any ideas?

  • Jesper Nielsen 141 posts 498 karma points
    Nov 22, 2013 @ 13:25
    Jesper Nielsen
    101

    Hi Rob,

    Would something as simple as

    @foreach (var property in prod.ProductProperties.OrderBy(x => x.ProductDefinitionField.SortOrder)) {

    not work?

    Maybe I am missing something? :-)

    Kind regards,

    Jesper

  • Rob Smith 34 posts 165 karma points
    Nov 22, 2013 @ 14:13
    Rob Smith
    0

    Jesper, you're not missing anything that works perfectly!

    You are a star - thank you

Please Sign in or register to post replies

Write your reply to:

Draft