Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combined complex filter for ranges

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?

like image 264
DrColossos Avatar asked Jan 29 '13 09:01

DrColossos


3 Answers

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!

like image 61
Ivan Baldo Avatar answered Oct 31 '22 05:10

Ivan Baldo


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.

like image 31
DrColossos Avatar answered Oct 31 '22 04:10

DrColossos


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

like image 21
cads Avatar answered Oct 31 '22 03:10

cads