Question

I cannot find any documentation (other than the WSDL itself) that provides a working example of how to filter a SOAP API_v2 catalogProductList.

I have a list of skus and I want to filter the list with nin (not in) so that the response gives me all products other than what I have in my skus.

$skus = array('1','2','3');
$filter = array(
    'sku' => array('nin' => $skus)
)
$productList = $client->catalogProductList($session, $filter);

// Returns all products in the store instead of filtered list.
Zend_Debug::dump($productList);

I have also see the $filter being built with complex_filters that uses a different array structure, but I don't understand what the difference is.

How do I simply filter an API product list using the nin method?


EDIT

Trying with complex_filters, using 'eq' works, but not 'nin':

// this returns a single product with sku 12345
$filter = array(
    'complex_filter' => array(
        array('key' => 'sku', 'value' => array('key' => 'eq', 'value' => '12345'))
    )
);

// This results in an error - "Notice: Array to string conversion  in ..."
$filter = array(
    'complex_filter' => array(
        array('key' => 'sku', 'value' => array('key' => 'nin', 'value' => array('12345', '67890'))
    )
);
Was it helpful?

Solution

API V2 queries use a "complex filter" for advanced queries. Their syntax is a bit different. Here's a complex filter query for your sample:

$filter = array(
  array(
    'complex_filter' => array(
      array(
        'key' => 'sku',
        'value' => array('key' => 'nin', 'value' => '1,2,3')
      )
    )
  )
);

$productList = $client->catalogProductList($session, $filter);

More query samples are available on the catalogProduct API Doc page

OTHER TIPS

I think you should use

array('nin'=>$skus) instead of array('nin',$skus)

Then it should work!

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top