Note: This article requires existing knowledge of Web Services and PHP.
Note: This article applies to the PHP Toolkit before version 2012.2.
This Article outlines a sample for performing and Advanced Search using the PHPToolkit that performs an ItemSearchAdvanced using a UI Item search with customsearch##, and adds the criteria for a specific item 'category'
...
require_once '../../PHPtoolkit.php';
require_once '../login_info.php';
global $myNSclient;
$myNSclient->setSearchPreferences(false, 20); $savedSearchId = 'customsearch##'; //customsearch## from UI ID field
$searchAdvanced = new nsComplexObject('ItemSearchAdvanced');
$searchAdvanced->setFields(array('savedSearchScriptId'=>$savedSearchId));
$search = new nsComplexObject('ItemSearch');
//Start code to add additional criteria using product category as a field.
$myResponderRefRecord = new nsRecordRef(array('internalId' => '#')); //Where # is the internalID of the product category
$multiselectfield = new nsComplexObject('SearchMultiSelectField');
$multiselectfield->setFields(array('operator'=>'anyOf','searchValue'=>$myResponderRefRecord));
$itemsearchobject = new nsComplexObject('ItemSearchBasic');
$itemsearchobject->setFields(array('category'=>$multiselectfield));
$search->setFields(array('basic'=>$itemsearchobject));
$searchAdvanced->setFields(array('criteria'=>$search));
//End code to add additional criteria
$results = $myNSclient->search($searchAdvanced);
print_r($results);//dumps the results directly from PHPToolkit
...
require_once '../../PHPtoolkit.php';
require_once '../login_info.php';
global $myNSclient;
$myNSclient->setSearchPreferences(false, 20); $savedSearchId = 'customsearch##'; //customsearch## from UI ID field
$searchAdvanced = new nsComplexObject('ItemSearchAdvanced');
$searchAdvanced->setFields(array('savedSearchScriptId'=>$savedSearchId));
$search = new nsComplexObject('ItemSearch');
//Start code to add additional criteria using product category as a field.
$myResponderRefRecord = new nsRecordRef(array('internalId' => '#')); //Where # is the internalID of the product category
$multiselectfield = new nsComplexObject('SearchMultiSelectField');
$multiselectfield->setFields(array('operator'=>'anyOf','searchValue'=>$myResponderRefRecord));
$itemsearchobject = new nsComplexObject('ItemSearchBasic');
$itemsearchobject->setFields(array('category'=>$multiselectfield));
$search->setFields(array('basic'=>$itemsearchobject));
$searchAdvanced->setFields(array('criteria'=>$search));
//End code to add additional criteria
$results = $myNSclient->search($searchAdvanced);
print_r($results);//dumps the results directly from PHPToolkit
...
The above code would generate the following SOAP request:
<body>
<search>
<searchRecord savedSearchScriptId="customsearch##" type="ItemSearchAdvanced">
<criteria>
<basic>
<category operator="anyOf">
<searchValue internalId="#" />
</category>
</basic>
</criteria>
</searchRecord>
</search>
</body>
<search>
<searchRecord savedSearchScriptId="customsearch##" type="ItemSearchAdvanced">
<criteria>
<basic>
<category operator="anyOf">
<searchValue internalId="#" />
</category>
</basic>
</criteria>
</searchRecord>
</search>
</body>
No comments:
Post a Comment