• Welcome to KonaKart Community Forum. Please login or sign up.
 

How do I lookup a product by SKU (Client and Server).

Started by GrapeApe, December 03, 2008, 12:08:19 am

Previous topic - Next topic

GrapeApe

Howdy,

I was wondering if there was a way to use the API to look up a product by sku (via the client or server apis)?  Or would I need to create a custom SQL query for this?

Thanks!
-Big Ol' Purple Gorilla

julie

Howdy Big and Old Purple Gorilla,

You can use the Admin App API to search for a product using the SKU . The method is searchForProducts() and the SKU that you want to search for is defined in the AdminProductSearchObject.

ReLLiK75

Interesting that the admin search will always return a more accurate result set then the regular search, but good to know!

trevor


ReLLiK75

Hi Trevor...

Well, performing a similar search using the server API will fail to return a search result.  For Example:

       public Products searchForProducts ( String searchText)
        {
            DataDescriptor dataDescriptor = new DataDescriptor ();
            dataDescriptor.limit = 5;
            dataDescriptor.offset = 0;
            dataDescriptor.showInvisible = true;
            dataDescriptor.custom1 = searchText;

            ProductSearch productSearch = new ProductSearch ();
            productSearch.searchInSubCats = true;
            //productSearch.searchText = searchText;
            productSearch.whereToSearch = -100;
            productSearch.manufacturerId = -100;
            productSearch.categoryId = -100;

            try
            {
                int customerID = kkServerApi.checkSession ( KKSessionID );
                return kkServerApi.searchForProducts( KKSessionID,dataDescriptor, productSearch, -1 );
            }
            catch (Exception ex)
            {
                throw new Exception ( ex.Message );
            }
        }


will not return a result while:

       public AdminProducts adminProductSearch(String searchText)
        {

            AdminDataDescriptor adminDataDescriptor = new AdminDataDescriptor();
            AdminProductSearch adminProductSearch = new AdminProductSearch();

            //adminProductSearch.searchText = searchText;
            adminProductSearch.categoryId = -100;
            adminProductSearch.manufacturerId = -100;
            adminProductSearch.promotionId = -100;
            adminProductSearch.productType = -100;
            adminProductSearch.whereToSearch = -100;


            adminDataDescriptor.limit = 5;
            adminDataDescriptor.offset = 0;
            adminDataDescriptor.custom1 = searchText;
            adminDataDescriptor.showInvisible = true;
            adminDataDescriptor.showInactive = true;

            if (adminSessionID == null)
                adminSessionID = kkAdminApi.login(adminUserName, adminPassword);

            return kkAdminApi.searchForProducts(adminSessionID, adminDataDescriptor, adminProductSearch, -1);
        }


will return a result. I don't know why.  I've got products that have similar names so just using the searchText parameter and searching within the product name will return too many results.  To work around this, I append a unique ID from the system that is actually driving product creation within KK to the custom1 field.  I would expect setting the custom1 field in dataDescriptor in the regular search would return a result, but for whatever reason, it does not.  AdminSearch, however, does.

Wayne

trevor

Are the returned products inactive (status==0) by any chance ?

ReLLiK75

Hi Trevor..

The products I get back from the AdminSearch have a status=1. 

trevor

Do you see the products if you run our demo app on your database ?

ReLLiK75

Ahhh!!  Interestingly enough, when I do a search through the KK demo web-site, if I enter a valid value in custom1 (on the advanced search page), it will return the correct object.  The java APIs are obviously a bit different in the way they behave than the SOAP APIs, so I wonder if there may be something happening on the SOAP side of things.  I would have expected it to be an issue with my code, but considering the fact that almost the exact same block of code making Admin API calls works, leads me to believe otherwise.

Wayne

sashwill

Since custom1 is already searchable in the app, I just added the descriptor that I wanted to identify the product to the custom1 field.  Its a bit of data duplication, but seems to work OK for me.