在 eBay 上可以使用三个选项来更新实时项目。
为了快速更新商品的数量,您可能需要使用 ReviseInventoryStatus,因为它比其他的有一些优势。
如果您可以在 PHP 项目中使用 Composer,我开发了一个 SDK,它简化了 eBay API 的使用。下面的示例显示了如何将 SDK 与 ReviseInventoryStatus 一起使用。代码中的 cmets 应该会告诉您需要更改哪些内容才能使其正常工作。
<?php
require 'vendor/autoload.php';
use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
use \DTS\eBaySDK\Trading\Enums;
// Your authorization token associated with the seller's account.
$authToken = 'abcd123';
// The ID of the item you wish to update (Must be a string).
$itemID = '123456789';
// The new quantity (Must be an integer and not a string!).
$quantity = 20;
// The numerical ID of the site that the item was listed on. For example the site ID for ebay.com is 0 and for ebay.co.uk it is 3. A complete list is available from eBay: http://developer.ebay.com/DevZone/XML/docs/Reference/ebay/types/SiteCodeType.html.
$siteID = '0';
$service = new Services\TradingService(array(
'authToken' => $authToken,
'apiVersion' => '899',
'siteId' => $siteID
));
$request = new Types\ReviseInventoryStatusRequestType();
$inventoryStatus = new Types\InventoryStatusType();
$inventoryStatus->ItemID = $itemID;
$inventoryStatus->Quantity = $quantity;
$request->InventoryStatus[] = $inventoryStatus;
$request->ErrorLanguage = 'en_US';
$request->WarningLevel = 'High';
$response = $service->reviseInventoryStatus($request);
if (isset($response->Errors)) {
foreach ($response->Errors as $error) {
printf("%s: %s\n%s\n\n",
$error->SeverityCode === Enums\SeverityCodeType::C_ERROR ? 'Error' : 'Warning',
$error->ShortMessage,
$error->LongMessage
);
}
}
if ($response->Ack !== 'Failure') {
foreach ($response->InventoryStatus as $inventoryStatus) {
printf("Quantity for [%s] is %s\n\n",
$inventoryStatus->ItemID,
$inventoryStatus->Quantity
);
}
}
如果您对更新项目的其他方面感兴趣,例如它的标题,您将需要使用任一 Revise 操作,因为这些操作旨在更新更多字段。
<?php
require 'vendor/autoload.php';
use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
use \DTS\eBaySDK\Trading\Enums;
// Your authorization token associated with the seller's account.
$authToken = 'abcd123';
// The ID of the item you wish to update (Must be a string).
$itemID = '123456789';
// The new quantity (Must be an integer and not a string!).
$quantity = 20;
// The numerical ID of the site that the item was listed on. For example the site ID for ebay.com is 0 and for ebay.co.uk it is 3. A complete list is available from eBay: http://developer.ebay.com/DevZone/XML/docs/Reference/ebay/types/SiteCodeType.html.
$siteID = '0';
$service = new Services\TradingService(array(
'authToken' => $authToken,
'apiVersion' => '899',
'siteId' => $siteID
));
$request = new Types\ReviseItemRequestType();
$item = new Types\ItemType();
$item->ItemID = $itemID;
$item->Quantity = $quantity;
$request->Item = $item;
$request->ErrorLanguage = 'en_US';
$request->WarningLevel = 'High';
$response = $service->reviseItem($request);
if (isset($response->Errors)) {
foreach ($response->Errors as $error) {
printf("%s: %s\n%s\n\n",
$error->SeverityCode === Enums\SeverityCodeType::C_ERROR ? 'Error' : 'Warning',
$error->ShortMessage,
$error->LongMessage
);
}
}
if ($response->Ack !== 'Failure') {
printf("Quantity for [%s] has been updated\n\n", $itemID);
}