コード例 #1
1
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);
}
コード例 #2
0
ファイル: ProductClient.php プロジェクト: pablosoria/MWS
 /**
  * @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;
 }
コード例 #3
0
 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;
 }