我正在创建一个模块,为magento API sopa_v1添加一个方法:我的“etc”中的api.xml如下:
<?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>
和我的Api.php在“模特”中:
<?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
答案 0 :(得分:1)
基本上错误意味着Novapc_ObterEnderecosFiltrado_Model_Api和类扩展中都没有方法getAllowedAttributes
- Mage_Api_Model_Resource_Abstract
所以你需要在你的课程中实现这个方法