2017-08-19 13 views
0

20件のASINで1件のリクエストがあります。私は20のASINを持つXMLの形で応答を得ます。私は1つのASINに対して1つのXML - Responsを取得し、txt-File(20 XML)で保存したいと考えています。 しかし、これはリクエスト1のASINでは20ではない場合にのみ行うことができます。しかし、プロセスは非常に遅いです。私は何をすべきか? 質問番号2. すべてのASIN(例:1000)で1つのXMLを作成するにはどうすればよいですか?ここでASINごとに個別のXMLを取得する方法は? Amazon MWS

$arr = file('asin.txt',FILE_IGNORE_NEW_LINES); 
$arr_chunks = array_chunk($arr, 20); 

$request->setMarketplaceId(MARKETPLACE_ID); 
$asin_list = new MarketplaceWebServiceProducts_Model_ASINListType(); 

//$request->setASINList($asin_list); 
$request->setItemCondition('used'); 

foreach ($arr_chunks as $value){ 
    $value = $value; 
    $asin_list->setASIN($value); 
$request->setASINList($asin_list); 
sleep(1); 
invokeGetLowestOfferListingsForASIN($service, $request); 
} 

    function invokeGetLowestOfferListingsForASIN(MarketplaceWebServiceProducts_Interface $service, $request) 
    { 
     try { 
     $response = $service->GetLowestOfferListingsForASIN(); 


file_put_contents('asin2.xml', $response->toXML()); 
     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"); 

はあなたのXMLドキュメントを作成したら、あなたが各ASINをリストするXPathを使用することができ、これはその後、XML、あなたのように出力することができるXMLの例(asin2.xml)

<GetLowestOfferListingsForASINResponse 
    xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01"> 
    <GetLowestOfferListingsForASINResult 
     ASIN='3944660110' status='Success'> 
     <AllOfferListingsConsidered>true</AllOfferListingsConsidered> 
     <Product> 
      <Identifiers> 
       <MarketplaceASIN> 
        <MarketplaceId>A1PA6795UKMFR9</MarketplaceId> 
        <ASIN>3944660110</ASIN> 
       </MarketplaceASIN> 
      </Identifiers> 
      <LowestOfferListings></LowestOfferListings> 
     </Product> 
    </GetLowestOfferListingsForASINResult> 
    <GetLowestOfferListingsForASINResult 
     ASIN='3000383964' status='Success'> 
     <AllOfferListingsConsidered>true</AllOfferListingsConsidered> 
     <Product> 
      <Identifiers> 
       <MarketplaceASIN> 
        <MarketplaceId>A1PA6795UKMFR9</MarketplaceId> 
        <ASIN>3000383964</ASIN> 
       </MarketplaceASIN> 
      </Identifiers> 
      <LowestOfferListings> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>Good</ItemSubcondition> 
         <FulfillmentChannel>Merchant</FulfillmentChannel> 
         <ShipsDomestically>True</ShipsDomestically> 
         <ShippingTime> 
          <Max>0-2 days</Max> 
         </ShippingTime> 
         <SellerPositiveFeedbackRating>98-100% 
         </SellerPositiveFeedbackRating> 
        </Qualifiers> 
        <NumberOfOfferListingsConsidered>1 
        </NumberOfOfferListingsConsidered> 
        <SellerFeedbackCount>1388</SellerFeedbackCount> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>EUR</CurrencyCode> 
          <Amount>31.80</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>EUR</CurrencyCode> 
          <Amount>28.80</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>EUR</CurrencyCode> 
          <Amount>3.00</Amount> 
         </Shipping> 
        </Price> 
        <MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice> 
       </LowestOfferListing> 
      </LowestOfferListings> 
     </Product> 
    </GetLowestOfferListingsForASINResult> 
    <GetLowestOfferListingsForASINResult 
     ASIN='3000556575' status='Success'> 
     <AllOfferListingsConsidered>true</AllOfferListingsConsidered> 
     <Product> 
      <Identifiers> 
       <MarketplaceASIN> 
        <MarketplaceId>A1PA6795UKMFR9</MarketplaceId> 
        <ASIN>3000556575</ASIN> 
       </MarketplaceASIN> 
      </Identifiers> 
      <LowestOfferListings></LowestOfferListings> 
     </Product> 
    </GetLowestOfferListingsForASINResult> 
    <ResponseMetadata> 
     <RequestId>3caac4dc-ca52-446f-9f4b-a8da2d685ce7</RequestId> 
    </ResponseMetadata> 
</GetLowestOfferListingsForASINResponse> 
+0

サンプルXMLファイルを追加すると役立ちます。 –

+0

私はそれを追加しました。しかし、それは常にただの行でしかありません。ごめんなさい。私はそれを正しく行う方法を知らない。 – user8457287

答えて

0

です各セグメントを適切なファイルに保存できます。

$dom = new DOMDocument(); 
    $dom->load ('t1.xml'); 
    $xp = new DOMXPath($dom); 
    $xp->registerNamespace("default", 
       "http://mws.amazonservices.com/schema/Products/2011-10-01"); 
    foreach ($xp->query("//default:GetLowestOfferListingsForASINResult") as $asin) { 
     echo "For ASIN:".$asin->getAttribute('ASIN').PHP_EOL; 
     echo "ASIN=".$xp->evaluate ("string(descendant::default:MarketplaceASIN/default:ASIN/text())", $asin) .PHP_EOL; 

     echo $dom->saveXML($asin).PHP_EOL; 
     $prices = $xp->query("descendant::default:Price", $asin); 
     foreach ($prices as $price) { 
      echo "LandedPrice=".$xp->evaluate("string(descendant::default:LandedPrice/default:Amount/text())",$price).PHP_EOL; 
      echo "ListingPrice=".$xp->evaluate("string(descendant::default:ListingPrice/default:Amount/text())",$price).PHP_EOL; 
      echo "Shipping=".$xp->evaluate("string(descendant::default:Shipping/default:Amount/text())",$price).PHP_EOL; 

     } 

    } 
+0

多くのありがとう!それは働いている。 "Votes"をクリックしようとしましたが、 " Tank for feedback!"と評されています。評判が15未満の人の投票は記録されますが、公表された投稿のスコアは変更されません " Soryy。しかし、あなたは私を助けました。ありがとうございました。 – user8457287

+0

もう一度おねがいします。もう一つの質問があります。どのようにこのラインから - $ asinからすべての価格(納品と一緒に最終価格)を受け取る? – user8457287

+0

私はコードを更新し、各ノードからさまざまな価格を抽出します。 –

関連する問題