The First Example Get a List of Merchants
The first thing I’ll do is outline the code to get a list of merchants for any given category.
Exploring the code:
1 2 3 4 5 6 | <?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); ?> |
This first block of code will be included in every example as it calls the required files and defines the $oClient.
Nothing to look at in there, so, moving on;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <?php $listmerchants = array('iCategoryId'=> 97, 'iMaxResult' => 10); $oResponse= $oClient->call('getMerchantList', $listmerchants); foreach($oResponse->oMerchant as $details){ $name = $details->sName; $strapline = $details->sStrapline; $description = $details->sDescription; $logo = $details->sLogoUrl; $showurl = $details->sDisplayUrl; $deeplink = $details->sClickThroughUrl; $id = $details->iId; if ($logo<>'') { echo "<a href=".$deeplink." title='".$name."'><img src=".$logo. " style='float:left; margin:5px;' alt='".$name. " :: ".$strapline." :: ".$description." :: ".$showurl. "' width=\"88\" height=\"31\" border=\"0\"></a>"; } } ?> |
The results for this code (new window)
These two lines are the ones that make the call and do the work;
$listmerchants = array(‘iCategoryId’=> 97, ‘iMaxResult’ => 10);
$oResponse= $oClient->call(‘getMerchantList’, $listmerchants);
You’ll notice an if loop in the code if ($logo<>”), why? Because very occasionally, the merchant logo just isn’t there in the system as they don’t have one. So the if loop is basically to prevent trying to show a logo when one doesn’t exist.
The first line sets the call parameters, namely the category ID that we want to return merchants for (97 is Clothing & Accessories), and the number of results we want back from the query (set to 10 in this example, you can use more or less).
The second line calls the ‘getMerchantList’ and sends the parameters from the first line with $listmerchants.
The possible results are as follows
- iId The merchant id.
- sName The merchant name.
- sStrapline The merchant strap line.
- sDescription The merchant description.
- sLogoUrl URL to merchant logo.
- sDisplayUrl Display URL to merchants website.
- sClickThroughUrl Tracked URL to merchants website.
And you can see how some of them are used in this these lines
1 2 3 4 5 6 7 | $name = $details->sName; $strapline = $details->sStrapline; $description = $details->sDescription; $logo = $details->sLogoUrl; $showurl = $details->sDisplayUrl; $deeplink = $details->sClickThroughUrl; $id = $details->iId; |
and then run out as html with these lines:
1 2 3 4 | echo "<a href=".$deeplink." title='".$name."'><img src=".$logo. " style='float:left; margin:5px;' alt='".$name. " :: ".$strapline." :: ".$description." :: ".$showurl. "' width=\"88\" height=\"31\" border=\"0\"></a>"; |
Next up, how to get some products showing for a specific Category ID » This Way




