我正在进行我的第一个API调用,而Linnworks的调用相当慢,并且只会随着库存的增加而变得更糟,因此我想保存输出以供离线使用。
据我了解,我是第一个打电话给Linnworks进行库存查询。
$inventoryItems = Inventory::GetInventoryItems($views[0], $locationIds, 0, 10, $authorization->Token, "https://api.linnworks.net/");
然后,基于响应,我可以请求商品图片;
$images = Inventory::GetInventoryItemImages($item->Id, $authorization->Token, "https://api.linnworks.net/");
我希望将图像从第一个请求$ inventoryItems添加到数组中,如何执行此操作?
这是我到目前为止所拥有的;
$authorization = json_decode(Factory::GetResponse("Auth/AuthorizeByApplication", "applicationId=asddas&applicationSecret=asdasd&token=asdasdasd", "", "https://api.linnworks.net/"));
$views = Inventory::GetInventoryViews($authorization->Token, "https://api.linnworks.net/");
file_put_contents("/tmp/views.json",json_encode($views));
$locations = Inventory::GetStockLocations($authorization->Token, "https://api.linnworks.net/");
file_put_contents("/tmp/locations.json",json_encode($locations));
$locationIds = array();
foreach($locations as $location){ $locationIds[] = $locations[0]->StockLocationId; }
$inventoryItems = Inventory::GetInventoryItems($views[0], $locationIds, 0, 10, $authorization->Token, "https://api.linnworks.net/");
foreach($inventoryItems->Items as $item){
$images = Inventory::GetInventoryItemImages($item->Id, $authorization->Token, "https://api.linnworks.net/");
foreach($images as $image){
// Add Image to $inventoryItems ??
$imageSource = $image->Source;
}
}
// Save Complete Results Set
file_put_contents("/tmp/inventoryItems.json",json_encode($inventoryItems));
$ InventoryItems输出的一部分;
stdClass Object
(
[Items] => Array
(
[0] => stdClass Object
(
[website] => stdClass Object
(
[LinksCount] => 1
[Templates] => Array
(
)
[Changes] => Array
(
)
[ContainsChanges] =>
)
)
[Id] => fe44bdcc-899f-47ff-958a-0285ed5e9936
[Title] => Product Title
[Category] => 00000000-0000-0000-0000-000000000000
[Image] =>
)
$ images部分输出;
Array
(
[0] => stdClass Object
(
[pkRowId] => sdfsdfsdsddsf
[Source] => http://images.linnlive.com/werwerwerwerwerwe/tumbnail_sdfsdfsdf.jpg
[IsMain] => 1
[StockItemId] => fe44bdcc-899f-47ff-958a-0285ed5e9936
)
[1] => stdClass Object
(
[pkRowId] => asdasdasddsa
[Source] => http://images.linnlive.com/werwerwerwerwerwe/tumbnail_sdfsdfsdf.jpg
[IsMain] =>
[StockItemId] => fe44bdcc-899f-47ff-958a-0285ed5e9936
)
)
Array
(
[0] => stdClass Object
(
[pkRowId] => weerewrwerewerewrew
[Source] => http://images.linnlive.com/werwerwerwerwerwe/tumbnail_sdfsdfsdf.jpg
[IsMain] => 1
[StockItemId] => fb9f4983-5391-4320-b745-03eb4f48640f
)
)
foreach($inventoryItems->Items as &$item){
$images = Inventory::GetInventoryItemImages($item->Id, $authorization->Token, "https://api.linnworks.net/");
$item->images =[];
foreach($images as $image){
$imageSource = $image->Source;
$item->images[] = $imageSource;
}
}
$item
是您的对象,因此默认情况下它通过引用传递,但是如果它不起作用,则可以&$item
在foreach语句中使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句