Copied to clipboard

Flag this post as spam?

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


  • Jeremy Wiersma 37 posts 134 karma points
    Sep 09, 2014 @ 13:15
    Jeremy Wiersma
    0

    Get products matching a specific tag, using typed methodology

    Hi folks,


    I'm trying to get a collection of items (products) where they contain a specific Category tag.

    The code I have is;

    IEnumerable getProducts = null;

    var categories = "";
    var productTags = "";
    var recordOrder = 1;

    // Assumes only one tag will be found as specified to Editors - ToDo: Tidy up validation here
    String[] categoryTags = Model.Content.GetPropertyValue("propCategoryTag").Split(',');

    foreach (var categoryTag in categoryTags)
    {
        categories += categoryTag + " ";
    }

    if (categories == "all")
    {
        getProducts = getProductsDatatype.Children.OfTypes("dtProduct").Where("propHide = false");
    }
    else
    {
       getProducts = getProductsDatatype.Children.OfTypes("dtProduct").Where("productCategoryTag = categories").Where("propHide = false");
    }

    foreach (var product in getProducts)
    {
    ..........

    So where I'm stuck is here;

    getProductsDatatype.Children.OfTypes("dtProduct").Where("productCategoryTag
     = categories").Where("propHide = false");

    What query can I use in a Where clause to match a Umbraco tag to a given string value in the above example?

    In the above code productCategoryTag = the tag datatype on the product which identifies it's parent category, and categories = the tag of the category I'm trying to match against.

    Your help is appreciated, and also a pointer to the best reference to learn more about these LINQ queries (are they also know as Lambda expressions?) and how to use them with Umbraco i.e. like a reference to umbraco specific methods, properties, etc.

     

    Thanks,
    Jeremy

     

     

  • Jeremy Wiersma 37 posts 134 karma points
    Sep 10, 2014 @ 13:36
    Jeremy Wiersma
    100

    I sorted this one out myself by going back to basics and breaking the steps down, ultimately realising that all I was doing was finding a partial string inside a larger string. Duhh.

    So the statement in question simply became;

    getProducts = getProductsDatatype.Children.OfTypes("dtProduct").Where("propProductCategoryTag.Contains(\"" + @categories.Trim() + "\")").Where("propHide = false");


    Woot, now onto the next bug :P

     

     

Please Sign in or register to post replies

Write your reply to:

Draft