Welcome to Mediachase Community Sign in | Join | Help    
in Search   

How to get Metafield ID based on value ?

Last post Wed, Sep 24 2008, 6:27 AM by Nadya. 7 replies.
Sort Posts: Previous Next
  •  Thu, Sep 18 2008, 4:02 AM 10310

    How to get Metafield ID based on value ?

    Hello,

    Is there a way to retrieve the ID of a meta attribute from a product ? Assuming the meta attribute is a dictionary type.

    Thanks,
    Victor
  •  Thu, Sep 18 2008, 1:44 PM 10320 in reply to 10310

    Re: How to get Metafield ID based on value ?

    We are looking into this and will post a response as soon as we can.

    Mediachase Software
  •  Fri, Sep 19 2008, 12:23 AM 10322 in reply to 10310

    Re: How to get Metafield ID based on value ?

    What do you need it for?
    ItemAttribute has Name property which uniquely identifies the MetaField.
  •  Fri, Sep 19 2008, 12:33 AM 10323 in reply to 10322

    Re: How to get Metafield ID based on value ?

    Well, it's a bit tricky.

    Since searching in dictionary meta fields doesn't work like it was suppose to work, i need to search by the ID value of the attribute. Not the text value. The MetaKey from MetaMultiDictionary table.

    I need it to search for products with the same attribute value.
  •  Fri, Sep 19 2008, 1:42 AM 10326 in reply to 10323

    Re: How to get Metafield ID based on value ?

    victorgunta:
    Since searching in dictionary meta fields doesn't work like it was suppose to work

    How do you suppose it should work?

       MetaKey field in MetaMultiDictionary table is intended for MetaData internal use. However, value of MetaField of type DictionaryMultiValue is array of MetaDictionaryItem, and MetaDictionaryItem has Id property which you can use to compare values.

  •  Fri, Sep 19 2008, 3:42 AM 10327 in reply to 10326

    Re: How to get Metafield ID based on value ?

    The situation is like this :

    I have a meta attribute of type Dictionary (with multiple selections) named "Author".

    When i use SearchProducts with KeyValues pair if i use "Author|=|John Doe" it doesn't return anything. In my opinion this is the way it had to work.

    But if i use "Author|=|10133" it does work. Well, partially. Because the 10133 value is the corresponding author of a single book. So the search returns only one result, not all the books of this author.

    So i have to make a reverse query, based on "John Doe" to find all the metaKeys of this attribute, create a list of KeyValue pairs and use them to get all the books of this author.
  •  Fri, Sep 19 2008, 3:48 AM 10328 in reply to 10327

    Re: How to get Metafield ID based on value ?

    This is how i do it :

            public int PageCount = 0;
            public int ItemsPerPage = 6;
            public int TotalRecords = 0;
            public string AuthorFilter = "John Doe";

            public KeyValueAttribute[] GetMetaFieldIDs(string MetaName, string MetaValue)
            {
                DataCommand cmd = new DataCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "SELECT t1.MetaKey FROM MetaMultiValueDictionary AS t1, MetaDictionary AS t2 WHERE t1.MetaDictionaryId = t2.MetaDictionaryId AND t2.Value = '" + MetaValue + "'";

                DataTable dataTable = DataService.LoadTable(cmd);

                if (dataTable.Rows.Count > 0)
                {
                    KeyValueAttribute[] filterValues = new KeyValueAttribute[dataTable.Rows.Count];

                    int i = 0;
                    foreach (DataRow row in dataTable.Rows)
                    {
                        filterValues[i] = new KeyValueAttribute(MetaName, "=", ((int)row["MetaKey"]).ToString());
                        i++;
                    }
                    ItemsPerPage = i;

                    return filterValues;
                }
                else
                {
                    return null;
                }
            }

            public void PerformSearch()
            {
                ErrorsError[] errors = new ErrorsError[] { };

                KeyValueAttribute[] kva = GetMetaFieldIDs("Author", AuthorFilter);

                Items items = ClientCatalog.SearchProducts("Carte", String.Empty, new string[] { "Author" }, kva, 109, true, 0, 0, "Name", true, ItemsPerPage, 0, new string[] { "ItemAttributes", "ItemMetaAttributes" }, ref TotalRecords, ref errors);

                if (items != null)
                {
                    ProductList.DataSource = items.Item;
                    ProductList.DataBind();
                }  
            }
  •  Wed, Sep 24 2008, 6:27 AM 10355 in reply to 10328

    Re: How to get Metafield ID based on value ?

    Hi,

       Unfortunately, there's no easy way to search through multiValueDictionary attributes but I would advice you to do so:

       When passing KeyValueAttribute array, you can use any SQL statement as "value". In your case, only one KeyValueAttribute is needed:

       new KeyValueAttribute(metaFieldName, "IN", "(SELECT DISTINCT MetaKey FROM [MetaMultiValueDictionary] MVD INNER JOIN [MetaDictionary] MD ON MVD.[MetaDictionaryId]=MD.[MetaDictionaryId] WHERE MD.[Value] LIKE 'some author')");

    Hope this helps.

    Nadya.

View as RSS news feed in XML
Site Terms | Privacy Policy | About Us | Contact Us
Running on Mediachase eCommerce Framework 4.0.
  Copyright © Mediachase, LTD. 1997-2006. All Rights Reserved

E-commerce, HelpDesk, Service Desk & Project Management Software, alternatives to Microsoft Project Server & Sharepoint Collaboration Server
project management software | microsoft project server | sharepoint collaboration server | issues management, helpdesk & service desk
Powered by Community Server, by Telligent Systems