问题
I am trying to get the available stock of a product for an sku. I searched it a-lot found some pdfs non of them worked for me. I am stuck scratching my head what to do, can anyone help me I will be more then thankful. I also tried this code,
$skus = new FBAInventoryServiceMWS_Model_SellerSkuList();
$skus->setmember( 'sku-111' );
invokeListInventorySupply($service, $request->withSellerSkus( $skus ) );
but what it returned is InStockSupplyQuantity is 0 you can see on this link
This is the full version of the code that I am using,
<?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 />");
}
}
回答1:
This code works fine for me:
...
$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);
...
My complete code is based on the file \src\FBAInventoryServiceMWS\Samples\ListInventorySupplySample.php
from the PHP Client Library v20101001 where the code above replace the line 71.
The output looks like:
回答2:
--Edit--
being that PHP and I are not the best of friends I'm going to paraphrase the steps needed to ensure that you can get the data you want:
- build your request with ListInventorySupply
crawl your response looking by looking at the following XML and ensuring your calling the objects correctly:
<?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> ....
In C# each reponse is available through a set of objects, for instance:
submitFeedResponse.SubmitFeedResult.FeedSubmissionInfo.FeedType
or
submitFeedResponse.ResponseMetadata.RequestId
I have found most of my invalid responses have been a result of not having the proper objects being called, or if I did the have the correct object, I was not displaying it correctly ( not calling toString() for example ).
On the other hand, you are returning your sku name, so have you ensured that the sku you are using should be returning an actual quantity via seller central?
Alternatively some excellent support is available at:
https://sellercentral.amazon.com/forums/forum.jspa?forumID=35
来源:https://stackoverflow.com/questions/11401212/amazon-mws-read-inventory-stock-php