magentomagento-1.7soap-clientmagento-soap-api

Magento Soap - Get detailed product list with one single call


I'm currently using a SOAP method called 'catalogProductList' (http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.list.html) that retrieves a Array of catalogProductEntity.

The problem is that catalogProductEntity doesn't have some attributes like 'price' and 'description'. The question is: Is there any (already implemented) SOAP method that gives me this information with one single call?

If don't, how/where can I add this fields to the returned values? I mean, change the php code in the server side to get this 'detailed list of products' in one single call.

I'm trying to avoid several queries to each product to get this info.

PS: I'm using Magento 1.7.


Edited

Following @Mat tips, I edited the \app\code\core\Mage\Catalog\Model\Product\Api.php file and my method items is just like this:

public function items($filters = null, $store = null)
{
    $collection = Mage::getModel('catalog/product')->getCollection()
        ->addStoreFilter($this->_getStoreId($store))
        ->addAttributeToSelect('price')
        ->addAttributeToSelect('description')
        ->addAttributeToSelect('name');

    /** @var $apiHelper Mage_Api_Helper_Data */
    $apiHelper = Mage::helper('api');
    $filters = $apiHelper->parseFilters($filters, $this->_filtersMap);
    try {
        foreach ($filters as $field => $value) {
            $collection->addFieldToFilter($field, $value);
        }
    } catch (Mage_Core_Exception $e) {
        $this->_fault('filters_invalid', $e->getMessage());
    }
    $result = array();
    foreach ($collection as $product) {
        $result[] = array(
            'product_id' => $product->getId(),
            'sku'        => $product->getSku(),
            'price'      => $product->getData('price'),
            'description'=> $product->getData('description'),
            'name'       => $product->getName(),
            'set'        => $product->getAttributeSetId(),
            'type'       => $product->getTypeId(),
            'category_ids' => $product->getCategoryIds(),
            'website_ids'  => $product->getWebsiteIds()
        );
    }
    error_log(print_r($result, true) . "\n", 3, "c:\log.txt");
    return $result;
}

The log file outputs this result:

 Array
(
    [0] => Array
        (
            [product_id] => 3
            [sku] => sim12ple1235
            [price] => 99.9500
            [description] => Simple Description
            [name] => Simple Product
            [set] => 4
            [type] => simple
            [category_ids] => Array
                (
                )
            [website_ids] => Array
                (
                    [0] => 1
                )
        )
)

Note that price and description are in the $result variable, but the xml response I get in the client application is:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:catalogProductListResponse>
<storeView SOAP-ENC:arrayType="ns1:catalogProductEntity[1]" xsi:type="ns1:catalogProductEntityArray">
<item xsi:type="ns1:catalogProductEntity">
<product_id xsi:type="xsd:string">3</product_id>
<sku xsi:type="xsd:string">sim12ple1235</sku>
<name xsi:type="xsd:string">Simple Product</name>
<set xsi:type="xsd:string">4</set>
<type xsi:type="xsd:string">simple</type>
<category_ids SOAP-ENC:arrayType="xsd:string[0]" xsi:type="ns1:ArrayOfString"/>
<website_ids SOAP-ENC:arrayType="xsd:string[1]" xsi:type="ns1:ArrayOfString">
<item xsi:type="xsd:string">1</item>
</website_ids>
</item>
</storeView>
</ns1:catalogProductListResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

My question is: Is there any xml schema or another config file that specifies the output? Anything else I'm missing to edit in the server side?


Solution

  • The problem is that it was missing this fields (price and description) in the file app/code/core/Mage/Catalog/etc/wsdl.xml, after applying the php change.

    ...
    <complexType name="catalogProductEntity">
    <all>
        <element name="product_id" type="xsd:string"/>
        <element name="sku" type="xsd:string"/>
        <element name="name" type="xsd:string"/>
        <element name="set" type="xsd:string"/>
        <element name="type" type="xsd:string"/>
        <element name="category_ids" type="typens:ArrayOfString"/>
        <element name="website_ids" type="typens:ArrayOfString"/>
    
        <element name="price" type="xsd:string"/>
        <element name="description" type="xsd:string"/>
    </all>
    </complexType>
    ...
    

    And DON'T FORGET CLEANING THE CACHE!