更新库存遇到的坑, xml格式不对,因为输出的测试xml ,后面又加了点字符串,因为这个错误,耽误我好几天。。。下次测试结果时候,一定要等变量完全停止定义的后面 输出
-
- if($debug) echo htmlentities($xml);
- $feedContents = $xml;
-
- // 原来这个多了一行,导致了错误
- //$xml .= '';
feed 更新方式
1,createFeedDocument 返回
feedDocumentId
(
POST_INVENTORY_AVAILABILITY_DATA
)
2. uploadxml
3 createfeed
检测方式
1 getFeed
2
getFeedDocument
3 根据返回的url ,打开这个网址 看feed的执行结果
说明1 。inventory 的xml
- <?xml version="1.0" encoding="UTF-8"?>
- <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
- <Header>
- <DocumentVersion>1.01</DocumentVersion>
- <MerchantIdentifier>A。。。。。。X</MerchantIdentifier>
- </Header>
- <MessageType>Inventory</MessageType>
- <Message>
- <MessageID>1</MessageID>
- <OperationType>Update</OperationType>
- <Inventory>
- <SKU>SY...</SKU>
- <FulfillmentCenterID>DEFAULT</FulfillmentCenterID>
- <Quantity>3</Quantity>
- </Inventory>
- </Message>
- </AmazonEnvelope>
2 xsd的位置
https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Inventory.xsd https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/amzn-envelope.xsd
3 根据xsd 判断xml是否符合格式
https://www.freeformatter.com/xml-validator-xsd.html
最后演示代码
- use SellingPartnerApi\Api\FeedsV20210630Api as FeedsApi;
- use SellingPartnerApi\FeedType;
- use SellingPartnerApi\Model\FeedsV20210630 as Feeds;
- 。。。。。
-
-
-
-
- //POST_INVENTORY_AVAILABILITY_DATA 原来用POST_PRODUCT_DATA 无效
- $feedType = FeedType::POST_INVENTORY_AVAILABILITY_DATA;
- $feedsApi = new FeedsApi($config);
-
-
- // Create feed document
- $createFeedDocSpec = new Feeds\CreateFeedDocumentSpecification(['content_type' => $feedType['contentType']]);
- $feedDocumentInfo = $feedsApi->createFeedDocument($createFeedDocSpec);
- $feedDocumentId = $feedDocumentInfo->getFeedDocumentId();
- 、。。。。。
-
-
-
-
- $xml = '';
- $xml .= '
' ; - $xml .= '
' ; - $xml .= '
1.01 '; - $xml .= '
' . $merchant_id . ''; - $xml .= '';
- $xml .= '
Inventory '; - $xml .= '
' ; - $xml .= '
1 '; - //?是否需要 价格更新需要加这个
- $xml .= '
Update '; - $xml .= '
' ; - // SELLER SKU
- $xml .= '
' . $seller_sku . '';// 售价 - // 发货中心 ,卖家自发货 用 DEFAULT
- $xml .= '
DEFAULT '; - //choice ,三选一
- //$xml .= '
true '; - $xml .= '
' . $qty . ''; - //$xml .= '
FulfillmentNetwork '; -
- //gmdate("Y-m-dTH:i:s.00:00:00Z")
- //2022-10-27GMT10:39:16.00:00:000
- // $created_after , $created_before两个参数不能同时用
-
- //minOccurs="0"
- //$xml .= '
' . date('Y-m-d',time()) . ''; - //几天内发货 minOccurs="0"
- //$xml .= '
2 '; - //切换货运方式 minOccurs="0"
- //$xml .= '
'; - $xml .= '';
- $xml .= '';
- $xml .= '';
-
-
- // 同时修改多个时
- //$xml .= '
' ; - //$xml .= '
2 '; -
-
- // 原来这个多了一行,导致了错误
- //$xml .= '';
-
- if ($debug) echo htmlentities($xml);
- $feedContents = $xml;
-
-
- // The Document constructor accepts a custom \GuzzleHttp\Client object as an optional 3rd parameter. If that
- // parameter is passed, your custom Guzzle client will be used when uploading the feed document contents to Amazon.
- $docToUpload = new \SellingPartnerApi\Document($feedDocumentInfo, $feedType);
- $docToUpload->upload($feedContents);
- // This is not present in the example
- $body = new Feeds\CreateFeedSpecification();
- $body->setMarketplaceIds(['ATVPDKIKX0DER']);
- $body->setInputFeedDocumentId($feedDocumentId);
- $body->setFeedType($feedType['name']);
-
- $result = $feedsApi->createFeed($body);
- $feed_id = $result->getFeedId();
-
-
-
-
-