I want to get a list of all products using magento API V2 SOAP catalogProductList endpoint, but I want to add the following fields to every product in response xml: price, quantity and manage_stock.
In order to do this, I made following changes:
In file: app\code\core\Mage\Catalog\etc\wsdl.xml
, I added
<element name="price" type="xsd:string"/>
<element name="qty" type="xsd:string"/>
<element name="manage_stock" type="xsd:string"/>
to <complexType name="catalogProductEntity">
so the tag looks like this:
<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="qty" type="xsd:string"/>
<element name="manage_stock" type="xsd:string"/>
</all>
</complexType>
Same changes have been made to wsi.xml( added xsd:element tag).
In file app\code\core\Mage\Catalog\Model\Product\Api.php
, in method items, I made following changes:
public function items( $filters = null, $store = null ) {
$collection = Mage::getModel( 'catalog/product' )->getCollection()
->addStoreFilter( $this->_getStoreId( $store ) )
->addAttributeToSelect( 'name' )
->addAttributeToSelect( 'price' )
->joinField( 'qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left' )
->joinField( 'manage_stock', 'cataloginventory/stock_item', 'manage_stock', 'product_id=entity_id', null, 'left');
/** @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 ) {//added price, qty, manage_stock to result
$result[] = array (
'product_id' => $product->getId(),
'sku' => $product->getSku(),
'name' => $product->getName(),
'set' => $product->getAttributeSetId(),
'type' => $product->getTypeId(),
'category_ids' => $product->getCategoryIds(),
'website_ids' => $product->getWebsiteIds(),
'price' => $product->getPrice(),
'qty' => $product->getQty(),
'manage_stock' => $product->getManageStock()
);
}
return $result;
}
When I make the soap request, I do not receive those 3 parameters, I only receive product_id, sku, name, set, type, category_ids and website_ids, even though I receive the correct wsdl configuration.
Here is an item returned by API after above changes were mage:
<item xsi:type="ns1:catalogProductEntity">
<product_id xsi:type="xsd:string">1</product_id>
<sku xsi:type="xsd:string">2435</sku>
<name xsi:type="xsd:string">product</name>
<set xsi:type="xsd:string">4</set>
<type xsi:type="xsd:string">simple</type>
<category_ids SOAP-ENC:arrayType="xsd:string[4]" xsi:type="ns1:ArrayOfString">
<item xsi:type="xsd:string">2</item>
<item xsi:type="xsd:string">3</item>
<item xsi:type="xsd:string">4</item>
<item xsi:type="xsd:string">5</item>
</category_ids>
<website_ids SOAP-ENC:arrayType="xsd:string[1]" xsi:type="ns1:ArrayOfString">
<item xsi:type="xsd:string">1</item>
</website_ids>
</item>
I cleared cache, made sure Api.php file is not overriden. Could you tell me what am I doing wrong?
Thanks!
Best Answer
I do not know why, but it works now.
I think that the cause for this was /tmp folder on my server. I forgot to clear it after I'd made above changes yesterday.
Sorry for being inattentive:(