Question

I am trying to use the GetMatchingProductForId function in the Amazon MWS PHP client library to match a UPC with an ASIN. Once matched I retrieved the ASIN value from the XML response. I am then trying to pass the ASIN variable to the GetLowestOfferForASIN function. I am not sure how to do this. I am new to developing and struggling. I read about static variables, global variables, and function arguments and not sure which, if any I can use in this case. Below is a portion of my code:

function invokeGetMatchingProductForId(MarketplaceWebServiceProducts_Interface $service, $request) { $response = $service->GetMatchingProductForId($request);

    $dom = new DOMDocument();
    $dom->loadXML($response->toXML());
    $dom->preserveWhiteSpace = false;
    $dom->formatOutput = true;
    $ASIN = $dom->getElementsByTagName('ASIN')->item(0)-> nodeValue;
    echo ($ASIN); 

//this returns the correct ASIN value for the UPC code that I am searching. I am then trying to use this ASIN value as a parameter in the function below.

$request = new MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINRequest();
$request->setSellerId(MERCHANT_ID);
$request->setMarketplaceId(MARKETPLACE_ID);
$asinList = new MarketplaceWebServiceProducts_Model_ASINListType();
$asinList = $ASIN;
$asinList->setASIN(array($ASIN));
$request->setASINList($asinList);
$request->setItemCondition('Used');
invokeGetLowestOfferListingsForASIN($service, $request);

/** * Get Get Lowest Offer Listings For ASIN Action Sample * Gets competitive pricing and related information for a product identified by * the MarketplaceId and ASIN. * @param MarketplaceWebServiceProducts_Interface $service instance of MarketplaceWebServiceProducts_Interface * @param mixed $request MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASIN or array of parameters */

function invokeGetLowestOfferListingsForASIN(MarketplaceWebServiceProducts_Interface $service, $request)

  {
      try {
        $response = $service->GetLowestOfferListingsForASIN($request);
        echo ("Service Response\n");
        echo 

("=============================================================================\n");

$dom = new DOMDocument();
$dom->loadXML($response->toXML());
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
echo $dom->saveXML();
echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");


} catch (MarketplaceWebServiceProducts_Exception $ex) {
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}
}

Any help would be greatly appreciated.

Thanks,

Eric

Était-ce utile?

La solution

You're not stating what kind of error you're getting, but deep research on the social economical backgrounds of object hierarchies pointed me here:

$asinList = new MarketplaceWebServiceProducts_Model_ASINListType();
$asinList = $ASIN;
$asinList->setASIN(array($ASIN));

The second line replaces the wonderful instance of StupidlyLongAmazonClassNameHere with a simple and proletarian string. It just might be the latter is offended by being treated as upper class citizen and hence refuses to have its setASIN method called.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top