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

Cannot find product based on SKU through AdminWebservice

Started by Kim.Zeevaarders, November 09, 2011, 10:46:53 am

Previous topic - Next topic

Kim.Zeevaarders

Hello veryone,

I have an issue using the Admin webservices to retrieve a product based on the SKU. Whatever I try, it seems impossible to get the product.

    public AdminProduct getProductBySku(String sku) throws ServiceException {
        logger.debug("Searching adminproduct by sku: " + sku);

        int languageId = -1;
        try {
            String session = kk_admin.login(loginname, password);
            AdminDataDescriptor dataDesc = new AdminDataDescriptor();
            dataDesc.setLimit(1);
            AdminProductSearch search = new AdminProductSearch();
            search.setWhereToSearch(0);
            search.setCategoryId(-100);
            search.setSearchCategoryTree(true);
            search.setManufacturerId(-100);
            search.setPromotionId(-100);
            search.setProductType(-100);
            search.setSku(sku);
            search.setSkuRule(0);

            AdminProducts results = kk_admin.searchForProducts(session, dataDesc, search, languageId);
            if (results.getProductArray() != null & results.getProductArray().length == 1) {
                return results.getProductArray()[0];
            }
            logger.warn("Adminproduct with sku not found: " + sku);
            return null;
        }
        catch (RemoteException re) {
            throw new ServiceException("Unable to find a product by SKU", re);
        }
    }

Does anyone know how to properly implement this?

Regards,

Kim

trevor

If you are using our SOAP engine it should be as easy as doing:

            AdminProductSearch search = new AdminProductSearch();
            search.setSku(sku);
            search.setSkuRule(KKConstants.SEARCH_EXACT);

without having to set anything else. All other attributes will take default values.

Kim.Zeevaarders

After too much trail and error with SoapUI, I found a way to get some kind of results.

            AdminDataDescriptor dataDesc = new AdminDataDescriptor();
            dataDesc.setLimit(1);
            AdminProductSearch search = new AdminProductSearch();
            search.setCategoryId(-100);
            search.setPromotionId(-100);
            search.setManufacturerId(-100);
            search.setPaymentScheduleId(-1);
            search.setSku(sku);
            search.setSkuRule(0);

Does anyone understand why these 'default' values are not set when saying: AdminProductSearch search = new AdminProductSearch();

Even the limit defaults to 0 and results in zero results. So you should always set this to -1 or some big number to get some sort of results.

Regards,

Kim

trevor

What AdminDataDescriptor and AdminProductSearch classes are you using? Aren't they the ones we ship in konakartadmin.jar?

Kim.Zeevaarders

No all our classes are generated by JAX-WS based on the complextypes defined in the kkadmin WSDL. So we do not have konakart api's in our project. The only thing we do is fill objects and call webservice methods.

Do you mean that you can talkt to the admin API and that the admin API uses SOAP under water? How can we accomplish this?

In the konakart application you can do this by editing the konakart_app.properties (comment normal engine, uncomment kkwseng) but how do you do this for the kkadmin application?

Any help on this would be very appreciated :)

Regards,

Kim

kate

If you generate your classes from the WSDL there is no way they will pick up our default values when instantiated.

This is one of a few reasons why it's a whole lot easier just to instantiate a KonaKart web services client engine (eg com.konakartadmin.ws.KKWSAdmin etc) instead of creating your own classes from the WSDL.

Check the User Guide for the recommended approach on this.

I would only use my own generated classes from WSDL if I was not using java on the client side.   You can do this, but you have to understand that you won't get the default values set in your objects... plus you have to do all the SOAP plumbing yourself (which our engines take care of).

By contrast, if you use KKWSAdmin and KKWSEng the code you write is absolutely identical to the code you would write against KKAdmin and KKEng...   so the javadoc is identical etc etc.. so much easier.