Copied to clipboard

Flag this post as spam?

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


  • Supun Livera 8 posts 102 karma points
    Apr 22, 2016 @ 21:48
    Supun Livera
    0

    Search for Extended data

    Hi All,

    How can I search for products in Merchello using extended data.

    Ex.

    I have the following extended data on products.

    enter image description here

    How can I do a search on them, say get all products with a length > 500?

    Thanks in advance for your help.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Apr 25, 2016 @ 14:22
    Rusty Swayne
    0

    Hi Supun,

    The dimensions are not stored in the ExtendedDataCollection, they are proper properties on IProduct and are also exposed on ProductDisplay and IProductContent.

  • Supun Livera 8 posts 102 karma points
    Apr 25, 2016 @ 17:02
    Supun Livera
    0

    Hi Rusty,

    Thanks for the reply.

    Unfortunately we have them as extended properties with some other fields :(.

    As a workaround, I'm the doing it the following way which is not very efficient.

                var queryResult = _merchello.Query.Product.Search(1, 150).Items.Select(x => (ProductDisplay)x)
                .Where(
                    x =>
                        x.DetachedContents.Any(s=>CompareSize(s.DetachedDataValues, length, depth, width)));
    

    And inside the CompareSize I do the following:

        private static bool CompareSize(IEnumerable<KeyValuePair<string, string>> valuePairs, decimal length, decimal height, decimal width)
        {
            var detachedValues = valuePairs.ToDictionary(s => s.Key);
    
            if (!detachedValues.Any())
            {
                return false;
            }
    
            if (!(detachedValues.ContainsKey("width") || detachedValues.ContainsKey("height") || detachedValues.ContainsKey("length")))
            {
                return false;
            }
    
            var productWidth= detachedValues.ContainsKey("width") && !string.IsNullOrEmpty(detachedValues["width"].Value) ? Convert.ToDecimal(detachedValues["width"].Value.Replace("\"", "")) :  0.0m;
            var productHeight = detachedValues.ContainsKey("height") && !string.IsNullOrEmpty(detachedValues["height"].Value) ? Convert.ToDecimal(detachedValues["height"].Value.Replace("\"", "")) : 0.0m;
            var productLength = detachedValues.ContainsKey("length") && !string.IsNullOrEmpty(detachedValues["length"].Value) ? Convert.ToDecimal(detachedValues["length"].Value.Replace("\"", "")) : 0.0m;
    
            if (productHeight == 0 && detachedValues.ContainsKey("depth") && !string.IsNullOrEmpty(detachedValues["depth"].Value))
            {
                productHeight = Convert.ToDecimal(detachedValues["depth"].Value.Replace("\"", ""));
            }
    
    
            if (productHeight >= height && productHeight <= height + 50)
            {
                if (productWidth >= width && productWidth <= width + 50)
                {
                    if (productLength >= length && productLength <= length + 50)
                    {
                        return true;
                    }
                }
    

    And so on, another requirement is that the search should pick up products with what ever pattern the user entered them on.

    ie:

    W -> W, H->H, L->L and also W->H, H->W, L->L and other permutations.

    Thanks for your help in advance.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Apr 27, 2016 @ 15:28
    Rusty Swayne
    0

    Hey Supun,

    If your going to do it through detached content, I think I might create a custom DataType and respective PropertyValueConverter so that you don't have to interact directly with the "detachedValues" higher up in the stack.

    This would allow you to return a typed model in the IProductContent property associated with the new DataType.

  • Supun Livera 8 posts 102 karma points
    Apr 27, 2016 @ 20:08
    Supun Livera
    0

    Thanks Rusty, I'll give it a go. If it's not too much trouble can you give me a pointer as to how to associate it with a Merchello Product?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Apr 27, 2016 @ 23:09
    Rusty Swayne
    0

    Sure thing Supun,

    You would associate your property with a Merchello product by adding it to a document type that is used to extend the Merchello Product.

    https://merchello.readme.io/docs/product-content-types

  • Supun Livera 8 posts 102 karma points
    Apr 27, 2016 @ 23:11
    Supun Livera
    1

    Thanks Rusty, will give it a go.

    Cheers.

Please Sign in or register to post replies

Write your reply to:

Draft