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

KKAdmin API getOrders Filtering

Started by AndreiN, January 17, 2014, 03:08:16 pm

Previous topic - Next topic

AndreiN

Hello,

I am trying to download orders through the KKAdmin API, using the getOrders method. When I set the AdminOrderSearch parameter to null, all orders are retrieved (as expected). My other search parameters are: offset set to zero to start, size at 50, and the language id is set to the store default, which I retrieve at run time.

However, I wish to filter the orders retrieved by various criteria such as Create Date, Create Date Range, OrderNumber, and OrderId. When I set, for example, the OrderId property to target a particular order, nothing is retrieved. The same happens when attempting to filter by dateAddedFrom, dateAddedTo, or any other criteria (that I have tried). It was my understanding that any properties of the AdminOrderSearch object that I do not set are simply ignored by the search (as per http://www.konakart.com/javadoc/admin/com/konakartadmin/app/AdminOrderSearch.html), however something clearly isn't working.

I have played around with it for a few hours, but to no avail. Can anyone give me an idea as to why this isn't working? Are there any compulsory AdminOrderSearch properties that must be set in order for the search to go through?

Thanks in advance!

ming

Not sure what's wrong in your case but here are a few examples from our unit tests that work:


           
        // See if there are any orders there
        AdminOrderSearch search = new AdminOrderSearch();
        AdminOrderSearchResult orders = eng.getOrders(getTheSetupSession, search, 0, 1, -1);

        // Use search rules
        search.setCustomerName("Fre");
        search.setCustomerNameRule(KKConstants.SEARCH_EXACT);
        result = eng.getOrders(getTheSetupSession(), search, 0, 100, -1);

        search = new AdminOrderSearch();
        search.setCustomerCity("Bedrock");
        result = eng.getOrders(getTheSetupSession(), search, 0, 100, -1);

        search = new AdminOrderSearch();
        search.setCustomerEmail("fred@flinstone.com");
        result = eng.getOrders(getTheSetupSession(), search, 0, 100, -1);

        search = new AdminOrderSearch();
        search.setCustomerName("Fred Bloggs");
        search.setOrderStatusId(2);
        result = eng.getOrders(getTheSetupSession(), search, 0, 100, -1);

        search = new AdminOrderSearch();
        search.setCustomerName("Fred Bloggs");
        search.setOrderStatusId(2);
        search.setCustomerId(1);
        result = eng.getOrders(getTheSetupSession(), search, 0, 100, -1);

        search = new AdminOrderSearch();
        search.setCustomerName("Fred Bloggs");
        search.setOrderStatusId(2);
        search.setCustomerId(1);
        search.setCustom1("cu1");
        search.setCustom2("cu2");
        search.setCustom3("cu3");
        search.setCustom4("cu4");
        search.setCustom5("cu5");
        search.setOrderNumber("12345");
        result = eng.getOrders(getTheSetupSession(), search, 0, 100, -1);

        /*
         * Finished Date
         */

        Calendar startC = new GregorianCalendar(2005, 01, 01);
        Calendar endC = new GregorianCalendar(2007, 01, 01);

        search = new AdminOrderSearch();
        search.setDateFinishedFrom(startC);
        search.setDateFinishedTo(endC);
        result = eng.getOrders(getTheSetupSession(), search, 0, 100, -1);


AndreiN

Thank you for your reply.

I have looked at your test code, and find it to be almost identical to mine. I'm really at my wits end here. Here's a little more detail on what's happening:

First off, all my declarations seem to be in order:


// Declaring the Service, and various objects needed
KKWSAdminIfService adminService = new KKWSAdminIfService();

AdminOrderSearchResult kkOrderSearchResult = new AdminOrderSearchResult();

AdminOrderSearch kkOrderSearch  = new AdminOrderSearch();


Then, I run the search (there are 3 orders in the test store which should be retrieved):


// Filter behavior
kkOrderSearchResult = adminService.getOrders(strSessionId, kkOrderSearch, 0, 5, -1);


This query returns absolutely nothing. The kkOrderSearchResult.orders array is empty, and the kkOrderSearchResult.totalSetSize property is zero. However, if I run the same query but pass no filters:


// No filter behavior
kkOrderSearchResult = adminService.getOrders(strSessionId, null, 0, 5, -1);


All 3 orders are successfully returned. kkOrderSearchResult.orders contains 3 orders, kkOrderSearchResult.totalSetSize equals 3.

Is it possible that there's something wrong with my KonaKart installation? Is there a setting within the store that could be affecting my search? This issue has already taken up a lot of my time, and I have absolutely no idea how to deal with it short of downloading every order in the store and filtering in memory, order by order (which I'm really hoping not to have to do).

