* 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 Lowest Offer Listings For ASIN Action ***********************************************************************/ // @TODO: set request. Action can be passed as MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASIN $request = new MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINRequest(); $request->setSellerId(MERCHANT_ID); // object or array of parameters 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);
/** * Get Lowest Offer Listings For ASIN * Gets some of the lowest prices based on the product identified by the given * MarketplaceId and ASIN. * * @param mixed $request array of parameters for MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASIN request or MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASIN object itself * @see MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINRequest * @return MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINResponse * * @throws MarketplaceWebServiceProducts_Exception */ public function getLowestOfferListingsForASIN($request) { if (!$request instanceof MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINRequest) { require_once dirname(__FILE__) . '/Model/GetLowestOfferListingsForASINRequest.php'; $request = new MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINRequest($request); } $parameters = $request->toQueryParameterArray(); $parameters['Action'] = 'GetLowestOfferListingsForASIN'; $httpResponse = $this->_invoke($parameters); require_once dirname(__FILE__) . '/Model/GetLowestOfferListingsForASINResponse.php'; $response = MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINResponse::fromXML($httpResponse['ResponseBody']); $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']); return $response; }
public function getLowestOfferListingsForASIN($ProductID) { // WPLA()->logger->info('getLowestOfferListingsForASIN() - '.join(', ',$ProductID)); $this->initAPI('Products'); $request = new MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINRequest(); $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->GetLowestOfferListingsForASIN($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; }