Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento API V2 - add an additional attribute to API response

Tags:

soap

api

magento

I'm using the Magento API V2.

When I call salesOrderCreditmemoInfo, I get a response with the credit memo details and a list of the products associated with the order.

But in the list of product items there is no product_type attribute.

I want to manually edit the response to add this attribute.

I tried editing: app\code\core\Mage\Sales\Model\Order\Creditmemo\Api.php

And replaced:

public function info($creditmemoIncrementId)
{
    ...
    $result['items'] = array();
    foreach ($creditmemo->getAllItems() as $item) {
        $result['items'][] = $this->_getAttributes($item, 'creditmemo_item');
    }

With the following - (basically appending an extra attribute to the array):

 public function info($creditmemoIncrementId)
    {
      ...
    $result['items'] = array();
    foreach ($creditmemo->getAllItems() as $item) {
            $product_type = '1'; //test value to check if works
            $attribs = $this->_getAttributes($item, 'creditmemo_item');
            $attribs['product_type'] = $product_type;

            $result['items'][] = $attribs;
        }

When I do mage::log($result), the extra attribute seems to be added correctly to the array. (also indicating that this function is the one getting called) But it has no impact on the actual API response.

Am I totally looking in the wrong place or is there something else I need to update?

like image 503
elMarquis Avatar asked Jun 27 '12 08:06

elMarquis


1 Answers

Since You were using SOAP V2, you should update the wsdl.xml to get the output.

For your case it is product_type and refresh cache on server. /tmp to load the new wsdl.xml that already updated. don't forget to go to System -> Cache Management clear all cache.

like image 176
Josua Marcel C Avatar answered Sep 23 '22 17:09

Josua Marcel C