Any advice would be greatly appreciated.

ming

Don't instantiate KKWSAdminIfService()

That's not the recommended way to work with the KonaKart SOAP engine.

You should instead instantiate KKWSAdmin by providing an AdminEngineConfig object in the constructor.

Once you've got your engine stub you would simply call the methods on the KKAdminIf interface (that KKWSAdmin implements).

This is the way to work with all of the KonaKart engines (KKEngIf and KKAdminIf).

The idea is that you could instantiate different implementations of KKAdminIf to use SOAP, JSON (KKEngIf only), RMI or POJO just by changing which engine is instantiated.  The engine could be specified in a property and you could use this to instantiate the engine stub by name, to make the change at runtime a configuration option.


AndreiN

Due to shifting priorities I haven't been working on this problem for the past couple of weeks, but have gotten back into it. I'm not sure I understand what you mean by

Quoteinstead instantiate KKWSAdmin by providing an AdminEngineConfig object in the constructor.


I have the KKWSAdmin WSDL referenced (ex: abc.com/konakartadmin/services/KKWSAdmin?wsdl ) and instantiate KKWSAdminIfService it in order to use its methods.

I can, similarly, instantiate an AdminEngineConfig object, but I don't understand what constructor I'm supposed to be passing it to.

Could you possible expand on your explanation, or post an example? Is there an additional WSDL I should be referencing? Thank you.

ming

Check the examples and the user guide for best practices.

You should never create a KKWSAdminIfService

Only create the engine proxies like KKAdmin (POJO) KKWSAdmin (SOAP) etc.

Focus on programming against the two main interfaces :  KKAdminIf for the Admin engine and KKEngIf for the storefront server engine.

KKWSAdmin is a proxy that implements the KKAdminIf and uses SOAP for the communication.   It handles all the details of the SOAP communication for you... hence you just have to focus on the KKAdminIf interfaces to use it.    The beauty is that you can switch to a different implementation of the proxy extremely easily (even at runtime)...  without changing any of your code, to change from SOAP to POJO, to RMI etc...


This is the recommended higher-level version (in this case for the KKEngIf but the technique is the same for KKAdminIf engine proxies):


EngineConfigIf engConfig = new EngineConfig();
engConfig.setMode(EngineConfig.MODE_SINGLE_STORE);
           
KKEngIf engine = new KKWSEng(engConfig);

// make some example calls

CountryIf[] countries = engine.getAllCountries();
System.out.println("There are " + countries.length + " countries");

ManufacturerIf[] manufacturers = engine.getAllManufacturers();
System.out.println("There are " + manufacturers.length + " manufacturers");

CurrencyIf curr = engine.getDefaultCurrency();
System.out.println("The default currency is: " + curr.getCode());

AndreiN

I admit I have trouble understanding exactly what goes into using the architecture as described above by Ming in .NET and C#, however I have discovered why my order filtering was not working as expected.

As stated above, any getOrders call was failing to retrieve orders when I passed a AdminOrderSearch object. The problem is that its integer properties are always instantiated as being equal to Zero, which is actually a valid search value. They have to be manually set to a NEGATIVE VALUE in order for the search to ignore them. Thus, the object declaration has to be:

AdminOrderSearch search = new AdminOrderSearch
            {
                affiliateIdRule = -1,
                creatorRule = -1,
                custom1Rule = -1,
                custom2Rule = -1,
                custom3Rule = -1,
                custom4Rule = -1,
                custom5Rule = -1,
                customerCityRule = -1,
                customerEmailRule = -1,
                customerId = -1,
                customerPostcodeRule = -1,
                orderId = -1,
                orderNumberRule = -1,
                orderStatusId = -1,
                parentId = -1
            };


This guarantees that any other property you set will filter orders as expected. As for the properties above, they can (after or during the declaration) be set to any value you wish as well. :)

Hope this saves someone some time and frustration!

AndreiN

Yet another problem cropped up after finally getting the getOrders filters to work. Even though the documentation doesn't suggest it (that I can find), the orders retrieved by this method are all missing key information, such as not including their line items.

What we are now resorting to doing is using the array of AdminOrder objects retrieved by getOrders to get their Id's, and are then retrieving the full order using getOrderByOrderId. Tedious, but I just don't have it in me to dig into this anymore.

If any KonaKart forum member can shed some light into why this might be happening, I'd love to hear a solution, or at least be pointed to the documentation that states that getOrders is not meant to retrieve critical order information such as line items.

Once again, I hope this saves someone a headache.