Combined complex filter for ranges
Asked Answered
I

3

15

On Magento 1.7 SOAP APIv2, i'm looking for a way to get a date range to retrieve information from the SOAP API.

$complexFilter = new filters();
$complexFilter->complex_filter = array(
    array(
        'key' => 'created_at',
        'value' => array('key' => 'from', 'value' => '2012-12-17 00:00:00')
    ), 
    array(
        'key' => 'created_at',
        'value' => array('key' => 'to', 'value' => '2013-01-21 12:02:02')
    ), 
);

This seemed like the most natural approach, but only the last criterion gets used. I also tried other combinations like a complex filter of complex filters, different ways to combine them, using gt and alike instead of from and co. Most of these approaches resulted in the same result: only the last criterion inside will be used.

What is the proper way to get a date range via the API? Can this also be done via a regular filter? If so, how to combine the start and end date?

Inguinal answered 29/1, 2013 at 9:33 Comment(0)
I
4

After googling a lot more i finally come to some explanation.

Obviously, the implementation of the complex filters does not allow more then one attribute to be present. This is also what I noticed during my tests: only the last attribute used influences the result. I therefore need to find another way of doing what I want. It's somehow sad to see that Magento does not provide an easy way to do this with ther SOAP API.

The final approach I used now is to determine a date that comes closest to what I want. Then just iterate through the results that that are in the daterange I want. This way (at least with our product data), I keep the load and results to a minumum and still get the desired products.

edit seems like the original link is down and the site doesn't exist anymore. The text above should be enough information. The blog merely showed some code examples with the faulty implementation.

Inguinal answered 8/2, 2013 at 13:50 Comment(0)
E
19

I found a better way looking at the code in Magento! Luckily it IS CASE SENSITIVE, so:

$complexFilter->complex_filter = array(
    array(
        'key' => 'CREATED_AT',
        'value' => array('key' => 'from', 'value' => '2012-12-17 00:00:00')
    ), 
    array(
        'key' => 'created_at',
        'value' => array('key' => 'to', 'value' => '2013-01-21 12:02:02')
    ), 
);

does the trick pretty neatly!

Eleaseeleatic answered 4/4, 2014 at 22:25 Comment(2)
This is incredible, appears to be working for me using increment_id as the column of a sales order list. I'd lump this approach into the "sad" part of Magento's SOAP API implementation.Solfatara
Sadly this is working really well for me with from and to dates on pulling orders. Thanks for the find.Pneumatic
I
4

After googling a lot more i finally come to some explanation.

Obviously, the implementation of the complex filters does not allow more then one attribute to be present. This is also what I noticed during my tests: only the last attribute used influences the result. I therefore need to find another way of doing what I want. It's somehow sad to see that Magento does not provide an easy way to do this with ther SOAP API.

The final approach I used now is to determine a date that comes closest to what I want. Then just iterate through the results that that are in the daterange I want. This way (at least with our product data), I keep the load and results to a minumum and still get the desired products.

edit seems like the original link is down and the site doesn't exist anymore. The text above should be enough information. The blog merely showed some code examples with the faulty implementation.

Inguinal answered 8/2, 2013 at 13:50 Comment(0)
G
2

Seems to be a bug in mage\sales\order\api\v2.php

Matlock provides a possible solution for this in the comment section of this thread: http://www.magentocommerce.com/bug-tracking/issue?issue=8073

Gadolinium answered 8/2, 2013 at 23:15 Comment(1)
Hmm, the issue is rather old. I still posted my 2cts to it... Sad that the issue is still there after almost 3 years.Inguinal

© 2022 - 2024 — McMap. All rights reserved.