如何从 Akeneo 5 获取产品的媒体资产
How to fetch Media Assets of a Product from Akeneo 5
我尝试从
中的产品中获取媒体资产
我正在使用 https://github.com/akeneo/api-php-client-ee (v6) and know about https://api.akeneo.com/api-reference-50.html
这是我到目前为止得出的结论:
$searchBuilder = new \Akeneo\Pim\ApiClient\Search\SearchBuilder();
$searchBuilder->addFilter('enabled', '=', true);
$searchFilters = $searchBuilder->getFilters();
$products = $client->getProductApi()->all(100, ['search' => $searchFilters]);
foreach ($products as $product) {
foreach($product['values']['assets'] as $assetData) {
foreach($assetData['data'] as $code) {
echo $code;
$asset = $client->getProductMediaFileApi()->all();
var_dump($asset);
}
}
我尝试过的/问题:
我得到类似 1234_00 的代码(如果 1234 是产品编号),但我不知道如何从产品媒体文件中获取特定文件 api .我必须在这里过滤吗?怎么样?
我试过 $client->getAssetMediaFileApi()->download($code)
但我的 $code
似乎不是完整的资产代码(我收到 404 未找到错误)
如何找到与特定产品相关的资产以下载它们或获取下载文件 URL?
这有效 - “bilder”是我们案例中的资产系列代码。
foreach ($products as $product) {
foreach($product['values']['assets'] as $assetData) {
foreach($assetData['data'] as $code) {
echo $code;
$assets = $client->getAssetManagerApi()->get('bilder', $code);
foreach($assets['values']['media'] as $dataLine) {
$download = $client->getAssetMediaFileApi()->download($dataLine['data']);
file_put_contents('/tmp/' . basename($dataLine['data']), $download->getBody());
}
foreach($assets['values']['variation_image'] as $dataLine) {
$download = $client->getAssetMediaFileApi()->download($dataLine['data']);
file_put_contents('/tmp/' . basename($dataLine['data']), $download->getBody());
}
}
我通过查看 Akeneo 管理面板及其请求找到了主要线索:-)
我尝试从
中的产品中获取媒体资产我正在使用 https://github.com/akeneo/api-php-client-ee (v6) and know about https://api.akeneo.com/api-reference-50.html
这是我到目前为止得出的结论:
$searchBuilder = new \Akeneo\Pim\ApiClient\Search\SearchBuilder();
$searchBuilder->addFilter('enabled', '=', true);
$searchFilters = $searchBuilder->getFilters();
$products = $client->getProductApi()->all(100, ['search' => $searchFilters]);
foreach ($products as $product) {
foreach($product['values']['assets'] as $assetData) {
foreach($assetData['data'] as $code) {
echo $code;
$asset = $client->getProductMediaFileApi()->all();
var_dump($asset);
}
}
我尝试过的/问题:
我得到类似 1234_00 的代码(如果 1234 是产品编号),但我不知道如何从产品媒体文件中获取特定文件 api .我必须在这里过滤吗?怎么样?
我试过
$client->getAssetMediaFileApi()->download($code)
但我的$code
似乎不是完整的资产代码(我收到 404 未找到错误)
如何找到与特定产品相关的资产以下载它们或获取下载文件 URL?
这有效 - “bilder”是我们案例中的资产系列代码。
foreach ($products as $product) {
foreach($product['values']['assets'] as $assetData) {
foreach($assetData['data'] as $code) {
echo $code;
$assets = $client->getAssetManagerApi()->get('bilder', $code);
foreach($assets['values']['media'] as $dataLine) {
$download = $client->getAssetMediaFileApi()->download($dataLine['data']);
file_put_contents('/tmp/' . basename($dataLine['data']), $download->getBody());
}
foreach($assets['values']['variation_image'] as $dataLine) {
$download = $client->getAssetMediaFileApi()->download($dataLine['data']);
file_put_contents('/tmp/' . basename($dataLine['data']), $download->getBody());
}
}
我通过查看 Akeneo 管理面板及其请求找到了主要线索:-)