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.

  • Tony Kiernan 278 posts 341 karma points
    Jul 27, 2011 @ 18:36
    Tony Kiernan
    0

    Variant sortOrder?

    How would I change the order variants are being listed?

  • Tony Kiernan 278 posts 341 karma points
    Oct 07, 2011 @ 12:00
    Tony Kiernan
    0

    So, I've created a variant property called SortOrder. How would I go about using that here:

    @foreach (Product myVariant in myVariants.OrderBy())
  • Tony Kiernan 278 posts 341 karma points
    Oct 26, 2011 @ 13:14
    Tony Kiernan
    0

    Anyone?  This:

    myVariants.OrderBy(v => v["SortOrder"].Value)

    Only, that will work

  • Tony Kiernan 278 posts 341 karma points
    Oct 26, 2011 @ 13:25
    Tony Kiernan
    0
    @foreach(Product myVariant in myVariants.OrderBy(v => v.ProductDefinitionField.Name == "SortOrder"))

    I can output that value as a string and it's what I want. Why can't I sort on it?

  • Tony Kiernan 278 posts 341 karma points
    Oct 26, 2011 @ 13:36
    Tony Kiernan
    0
    @foreach(Product myVariant in myVariants.OrderBy(v => v.ProductDefinitionField.Name == "SortOrder"))

    I can output that value as a string and it's what I want. Why can't I sort on it?

  • Tony Kiernan 278 posts 341 karma points
    Nov 04, 2011 @ 15:24
    Tony Kiernan
    0

    OK. For anyone lese that might be having the same problem; I used this query

    var variants = from product in Product.All()
                   join sort in ProductProperty.All()
                   on product.ProductId equals sort.ProductId
                   where product.ParentProductId == int.Parse(Request.QueryString["product"])
                       && product.AllowOrdering
                       && sort.ProductDefinitionField.Name == "SortOrder"
                   orderby sort.Value.Length == 1 ? "0" + sort.Value : sort.Value
                  
                   select product;
  • Søren Spelling Lund 1797 posts 2786 karma points
    Nov 07, 2011 @ 16:57
    Søren Spelling Lund
    0

    Hi Tony,

    The issue is probably that we store all the custom values as strings so you're ending up doing a alpha numerical sort. If you do a ToList on the query you'll be able to convert the value and sort it as a numeric value instead.

    var products = products.ToList();

    products = products.OrderBy(x => Convert.ToInt32(x["SortOrder"]));

  • Tony Kiernan 278 posts 341 karma points
    Nov 07, 2011 @ 18:08
    Tony Kiernan
    0
    Cannot implicitly convert type 'System.Linq.IOrderedEnumerable' 
    to 'System.Collections.Generic.List'.
    An explicit conversion exists (are you missing a cast?)

    It doesn't like that at all

  • Tony Kiernan 278 posts 341 karma points
    Nov 07, 2011 @ 18:15
    Tony Kiernan
    0

    Of course

    .OrderBy(x => Convert.ToInt32(x["SortOrder"].Value))

    On the foreach

  • Søren Spelling Lund 1797 posts 2786 karma points
    Nov 08, 2011 @ 12:38
    Søren Spelling Lund
    1

    Silly me. I keep forgetting :)

Please Sign in or register to post replies

Write your reply to:

Draft