简体   繁体   中英

Magento API: Get products/details with media in one call

I don't know if it's even possible to get the media list with the product list without having to do multiple .call()'s

Is multiCall() an option somehow? I'd have to have return values from the first call in that multiCall() to insert into the second that retrieves the media, but Magento's documentation is poor in my opinion.

Do I have to create my own API extension just to do something as simple as return image url's with the product details?

Here's what I have at the moment:

<?php
$soap = new SoapClient('http://hello-magento.local/magento/api/soap?wsdl');
$session_id = $soap->login('username', 'password');

$product_list = $soap->call($session_id, 'product.list');

$products = array();

foreach($product_list as $product_item)
{
    $product_id = $product_item['product_id'];
    $product_image = $soap->call($session_id, 'catalog_product_attribute_media.list', $product_id);

    $product_details = array();
    $product_details['id']      = $product_id;
    $product_details['name']    = $product_item['name'];
    $product_details['image']   = $product_image[0]['url'];

    $products['products'][] = $product_details;
}

$soap->endSession($session_id);

echo json_encode($products);
?>

I had a similar problem where I wanted to get more info on order items when getting a list of orders. I was able to solve this by creating a module with an observer. Whenever an order model is loaded, I could do $order->setMyCustomValue($orderItemInfo) and this data would show up when I would do an order.list request.

Looking at Mage_Catalog_Model_Product_Api, the basic product info (product_id, sku, name, etc) are all hard-coded in the items method (which product.list calls). The only way I see around this is to create a custom module that overwrites and extends Mage_Catalog_Model_Product_Api. Call the parent items method, then add in the data you need to the result (such as media url) and return that.

A custom API would work too, but it would be a little more work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM