I'm creating a module that adds a method to the magento API sopa_v1: api.xml within my "etc" is as follows:
<?xml version="1.0"?>
<config>
<api>
<resources>
<obterenderecosfiltrado_api translate="title" module="obterenderecosfiltrado">
<title>Myapi</title>
<acl>obterenderecosfiltrado/api</acl>
<model>obterenderecosfiltrado/api</model>
<methods>
<getaddressbyfilter translate="title" module="obterenderecosfiltrado">
<title>Obter Address Filtrado</title>
<acl>obterenderecosfiltrado/getaddressbyfilter</acl>
</getaddressbyfilter>
</methods>
</obterenderecosfiltrado_api>
</resources>
<acl>
<resources>
<obterenderecosfiltrado translate="title" module="obterenderecosfiltrado">
<title>ObterEnderecosFiltrado</title>
<sort_order>2000</sort_order>
<getaddressbyfilter translate="title" module="obterenderecosfiltrado">
<title>Obter Address Filtrado</title>
</getaddressbyfilter>
</obterenderecosfiltrado>
</resources>
</acl>
</api>
</config>
and my Api.php within "model":
<?php
class Novapc_ObterEnderecosFiltrado_Model_Api extends Mage_Api_Model_Resource_Abstract
{
protected $_mapAttributes = array(
'customer_address_id' => 'entity_id'
);
public function __construct()
{
$this->_ignoredAttributeCodes[] = 'parent_id';
}
public function getaddressbyfilter($filters)
{
$collection = Mage::getModel('customer/address')->getCollection()
->addAttributeToSelect('*');
if (is_array($filters)) {
try {
foreach ($filters as $field => $value) {
if (isset($this->_mapAttributes[$field])) {
$field = $this->_mapAttributes[$field];
}
$collection->addFieldToFilter($field, $value);
}
} catch (Mage_Core_Exception $e) {
$this->_fault('filters_invalid', $e->getMessage());
}
}
$result = array();
foreach ($collection as $address) {
$data = $address->toArray();
$row = array();
foreach ($this->_mapAttributes as $attributeAlias => $attributeCode) {
$row[$attributeAlias] = (isset($data[$attributeCode]) ? $data[$attributeCode] : null);
}
foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) {
if (isset($data[$attributeCode])) {
$row[$attributeCode] = $data[$attributeCode];
}
}
$customerId = $address->getParentId();
$customer = Mage::getModel('customer/customer')->load($customerId);
$row['customer_id'] = $customerId;
$row['is_default_billing'] = $customer->getDefaultBilling() == $address->getId();
$row['is_default_shipping'] = $customer->getDefaultShipping() == $address->getId();
$result[] = $row;
}
return $result;
}
}
O Erro esta na TAG:
foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) {
if (isset($data[$attributeCode])) {
$row[$attributeCode] = $data[$attributeCode];
}
}
me retorna o seguinte:
Uncaught SoapFault exception: [SOAP-ENV:Server] Call to undefined method Novapc_ObterEnderecosFiltrado_Model_Api::getAllowedAttributes() in C:\wamp\www\conectar_ws.php:13 Stack trace: #0 C:\wamp\www\conectar_ws.php(13): SoapClient->__call('call', Array) #1 C:\wamp\www\conectar_ws.php(13): SoapClient->call('739882c5e4d2184...', 'obterenderecosf...', Array) #2 {main} thrown in C:\wamp\www\conectar_ws.php on line 13