2012-07-09 109 views
1

我想獲得sku產品的可用庫存。我搜查了一大堆發現一些pdf的非他們爲我工作。我一直在抓我的腦子該怎麼辦,誰能幫助我,我會更感謝。 我也試過這個代碼,亞馬遜MWS閱讀庫存股票Php

$skus = new FBAInventoryServiceMWS_Model_SellerSkuList(); 
$skus->setmember('sku-111'); 

invokeListInventorySupply($service, $request->withSellerSkus($skus)); 

,但它返回的是InStockSupplyQuantity爲0,你可以在此link

看到這是我使用的代碼的完整版本,

<?php 

include_once ('.config.inc.php'); 

$config = array (
    'ServiceURL' => MWS_ENDPOINT_URL, 
    'ProxyHost' => null, 
    'ProxyPort' => -1, 
    'MaxErrorRetry' => 3 
); 

$service = new FBAInventoryServiceMWS_Client(
    ACCESS_KEY_ID, 
    SECRET_ACCESS_KEY, 
    $config, 
    APPLICATION_NAME, 
    APPLICATION_VERSION); 

$request = new FBAInventoryServiceMWS_Model_ListInventorySupplyRequest(); 
    $request->setSellerId(SELLER_ID); 

    $skus = new FBAInventoryServiceMWS_Model_SellerSkuList(); 
    $skus->setmember('sku-111'); 

    invokeListInventorySupply($service, $request->withSellerSkus($skus)); 

    function invokeListInventorySupply(FBAInventoryServiceMWS_Interface $service, $request) 
    { 
     try { 
       $response = $service->listInventorySupply($request); 

       echo ("Service Response<br />"); 
       echo ("=============================================================================<br />"); 

       echo("  ListInventorySupplyResponse<br />"); 
       if ($response->isSetListInventorySupplyResult()) { 
        echo("   ListInventorySupplyResult<br />"); 
        $listInventorySupplyResult = $response->getListInventorySupplyResult(); 
        if ($listInventorySupplyResult->isSetInventorySupplyList()) { 
         echo("    InventorySupplyList<br />"); 
         $inventorySupplyList = $listInventorySupplyResult->getInventorySupplyList(); 
         $memberList = $inventorySupplyList->getmember(); 
         foreach ($memberList as $member) { 
          echo("     member<br />"); 
          echo ("=============================================================================<br />"); 
          if ($member->isSetSellerSKU()) 
          { 
           echo("      SellerSKU<br />"); 
           echo("       " . $member->getSellerSKU() . "<br /><br />"); 
          } 
          if ($member->isSetFNSKU()) 
          { 
           echo("      FNSKU<br />"); 
           echo("       " . $member->getFNSKU() . "<br /><br />"); 
          } 
          if ($member->isSetASIN()) 
          { 
           echo("      ASIN<br />"); 
           echo("       " . $member->getASIN() . "<br /><br />"); 
          } 
          if ($member->isSetCondition()) 
          { 
           echo("      Condition<br />"); 
           echo("       " . $member->getCondition() . "<br /><br />"); 
          } 
          if ($member->isSetTotalSupplyQuantity()) 
          { 
           echo("      TotalSupplyQuantity<br />"); 
           echo("       " . $member->getTotalSupplyQuantity() . "<br /><br />"); 
          } 
          if ($member->isSetInStockSupplyQuantity()) 
          { 
           echo("      InStockSupplyQuantity<br />"); 
           echo("       " . $member->getInStockSupplyQuantity() . "<br /><br />"); 
          } 
          if ($member->isSetEarliestAvailability()) { 
           echo("      EarliestAvailability<br />"); 
           $earliestAvailability = $member->getEarliestAvailability(); 
           if ($earliestAvailability->isSetTimepointType()) 
           { 
            echo("       TimepointType<br />"); 
            echo("        " . $earliestAvailability->getTimepointType() . "<br /><br />"); 
           } 
           if ($earliestAvailability->isSetDateTime()) 
           { 
            echo("       DateTime<br />"); 
            echo("        " . $earliestAvailability->getDateTime() . "<br /><br />"); 
           } 
          } 
          if ($member->isSetSupplyDetail()) { 
           echo("      SupplyDetail<br />"); 
           $supplyDetail = $member->getSupplyDetail(); 
           $member1List = $supplyDetail->getmember(); 
           foreach ($member1List as $member1) { 
            echo("       member<br />"); 
            if ($member1->isSetQuantity()) 
            { 
             echo("        Quantity<br />"); 
             echo("         " . $member1->getQuantity() . "<br /><br />"); 
            } 
            if ($member1->isSetSupplyType()) 
            { 
             echo("        SupplyType<br />"); 
             echo("         " . $member1->getSupplyType() . "<br /><br />"); 
            } 
            if ($member1->isSetEarliestAvailableToPick()) { 
             echo("        EarliestAvailableToPick<br />"); 
             $earliestAvailableToPick = $member1->getEarliestAvailableToPick(); 
             if ($earliestAvailableToPick->isSetTimepointType()) 
             { 
              echo("         TimepointType<br />"); 
              echo("          " . $earliestAvailableToPick->getTimepointType() . "<br /><br />"); 
             } 
             if ($earliestAvailableToPick->isSetDateTime()) 
             { 
              echo("         DateTime<br />"); 
              echo("          " . $earliestAvailableToPick->getDateTime() . "<br /><br />"); 
             } 
            } 
            if ($member1->isSetLatestAvailableToPick()) { 
             echo("        LatestAvailableToPick<br />"); 
             $latestAvailableToPick = $member1->getLatestAvailableToPick(); 
             if ($latestAvailableToPick->isSetTimepointType()) 
             { 
              echo("         TimepointType<br />"); 
              echo("          " . $latestAvailableToPick->getTimepointType() . "<br /><br />"); 
             } 
             if ($latestAvailableToPick->isSetDateTime()) 
             { 
              echo("         DateTime<br />"); 
              echo("          " . $latestAvailableToPick->getDateTime() . "<br /><br />"); 
             } 
            } 
           } 
          } 
         } 
        } 
        if ($listInventorySupplyResult->isSetNextToken()) 
        { 
         echo("    NextToken<br />"); 
         echo("     " . $listInventorySupplyResult->getNextToken() . "<br /><br />"); 
        } 
       } 
       if ($response->isSetResponseMetadata()) { 
        echo("   ResponseMetadata<br />"); 
        $responseMetadata = $response->getResponseMetadata(); 
        if ($responseMetadata->isSetRequestId()) 
        { 
         echo("    RequestId<br />"); 
         echo("     " . $responseMetadata->getRequestId() . "<br /><br />"); 
        } 
       } 

    } catch (FBAInventoryServiceMWS_Exception $ex) { 
     echo("Caught Exception: " . $ex->getMessage() . "<br /><br />"); 
     echo("Response Status Code: " . $ex->getStatusCode() . "<br /><br />"); 
     echo("Error Code: " . $ex->getErrorCode() . "<br /><br />"); 
     echo("Error Type: " . $ex->getErrorType() . "<br /><br />"); 
     echo("Request ID: " . $ex->getRequestId() . "<br /><br />"); 
     echo("XML: " . $ex->getXML() . "<br /><br />"); 
    } 
} 

