PDA

View Full Version : Getting Merchant Name from Merchant ID


Iceman
01-05-07, 21:17
I see iMerchantId is a value of a product. How do you get the merchant name from the iMerchantId? I see there is a merchant object with a sName field but how do you get a merchant object?

Ah, getMerchant function.

Iceman
02-05-07, 10:37
Ah, discovered getMerchant function but it doesn't work for me. Following code gives error

SoapError Object ( [sCode] => SOAP-ENV:Server [sString] => SOAP-ERROR: Encoding: string 'SOAP-ERROR

$oClient = new api_client();
$merchantParams = array('aMerchantIds' => 782);
$oMerchant=$oClient->call('getMerchant', $merchantParams);
$merchantnames=$oMerchant->getMerchantReturn;
echo $merchantnames;

Can someone please point out what I am doing wrong or know of an easier way of getting a merchant name from a product object without creating a merchant object?

authcode
02-05-07, 11:10
I had trouble with this too until I got some help here and found some more code in the client install. It's not totally obvious at first glance but it should help.
Instead of using the api_client which is generic you can use the more specific api_merchant which requires the class.api_merchant.php. You can use api_client, I'm not yet sure why there are specific api classes at all, all I know is that this works for me so I'm sticking with it!

$oMerchantParams->aMerchantIds[]= <merchant id>;
//make the call
$oMerchant = new api_merchant();
$aMerchants = $oMerchant->getMerchant($oMerchantParams);
//access the merchant array data
$aMerchants[<merchant id>]->sName

Hard code a <merchant id> to start with to check this works for you. Remember to 'require' the class.api_merchant.php file first.

As for why your code doesn't work, possibly because $merchantnames is an array of merchant objects so echo $merchantnames will probably just print 'object' or 'array'. You'll need to loop through the array and echo something like echo $merchantsnames[$i]->sName. Having said that, I think some of the code above it may be wrong but I can't be sure. As I say I had problems too until I found this code.

Iceman
02-05-07, 12:02
Thanks for your help Steve. But I am still not quite there.

$oMerchant = new api_merchant();
// what should a list of merchant ids look like?
$oMerchantParams->aMerchantIds[]= '782';
$aMerchants = $oMerchant->getMerchant($oMerchantParams);
//access the merchant array data
echo $aMerchants[0]->sName;

Gives error

SoapError Object ( [sCode] => ns1:Client.LIMIT_1 [sString] => Insufficient Quota [sDetails] => getMerchant: You have used all your operations quota )
1

But I have API quota.

authcode
02-05-07, 12:15
Hmm, sounds like quota limit but if you say you've got quote remaining.....
are you still setting the globals (username, password) etc. before trying this? That's just a guess.
I create the merchant id list by looping through a product array i.e.

//given a product array called $aProducts
//get all the merchant ids for the product list
foreach($aProducts as $oProd) {
$oMerchantParams->aMerchantIds[]= $oProd->iMerchantId;
}


Try the merchant id without the surrounding ' ' cos you might be passing it as a string instead of an int. And instead of accessing the first element of the array try accessing it as an associative array with the merchant id as the key i.e.

echo $aMerchants[782]->sName;

Iceman
02-05-07, 12:41
Got it now. Thanks again.

I had require("./includes/classes/class.api_merchant.php");
before my user details.

I suppose I could implement something today but am not happy about no delivery prices being available.:(

Iceman
02-05-07, 16:31
Got the api implemented for digital cameras now, working well. Decided not to use merchant object to get merchant name as each api request takes a few seconds. Set up an array, ditto delivery charges.

So thanks for your help Steve and thanks to AWIN for creating the API. Tis a cool bit of IT.

authcode
02-05-07, 16:51
No problem, happy I could help.