Showing Products based on a Keyword Query
This example will show 24 products, with their thumbnails, product name, price and brand (if it exists)
The first block of code, same as always:
<?php define('API', 'PS'); require_once('constants.inc.php'); require_once('classes/class.ClientFactory.php'); $oClient = ClientFactory::getClient(API_USERNAME, API_PASSWORD, API_USER_TYPE); ?>
The business end of the code, using the Category ID, but this time its been set to 0, which is all categories, and a keyword query, in this case ‘firetrap shoe’:
<?php $oRefineBy = new stdClass(); $oRefineBy -> iId = 4; $oRefineBy -> sName = 'Category'; $oRefineByDefinition = new stdClass(); $oRefineByDefinition -> sId = 0; $oRefineByDefinition -> sName = ''; $oRefineBy -> oRefineByDefinition = $oRefineByDefinition; $searchquery = 'firetrap shoe'; $listproducts = array( "iLimit"=>24, "oActiveRefineByGroup" => $oRefineBy, "sQuery" => urlencode($searchquery), "bIncludeTree" => true); $oResponse= $oClient->call('getProductList', $listproducts); foreach($oResponse->oProduct as $details){ $image = $details->sAwThumbUrl; $name = $details->sName; $name = $details->sName; $price = $details->fPrice; $link = $details->sAwDeepLink; $brand = $details->sBrand; echo "<div style=\"width:31%;margin: 5px;padding:2px;display:inline-block;min-height:110px;height:110px;vertical-align:top;\"> <a href=".$link."> <img src=\"".$image."\" width=\"70\" height=\"70\" alt=\"".$name."\" style=\"float:left; margin:5px;border:0px\" /> </a>".$name."<br/>£".number_format($price,2,'.',',')."<br/>".$brand."</div>"; } ?>
The Results of this query (new window)
There are one or two differences in this code to the category based query.
Firstly, there is a new parameter in the call “sQuery” => urlencode($searchquery). It should be evident what this parameter does, and shouldn’t need any explanation here, suffice to say that the line above it $searchquery = ‘firetrap shoe’;
Comments
5 Comments on Showing Products based on a Keyword Query
-
Dean on
Tue, 22nd Sep 2009 2:30 pm
-
Dean on
Tue, 22nd Sep 2009 2:31 pm
-
apimonkey on
Tue, 22nd Sep 2009 2:43 pm
-
hardyk on
Tue, 16th Mar 2010 11:41 am
-
apimonkey on
Thu, 18th Mar 2010 1:47 am
I have a question but first can I say thank you sooo much for putting this site up! The wiki and forum are very little help and I’ve been struggling… Now for my question – Is it possible to query a more general term such as ‘high heel shoes’ instead of just shoes? Can you filter out results too, say if you dont want ‘red high heels’ just the rest? Thanks again!!
Dean
sorry I meant query a more ‘specific term’, not general
Hi Dean, of course, the query is your choice, with V3 you can also use negative keywords (using the “sMode” =>boolean parameter in your API call)
I’ll knock up a quick page later to show how this is done
Hi,
I’m new to AW and wouldn’t have known how to start using the api tool if I hadn’t chanced upon your site – Thanks a lot !
I’m trying to ‘construct’ a key word query using negative keywords but with no joy.
Here is my latest effort:
$searchquery = “+Shoe+Black-Flat” (N.b. also tried using ! to indicate negative)
$listproducts = array( “iLimit”=>100, “sSort” => “hi”, “oActiveRefineByGroup” => array( $oRefineBy,$oRefineBy1,$oRefineBy2,$oRefineBy3 ), “sQuery” => $searchquery, “sMode” => “boolean”, “bIncludeTree” => true, “bUseGlobalList” => false);
N.b. RefineBy = CatId, RefineBy1 thru 3 = Merchants
Trying to retrieve Black Shoes that don’t have Flat heels !
Regards
You need some spacing in there : “+Shoe +Black -Flat” should do the job for the query
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!
You must be logged in to post a comment.









