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.

  • Filip Lundby 128 posts 149 karma points
    Feb 05, 2014 @ 09:53
    Filip Lundby
    0

    Listing variants and adding to basket when on a variantpage

    Hi,

    I'm linking to a variant in this way, which works fine:

    <a href="@CatalogLibrary.GetNiceUrlForVariant(variant, category, category.ProductCatalog)">Variant name</a>

     

    Now I've got two problems on the variantpage:

    1) How do I output the other variants on the variantpage? Variants only gets outputted on the master-product. This is what I use for listing variants:

    @foreach (var variant in product.Variants) 
    {
      <div>@variant.VariantSku</div>
    }

     

    2) When I try to add the variant to the basket/cart, umbDebugShowTrace tells me: "The product with SKU '1000000' contains variants, and cannot be added the basket. Add a specific variant instead.".
    So even when I'm on the variantpage I'll have to check if current product is a variant or a master-produkt...? If so, how would I do that?

  • Nickolaj Lundgreen 233 posts 1132 karma points
    Feb 05, 2014 @ 10:02
    Nickolaj Lundgreen
    100

    Hey skooter

    You can use the product.IsVariant propery, to check if the product you are using is a variant.

    When you are sure you have a variant you can use var parent = variant.ParentProduct and then: parent.Variants.Where(x=> x.Id != variantId.Id) to the other variants.

  • Filip Lundby 128 posts 149 karma points
    Feb 05, 2014 @ 10:55
    Filip Lundby
    0

    Thanks Nickolaj! So, something like:

    var variants = product.IsVariant ? product.ParentProduct.Variants : product.Variants;
    if (product.Variants.Any() || (product.IsVariant && product.ParentProduct.Variants.Any()))
    {
    foreach (var variant in variants) { ... }

    Umbraco validation tells me: "The name 'variants' does not exist in the current context" - on the foreach-line.

  • Nickolaj Lundgreen 233 posts 1132 karma points
    Feb 05, 2014 @ 11:23
    Nickolaj Lundgreen
    0

    Seems very right. Maybe a } got misplaced causing variants to be out of context in the foreach?

    The code snippet seems to work fine for me

  • Filip Lundby 128 posts 149 karma points
    Feb 05, 2014 @ 11:52
    Filip Lundby
    0

    Odd, can't get it to work. But it works with a "normal" if-statement. Will have to do for now :-/

Please Sign in or register to post replies

Write your reply to:

Draft