如何从 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);
    }
}

我尝试过的/问题:

如何找到与特定产品相关的资产以下载它们或获取下载文件 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 管理面板及其请求找到了主要线索:-)