Copied to clipboard

Flag this post as spam?

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


  • Wesley de Roo 38 posts 142 karma points
    Jan 05, 2016 @ 21:17
    Wesley de Roo
    0

    Get TypeContent from Variant

    Hi,

    Is it possible to get typecontent from product variants, when i try:

    IProductContent productContent = merchelloHelper.TypeProductContentBySku(masterProduct.Sku); 
    

    I get content, when i try:

    IProductContent productVariantContent = merchelloHelper.TypeProductContentBySku(variantProduct.Sku);
    

    productVariantContent is null. If noticed there is IProductVariantContent, but I can't find something like merchelloHelper.TypeProductVariantContentBySku

    Best, Wesley

  • Wesley de Roo 38 posts 142 karma points
    Jan 06, 2016 @ 08:13
    Wesley de Roo
    0

    Found it,

    It seems that a IProductContent has a collection of IProductVariantContent which could be found either by SKU or selected option choices.

    https://github.com/Merchello/Merchello/issues/1486

    So based on BazaarSiteApiController in the Bazaar example store

    I now have this code that works:

        var product = _merchello.Query.Product.GetByKey(productKey);
        var variant = product.GetProductVariantDisplayWithAttributes(optionsArray);
    
        IProductContent masterProductContent = null;
        IProductVariantContent variantProductContent = null;
        masterProductContent = _merchello.TypeProductContentBySku(product.Sku);
        variantProductContent = masterProductContent.ProductVariants.First(x => x.Key == variant.Key);
    
  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 06, 2016 @ 16:57
    Rusty Swayne
    100

    @Wesley

    You should be able to

     var masterProductContent = _merchello.TypedProductContent(productKey);
    var variantProductContent = masterProductContent.ProductVariants.First(x => ...
    
  • Wesley de Roo 38 posts 142 karma points
    Jan 07, 2016 @ 07:26
    Wesley de Roo
    1

    Thanks Rusty, will try that out!

Please Sign in or register to post replies

Write your reply to:

Draft