function get_detail_by_skus($skus)
{
    global $serviceUrl, $config, $service;
    $request = new MarketplaceWebServiceProducts_Model_GetMatchingProductForIdRequest();
    $request->setSellerId(MWS_MERCHANG_ID);
    $request->withMarketplaceId(MWS_MARKETPLACE_ID);
    $request->withIdType('SellerSKU');
    $asinList = new MarketplaceWebServiceProducts_Model_IdListType();
    foreach ($skus as $sku) {
        $asinList->withId($sku);
    }
    $request->withIdList($asinList);
    // object or array of parameters
    return invokeGetMatchingProductForId($service, $request);
}
Beispiel #2
0
 /**
  * @param Ean13 $ean
  *
  * @return AmazonProduct|bool
  */
 public function getProductByEAN(Ean13 $ean)
 {
     $getMatchingProductForIdRequest = new \MarketplaceWebServiceProducts_Model_GetMatchingProductForIdRequest();
     $getMatchingProductForIdRequest->setSellerId($this->config['merchant_id']);
     $getMatchingProductForIdRequest->setMarketplaceId($this->config['marketplace_id']);
     $getMatchingProductForIdRequest->setIdType('EAN');
     try {
         $idListType = new \MarketplaceWebServiceProducts_Model_IdListType();
         $idListType->setId($ean->ean13());
         $getMatchingProductForIdRequest->withIdList($idListType);
         /** @var $marketPlaceManager \MarketplaceWebServiceProducts_Model_GetMatchingProductForIdResponse */
         $response = $this->client->getMatchingProductForId($getMatchingProductForIdRequest);
         /** @var  $headersMetadata  \MarketplaceWebServiceProducts_Model_ResponseHeaderMetadata */
         $headersMetadata = $response->getResponseHeaderMetadata();
         //$quotaMax = $headersMetadata->getQuotaMax();
         $quotaRemaining = $headersMetadata->getQuotaRemaining();
         //$requestTimeStamp = $headersMetadata->getTimestamp();
         //$requestId = $headersMetadata->getRequestId();
         //$resetsAt = $headersMetadata->getQuotaResetsAt();
         while ($quotaRemaining < 1) {
             echo 'ProductClient: Has been reached the limit of requests. Waiting 5 minutes to continue... ' . 'QuotaRemaining: ' . $quotaRemaining;
             sleep(5 * 60);
         }
         if (is_object($response)) {
             $xmlString = str_replace('ns2:', '', $response->toXML());
             $xml = simplexml_load_string($xmlString);
             if (!isset($xml->{'GetMatchingProductForIdResult'}->Error)) {
                 $product = $xml->{'GetMatchingProductForIdResult'}->Products->Product;
                 $identifiers = $product->{'Identifiers'};
                 $asin = !is_null($identifiers) ? $identifiers->{'MarketplaceASIN'}->ASIN->__toString() : null;
                 $url = !empty($asin) ? 'http://www.amazon.es/gp/product/' . $asin : null;
                 try {
                     $asin = new Asin($asin);
                 } catch (\Exception $e) {
                     echo $e->getMessage() . "\n";
                     return false;
                 }
                 $attributes = $product->{'AttributeSets'}->ItemAttributes;
                 $brand = $attributes->{'Brand'}->__toString();
                 $color = $attributes->{'Color'}->__toString();
                 $productType = $attributes->{'ProductTypeName'}->__toString();
                 $productGroup = $attributes->{'ProductGroup'}->__toString();
                 $size = $attributes->{'Size'}->__toString();
                 $model = $attributes->{'Model'}->__toString();
                 $title = $attributes->{'Title'}->__toString();
                 $prod = new $this->class($ean, $brand, $title);
                 $prod->setAsin($asin)->setColor($color)->setSize($size)->setUrl($url)->setProductType($productType)->setProductGroup($productGroup)->setModel($model);
                 return $prod;
             } else {
                 echo 'El ean ' . $ean->ean13() . ' no está en Amazon.' . "\n";
                 return false;
             }
         }
     } catch (\MarketplaceWebServiceProducts_Exception $ex) {
         var_dump($ex);
     }
     return false;
 }
 * 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 Matching Product For Id Action
 ***********************************************************************/
// @TODO: set request. Action can be passed as MarketplaceWebServiceProducts_Model_GetMatchingProductForId
$request = new MarketplaceWebServiceProducts_Model_GetMatchingProductForIdRequest();
$request->setSellerId(MERCHANT_ID);
// object or array of parameters
invokeGetMatchingProductForId($service, $request);
/**
 * Get Get Matching Product For Id 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_GetMatchingProductForId or array of parameters
 */
function invokeGetMatchingProductForId(MarketplaceWebServiceProducts_Interface $service, $request)
{
    try {
        $response = $service->GetMatchingProductForId($request);
 /**
  * Get Matching Product For Id
  * GetMatchingProduct will return the details (attributes) for the
  * given Identifier list. Identifer type can be one of [SKU|ASIN|UPC|EAN|ISBN|GTIN|JAN]
  *
  * @param mixed $request array of parameters for MarketplaceWebServiceProducts_Model_GetMatchingProductForId request or MarketplaceWebServiceProducts_Model_GetMatchingProductForId object itself
  * @see MarketplaceWebServiceProducts_Model_GetMatchingProductForIdRequest
  * @return MarketplaceWebServiceProducts_Model_GetMatchingProductForIdResponse
  *
  * @throws MarketplaceWebServiceProducts_Exception
  */
 public function getMatchingProductForId($request)
 {
     if (!$request instanceof MarketplaceWebServiceProducts_Model_GetMatchingProductForIdRequest) {
         require_once dirname(__FILE__) . '/Model/GetMatchingProductForIdRequest.php';
         $request = new MarketplaceWebServiceProducts_Model_GetMatchingProductForIdRequest($request);
     }
     $parameters = $request->toQueryParameterArray();
     $parameters['Action'] = 'GetMatchingProductForId';
     $httpResponse = $this->_invoke($parameters);
     require_once dirname(__FILE__) . '/Model/GetMatchingProductForIdResponse.php';
     $response = MarketplaceWebServiceProducts_Model_GetMatchingProductForIdResponse::fromXML($httpResponse['ResponseBody']);
     $response->setResponseHeaderMetadata($httpResponse['ResponseHeaderMetadata']);
     return $response;
 }
 public function getMatchingProductForId($ProductID, $IdType = 'ASIN')
 {
     WPLA()->logger->info('getMatchingProductForId() - ' . $ProductID);
     $this->initAPI('Products');
     $request = new MarketplaceWebServiceProducts_Model_GetMatchingProductForIdRequest();
     $request->setSellerId($this->SellerId);
     $request->setMarketplaceId($this->MarketplaceId);
     $request->setIdType($IdType);
     // set idList
     if (!is_array($ProductID)) {
         $ProductID = array($ProductID);
     }
     $idList = new MarketplaceWebServiceProducts_Model_IdListType();
     $idList->setId($ProductID);
     $request->setIdList($idList);
     // invoke request
     try {
         $response = $this->service->GetMatchingProductForId($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));
         // $res = $response->getGetMatchingProductForIdResult();
         // echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
         $result = new stdClass();
         $result->product = $parsed_xml;
         $result->success = true;
         // log to db - parsed request
         $this->dblogger->updateLog(array('response' => $xml_data, 'result' => json_encode($result->product), '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();
         $error->success = false;
         // 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;
 }