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.

  • Vilius Janulis 38 posts 79 karma points
    Mar 07, 2013 @ 11:03
    Vilius Janulis
    0

    Variant options : disable option and order options

    Hi,

    Already finishing one pretty nice uCommerce solution. My second one :)

    But have few pretty hard core at least for me questions, redarding variants and variant options.

    Have created all options i need (actually two - color and size) and two additional ones (witch i marked not to show on website).

    These are disable (checkbox) and SortOrder (number).

    I am using standard razor show and all its functionalities.

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

     

    @foreach (var prop in uniqueVariants){
    var controlName = string.Format("variation-{0}", prop.Key.Name.ToLower());

    }

     

    1.  Quetion is how i can make it with that Linq/Lambda or etc to sort variant options by field SortOrder if they are filled in

    2.  How can i not show variant options with disable button checked.

     

    Thanks

  • Nickolaj Lundgreen 233 posts 1132 karma points
    Mar 07, 2013 @ 14:07
    Nickolaj Lundgreen
    0

    1.

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

    Im not sure this is what you are looking for - but give it a go (not testet - im not sure how Nhibernate handle the ProductDefinitionField.Get )

     

     

  • Vilius Janulis 38 posts 79 karma points
    Mar 07, 2013 @ 14:59
    Vilius Janulis
    0

    Thanks for answer sadly did not worked :(

    You example gave me some more ideas witch non of them worked too ... So ... back to squere one :)

    And basiclly it is because it tries to sort variants and i want to sort variant options :)

     

    So i assume that at least for 1. some additions need to be done in these lines :

    foreach (var value in prop.Select(p => p.Value).Distinct())
  • Nickolaj Lundgreen 233 posts 1132 karma points
    Mar 07, 2013 @ 15:35
    Nickolaj Lundgreen
    0

    I don't know what i was think with the ProductDefinitionField.Get ^^

     

        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;

    This should do the correct sorting (it did i my test ) :)

  • Vilius Janulis 38 posts 79 karma points
    Mar 07, 2013 @ 15:45
    Vilius Janulis
    0

    Hey Nickolaj,

    Really thanks for you help :)

    Sadly :S did not worked for me :S just to be sure posting a variant structure of mine, and did you understood like that ?

    You said it wokrs for you ? :)

    Hm ...

     

    Using exactely the same as you :S

     

     

     

     

  • Nickolaj Lundgreen 233 posts 1132 karma points
    Mar 07, 2013 @ 15:57
    Nickolaj Lundgreen
    0

    Ohh. Mine is sorting by the SortOrder on the ProductDefinitionField so that's why it is not working for you.

    Im not quite sure what you are trying to do. You are listing the productProperties, but are trying to order the variants sortOrder property.

    What do you want in the dropdown list?

     

    On another node. I would advice using the enum datatype for "Storrelse" and "Farve" to get a better data structure :)

  • Vilius Janulis 38 posts 79 karma points
    Mar 07, 2013 @ 16:15
    Vilius Janulis
    0

    hey Nickolaj,

    Sorry fot not full explanation :) and i can see there is a bug in forum showing full code from me :) 

    Here it is :

    @foreach (var prop in uniqueVariants){
    var controlName = string.Format("variation-{0}", prop.Key.Name.ToLower());
    <label for="@controlName">@prop.Key.GetDisplayName()</label>
    <select name="@controlName" id="@controlName" class="variant">
    <option value="">-- Vælg venligst --</option>
    @foreach (var value in prop.Select(p => p.Value).Distinct()){
    <option value="@value">@value</option>
    }
    </select>
    }

    Why i am doing this, is that client adds as size (S,L,XL) and then he gets also or remembers that he needs to add M too, so if he whant to get them in nice order he has to delete L and XL add M and then add back L and XL, since variant combinations are not sortable.

    And what i want to do is to allow him to set order number so it would be ordered correctly.

    And i am not listing product properties i am listing variants by setting select tag on every property and the it has option tag for every variant option. And what i need is to be able to sort these variant options in that select tag :)

     p.s. this predefined and code styles do not listen to me :P

    Thanks

     

  • Vilius Janulis 38 posts 79 karma points
    Mar 11, 2013 @ 15:30
    Vilius Janulis
    0

    bump :)

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Mar 12, 2013 @ 11:39
    David Brendel
    0

    I'm not sure if i understand you right, but to sort the variants by a cusotm property you can just use linq and do something like that:

    < select name="size"> @foreach(var v in product.Variants.OrderBy(x => x["sortOrder"])) { < option value="@v.VariantSku" >@v.Name } 
    

    Not tested but that should do it.

Please Sign in or register to post replies

Write your reply to:

Draft