Copied to clipboard

Flag this post as spam?

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


  • Jim 22 posts 163 karma points
    May 03, 2016 @ 09:27
    Jim
    0

    List all variants of a product

    Hello,

    Im trying to get a list of color variants specified on a product in the product list-view, I have tried to use:

          @foreach (var product in Model.Content.Children()){ [...]
    
        @foreach (var variant in TC.GetVariants(1, product, true)){ [...]
    }
    }
    

    But I dont get any data from it.

    Thanks in advance. Cheers!

  • Rune Grønkjær 1371 posts 3102 karma points
    May 03, 2016 @ 11:18
    Rune Grønkjær
    100

    Hi Jim,

    And you are sure that the Children all have variants and the variants are valid?

    This code works on the demo website:

    @foreach ( var variant in TC.GetVariants( 1, productPage, true ) ) {

    @(TC.GetPropertyValue

    }

    Check it out here: https://demo.teacommerce.net/expensive-yachts/summer-yacht/

    /Rune

  • Jim 22 posts 163 karma points
    May 03, 2016 @ 11:44
    Jim
    0

    Hi,

    Well, I dont get anything in my loop, what is required for a variant? I have, like the demo site, variant groups => variant group => variant type and in my product I have a variant tab where I can choose different colors and add name, stock etc. But somehow they don't connect to the GetVariants? Thanks!

    /Jim

  • Rune Grønkjær 1371 posts 3102 karma points
    May 03, 2016 @ 12:08
    Rune Grønkjær
    0

    Have you named your properties and doc types the same as in the demo website? It might be looking after the variant property in the wrong place.

    And i guess you are using the "Tea Commerce: Variant Editor"? Just checking :)

    /Rune

  • Jim 22 posts 163 karma points
    May 03, 2016 @ 12:40
    Jim
    0

    I have named the properties and doc types the same as in the demo. I also have been using The Tea Commerce Variant Editor! :)

    if I try this:

    @foreach (var item in Model.Content.GetPropertyValue<string>("variants"))
    {
        @item
    }
    

    I get:

    A { "variants": [ { "id": "abaaa4c1-ad2f-c889-fef5-2c4db19a20cc", "documentTypeAlias": "Variant", "validation": { "holesInVariants": false, "duplicatesFound": false }, "properties": { "stock": "", "ProductName": "", "sku": "", "price": "" }, "combination": [ { "name": "Black", "id": 1143, "groupName": "Färger", "groupId": 1139 } ] }, { "id": "67659ca9-d9ed-0e66-3d79-5f38413df267", "documentTypeAlias": "Variant", "validation": { "holesInVariants": false, "duplicatesFound": false }, "properties": { "stock": "", "ProductName": "", "sku": "", "price": "" }, "combination": [ { "name": "Green", "id": 1146, "groupName": "Färger", "groupId": 1139 } ] }, { "id": "993f8192-5024-4792-87f3-6476f3a80ba9", "documentTypeAlias": "Variant", "validation": { "holesInVariants": false, "duplicatesFound": false }, "properties": { "stock": "", "ProductName": "", "sku": "", "price": "" }, "combination": [ { "name": "Orange", "id": 1147, "groupName": "Färger", "groupId": 1139 } ] } ], "variantGroupsOpen": { "1139": true } }
    

    Any ideas? :) Thanks!

    /Jim

  • Rune Grønkjær 1371 posts 3102 karma points
    May 03, 2016 @ 13:17
    Rune Grønkjær
    0

    And what does your code look like? The one you're using to GetVariants.

    Looks like the data is there.

  • Jim 22 posts 163 karma points
    May 03, 2016 @ 15:32
    Jim
    1

    Hello!

    I managed to solve it...! I forgot to fill in the "Product variant property alias" in the Tea commerce settings.

    Thanks for your help!

    /Jim

  • Jim 22 posts 163 karma points
    May 03, 2016 @ 13:22
    Jim
    0

    Trying different things, but the same as the one in the demo:

    @foreach (var variant in TC.GetVariants(1, Model.Content, true))
    {
    
        <div>
            @(TC.GetPropertyValue<string>(1, productPage, "sku", variant.VariantId))
        </div>
    }
    

    /Jim

  • Rune Grønkjær 1371 posts 3102 karma points
    May 04, 2016 @ 06:18
    Rune Grønkjær
    0

    Great. Good work.

    Cheers /Rune

Please Sign in or register to post replies

Write your reply to:

Draft