0

I need to list the products based on created date, How to filter the list based on created at in the following code

$client = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
$session = $client->login('apiUser', 'apiKey');
$complexFilter = array(
'complex_filter' => array(
    array(
        'key' => 'type',
        'value' => array('key' => 'in', 'value' => 'simple,configurable')
    )
)
);
$result = $client->catalogProductList($session, $complexFilter);
var_dump ($result);

key as created at and value as some date. How to achieve this...

1

Try this

$client = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
$session = $client->login('apiUser', 'apiKey');
$complexFilter = array(
'complex_filter' => array(
    array(
        'key' => 'type',
        'value' => array('key' => 'in', 'value' => 'simple,configurable')
    ),
    array(
        'key' => 'created_at',
        'value' => array('key' => 'from', 'value' => '2015-01-01 00:00:00')
    ),
    array(
        'key' => 'created_at',
        'value' => array('key' => 'to', 'value' => '2016-12-31 23:59:59')
    )     
)
);
$result = $client->catalogProductList($session, $complexFilter);
var_dump ($result);

There are quite a few filter operators available which directly correspond to SQL operators, since that's what they are translated to internally.

  1. from => After the given timestamp

  2. to => Before the given timestamp

  3. like => Like the given text (SQL syntax, using % for wildcards)

  4. nlike => Not like the given text (SQL syntax)

  5. eq => Equal to the given value
  6. neq => Not equal to the given value
  7. in => In the given array
  8. nin => Not in the given array
  9. null => Is null
  10. notnull => Is not null
  11. gt => Greater than
  12. lt => Less than
  13. gteq => Greater than or equal to
  14. lteq => Less than or equal to

You can check Web services API filter operators here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.