Showing Products Based on Category ID

This code will show how to retrieve products based on AFiiliate Window Category ID a list of which can be found here

Once again there is the code whaich is required for every call

<?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);
	?>

Then into the actual workings;

<?php
	$oRefineBy = new stdClass();
	$oRefineBy -> iId = 4;
	$oRefineBy -> sName = 'Category';
	$oRefineByDefinition = new stdClass();
	$oRefineByDefinition -> sId = 97;
	$oRefineByDefinition -> sName = '';
	$oRefineBy -> oRefineByDefinition = $oRefineByDefinition;
 
 
	$listproducts = array( "iLimit"=>24, "oActiveRefineByGroup" => $oRefineBy, "bIncludeTree" => true);
	$oResponse= $oClient->call('getProductList', $listproducts);
	foreach($oResponse->oProduct as $details){
		$image = $details->sAwThumbUrl;
		$id = $details->iId;
		$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/>&pound;".number_format($price,2,'.',',')."<br/>".$brand."</div>";
	}
 
	?>

the results of this code (new window)
There’s a new bit at the top of this code, the $oRefineBy bit, which create a refinement for the code below it, this particular refinement is $oRefineBy -> sName = ‘Category’;. Which defines the content of a new parameter to the API call, namely this “oActiveRefineByGroup” => $oRefineBy, in this case I’ve used the category ID 97 on this line $oRefineByDefinition -> sId = 97;.

Comments

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.