回答

0

- 編輯 -

因爲PHP和我不是最好的朋友,我將解釋確保所需的步驟你可以得到這些數據,您需要:

<?xml version="1.0"?> 
<ListInventorySupplyResponse xmlns="http://mws.amazonaws.com/FulfillmentInventory/2010-10-01"> 
<ListInventorySupplyResult> 
    <InventorySupplyList> 
     <member> 
       <SellerSKU>SampleSKU1</SellerSKU> 
       <ASIN>B00000K3CQ</ASIN> 
       <TotalSupplyQuantity>20</TotalSupplyQuantity> 
       <FNSKU>X0000000FM</FNSKU> 
       <Condition>NewItem</Condition> 
       <SupplyDetail/> 
       <InStockSupplyQuantity>15</InStockSupplyQuantity> 
       <EarliestAvailability> 
        <TimepointType>Immediately</TimepointType> 
       </EarliestAvailability> 
     .... 
    1. 構建您的ListInventorySupply
    2. 爬行你的反應看下面的XML,並確保你正確地調用對象的尋找請求在C#中,每個響應通過一組對象可用,例如:

      submitFeedResponse.SubmitFeedResult.FeedSubmissionInfo.FeedType 
      

      submitFeedResponse.ResponseMetadata.RequestId 
      

    我已經找到了我的大部分響應無效一直沒有合適的對象,結果被調用,或者如果我做了正確的對象,我沒有正確顯示它(沒有調用toString()例如)。

    另一方面,您正在返回您的sku名稱,那麼您是否確保您使用的sku應該通過賣家中心返回實際數量?

    另外一些優秀的支持,請訪問:

    https://sellercentral.amazon.com/forums/forum.jspa?forumID=35

  • +0

    我嘗試了足夠的例子,但沒有一個爲我工作。我編輯了我的問題發佈所有你需要的感謝。 – 2012-07-09 19:15:08

    +0

    這將會做什麼,它會添加新的項目,我想要的是閱讀我不想寫的清單。 – 2012-07-10 11:28:09

    +0

    因爲您的示例是MWS php示例,您是否確保整個API位於您的Web服務器上,包括模擬(如果您想運行像這樣的模擬示例)和Model目錄? – 2012-07-10 12:37:46

    5

    此代碼工作正常,我:

    ... 
    $skus= new FBAInventoryServiceMWS_Model_SellerSkuList(); 
    $skus->setmember("??-????-????"); // Your SKU 
    $request = new FBAInventoryServiceMWS_Model_ListInventorySupplyRequest(); 
    $request->setSellerId(SELLER_ID); 
    $request->setMarketplace(MARKETPLACE_ID); 
    $request->setSellerSkus($skus); 
    invokeListInventorySupply($service, $request); 
    ... 
    

    我完整的代碼是基於文件\src\FBAInventoryServiceMWS\Samples\ListInventorySupplySample.phpPHP Client Library v20101001其中代碼以上取代線71.

    輸出如下: enter image description here