Exemplo n.º 1
0
 /**
  * Get Competitive Pricing For ASIN
  * Gets competitive pricing and related information for a product identified by
  * the MarketplaceId and ASIN.
  *
  * @param mixed $request array of parameters for MarketplaceWebServiceProducts_Model_GetCompetitivePricingForASIN request or MarketplaceWebServiceProducts_Model_GetCompetitivePricingForASIN object itself
  * @see MarketplaceWebServiceProducts_Model_GetCompetitivePricingForASINRequest
  * @return MarketplaceWebServiceProducts_Model_GetCompetitivePricingForASINResponse
  *
  * @throws MarketplaceWebServiceProducts_Exception
  */
 public function getCompetitivePricingForASIN($request)
 {
     if (!$request instanceof MarketplaceWebServiceProducts_Model_GetCompetitivePricingForASINRequest) {
         $request = new MarketplaceWebServiceProducts_Model_GetCompetitivePricingForASINRequest($request);
     }
     $parameters = $request->toQueryParameterArray();
     $parameters['Action'] = 'GetCompetitivePricingForASIN';
     $httpResponse = $this->_invoke($parameters);
     $response = MarketplaceWebServiceProducts_Model_GetCompetitivePricingForASINResponse::fromXML($httpResponse['ResponseBody']);
     $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
     return $response;
 }
 * Uncomment to try out Mock Service that simulates MarketplaceWebServiceProducts
 * responses without calling MarketplaceWebServiceProducts service.
 *
 * Responses are loaded from local XML files. You can tweak XML files to
 * experiment with various outputs during development
 *
 * XML files available under MarketplaceWebServiceProducts/Mock tree
 *
 ***********************************************************************/
// $service = new MarketplaceWebServiceProducts_Mock();
/************************************************************************
 * Setup request parameters and uncomment invoke to try out 
 * sample for Get Competitive Pricing For ASIN Action
 ***********************************************************************/
// @TODO: set request. Action can be passed as MarketplaceWebServiceProducts_Model_GetCompetitivePricingForASINRequest
$request = new MarketplaceWebServiceProducts_Model_GetCompetitivePricingForASINRequest();
$request->setSellerId(MERCHANT_ID);
// object or array of parameters
invokeGetCompetitivePricingForASIN($service, $request);
/**
 * Get Competitive Pricing 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_GetCompetitivePricingForASIN or array of parameters
 */
function invokeGetCompetitivePricingForASIN(MarketplaceWebServiceProducts_Interface $service, $request)
{
    try {
        $response = $service->getCompetitivePricingForASIN($request);
 public function getCompetitivePricingForId($ProductID)
 {
     WPLA()->logger->info('getCompetitivePricingForId() - ' . join(', ', $ProductID));
     $this->initAPI('Products');
     $request = new MarketplaceWebServiceProducts_Model_GetCompetitivePricingForASINRequest();
     $request->setSellerId($this->SellerId);
     $request->setMarketplaceId($this->MarketplaceId);
     // set idList
     if (!is_array($ProductID)) {
         $ProductID = array($ProductID);
     }
     $idList = new MarketplaceWebServiceProducts_Model_ASINListType();
     $idList->setASIN($ProductID);
     $request->setASINList($idList);
     // invoke request
     try {
         $response = $this->service->GetCompetitivePricingForASIN($request);
         // parse XML response
         $dom = new DOMDocument();
         $dom->loadXML($response->toXML());
         $dom->preserveWhiteSpace = false;
         $dom->formatOutput = true;
         $xml_data = $dom->saveXML();
         // WPLA()->logger->info('XML: '.print_r($xml_data,1));
         $parsed_xml = $this->parseXML($xml_data);
         WPLA()->logger->debug('parsed_xml: ' . print_r($parsed_xml, 1));
         // echo "<pre>parsed_xml: ";print_r($parsed_xml);echo"</pre>";
         // unify results for single and multiple items - result is an array of items
         // if ( is_array( $parsed_xml->products ) ) {
         //     $products = $parsed_xml->products;
         // } else {
         //     $products = array( $parsed_xml->products );
         // }
         $result = new stdClass();
         $result->products = $parsed_xml;
         $result->success = true;
         // log to db - parsed request
         $this->dblogger->updateLog(array('response' => $xml_data, 'result' => json_encode($result->products), 'success' => 'Success'));
         return $result;
     } catch (MarketplaceWebServiceProducts_Exception $ex) {
         $error = new stdClass();
         $error->ErrorMessage = $ex->getMessage();
         $error->ErrorCode = $ex->getErrorCode();
         $error->StatusCode = $ex->getStatusCode();
         $error->ErrorType = $ex->getErrorType();
         $error->RequestId = $ex->getRequestId();
         $error->XML = $ex->getXML();
         $error->HeaderMeta = $ex->getResponseHeaderMetadata();
         // log to db - parsed request
         $this->dblogger->updateLog(array('result' => json_encode($error), 'success' => 'Error'));
         return $error;
     }
     $result = new stdClass();
     $result->success = false;
     return $result;
 }