2013-10-09 43 views
0

我創建一個模塊,增加了一個方法,Magento的API sopa_v1:內api.xml我的「等」如下:錯誤創建Magento的API方法 - getAllowedAttributes

<?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; 
     } 
} 

Ø埃羅ESTA吶TAG:

foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { 
    if (isset($data[$attributeCode])) { 
     $row[$attributeCode] = $data[$attributeCode]; 
    } 
    } 

我retornaØ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 
+1

我認爲這是相當明確。您的類Novapc_ObterEnderecosFiltrado_Model_Api和Mage_Api_Model_Resource_Abstract(它從中擴展而來)沒有方法getAllowedAttributes()。創建它,並應該工作。 – medina

回答

1

基本上什麼錯誤意味着沒有方法getAllowedAttributes既不Novapc_ObterEnderecosFiltrado_Model_Api也不類,它擴展 - Mage_Api_Model_Resource_Abstract

因此,你需要在你的類實現此方法

+0

可以告訴我如何在我的課程中實現這種方法嗎?我從另一位程序員那裏得到這段代碼,我有點迷路。 –

+0

對不起,我設法解決,我只是將我的課程擴展到「Mage_Customer_Model_Address_Api」 –