Copied to clipboard

Flag this post as spam?

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


  • TRiV 4 posts 74 karma points
    Jul 06, 2017 @ 16:25
    TRiV
    0

    Sort Order by Date

    How can I sort products by date? CreateDate and UpdateDate fields of IProductContent always same for all products. Can anybody help with it?

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jul 12, 2017 @ 17:13
    Dennis Aaen
    0

    Hi TRiV and welcome to Our.

    Would it be possible for you to share the code that you have right now to pull out the products.

    By sharing the code, then people can try to help you with a specific example.

    Best,

    /Dennis

  • TRiV 4 posts 74 karma points
    Jul 13, 2017 @ 16:37
    TRiV
    0

    Hi Dennis!

    Code snippet:

    ProductCollection currentCollection = ...getting current collection...
    var childCollections = currentCollection.Children().OrderBy(x => x.SortOrder);
    IEnumerable<IProductContent> products = childCollections.SelectMany(x => x.GetProducts()).Union(currentCollection.GetProducts()).DistinctBy(x => x.Key);
    
    var temp = products;
    
    switch (filter.SortOrder)
    {
        case SortOrder.FromNewToOld:
            {
                temp = temp.OrderByDescending(x => x.CreateDate);
                break;
            }
        case SortOrder.FromOldToNew:
            {
                temp = temp.OrderBy(x => x.CreateDate);
                break;
            }
        case SortOrder.LowPriceToHighPrice:
            {
                temp = temp.OrderBy(x => x.Price);
                break;
            }
        case SortOrder.HighPriceToLowPrice:
            {
                temp = temp.OrderByDescending(x => x.Price);
                break;
            }
    }
    

    Sort order not work, b/c "CreateDate" always same for all products. Same thing with "UpdateDate". Can anyone help with it?

    Thanks,

    TRiV!

  • Phelipp Ferreira da Silva 5 posts 95 karma points
    Jan 21, 2019 @ 12:02
    Phelipp Ferreira da Silva
    0

    Did you find any solution?

Please Sign in or register to post replies

Write your reply to:

Draft