Copied to clipboard

Flag this post as spam?

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


  • Robert Dyson 50 posts 147 karma points c-trib
    Apr 05, 2016 @ 11:28
    Robert Dyson
    0

    Price Sorting

    Hi,

    I'm trying to implement sorting of a list of products. I have a product list in the form List

    productList.OrderBy(x => x.SalePrice)
    
    productList.OrderBy(x => x.Price)
    

    However without creating classes for my products with calculated parameters. Is there a simple way to sort this by the "effective" Price. So that if it's not on sale it uses the normal price, if it is on sale it uses the Sale Price?

    Please let me know if this is available.. Otherwise I would very much like to see this included (or could even add it myself on GitHub?)

    Thanks!

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Apr 05, 2016 @ 19:52
    Rusty Swayne
    100

    Hey Robert,

    There is nothing in the Core to do that at the moment, but that's a really good idea.

    It would be a simple extension method to write:

       public static decimal EffectivePrice(this IProductContent product) 
       {
              return product.OnSale ? product.SalePrice : product.Price;
       }
    
  • Robert Dyson 50 posts 147 karma points c-trib
    Apr 06, 2016 @ 11:25
    Robert Dyson
    0

    Yes, This solves it nicely, thanks for the quick assistance. I'm loving Merchello.

Please Sign in or register to post replies

Write your reply to:

Draft