Mage_Customer_Model_Customer_Api Class Reference

Inheritance diagram for Mage_Customer_Model_Customer_Api:

Mage_Customer_Model_Api_Resource Mage_Api_Model_Resource_Abstract Mage_Customer_Model_Customer_Api_V2

List of all members.

Public Member Functions

 create ($customerData)
 info ($customerId, $attributes=null)
 items ($filters)
 update ($customerId, $customerData)
 delete ($customerId)

Protected Attributes

 $_mapAttributes


Detailed Description

Definition at line 34 of file Api.php.


Member Function Documentation

create ( customerData  ) 

Create new customer

Parameters:
array $customerData
Returns:
int

Reimplemented in Mage_Customer_Model_Customer_Api_V2.

Definition at line 46 of file Api.php.

00047     {
00048         try {
00049             $customer = Mage::getModel('customer/customer')
00050                 ->setData($customerData)
00051                 ->save();
00052         } catch (Mage_Core_Exception $e) {
00053             $this->_fault('data_invalid', $e->getMessage());
00054         }
00055         return $customer->getId();
00056     }

delete ( customerId  ) 

Delete customer

Parameters:
int $customerId
Returns:
boolean

Definition at line 167 of file Api.php.

00168     {
00169         $customer = Mage::getModel('customer/customer')->load($customerId);
00170 
00171         if (!$customer->getId()) {
00172             $this->_fault('not_exists');
00173         }
00174 
00175         try {
00176             $customer->delete();
00177         } catch (Mage_Core_Exception $e) {
00178             $this->_fault('not_deleted', $e->getMessage());
00179         }
00180 
00181         return true;
00182     }

info ( customerId,
attributes = null 
)

Retrieve customer data

Parameters:
int $customerId
array $attributes
Returns:
array

Definition at line 65 of file Api.php.

00066     {
00067         $customer = Mage::getModel('customer/customer')->load($customerId);
00068 
00069         if (!$customer->getId()) {
00070             $this->_fault('not_exists');
00071         }
00072 
00073         if (!is_null($attributes) && !is_array($attributes)) {
00074             $attributes = array($attributes);
00075         }
00076 
00077         $result = array();
00078 
00079         foreach ($this->_mapAttributes as $attributeAlias=>$attributeCode) {
00080             $result[$attributeAlias] = $customer->getData($attributeCode);
00081         }
00082 
00083         foreach ($this->getAllowedAttributes($customer, $attributes) as $attributeCode=>$attribute) {
00084             $result[$attributeCode] = $customer->getData($attributeCode);
00085         }
00086 
00087         return $result;
00088     }

items ( filters  ) 

Retrieve cutomers data

Parameters:
array $filters
Returns:
array

Reimplemented in Mage_Customer_Model_Customer_Api_V2.

Definition at line 96 of file Api.php.

00097     {
00098         $collection = Mage::getModel('customer/customer')->getCollection()
00099             ->addAttributeToSelect('*');
00100 
00101         if (is_array($filters)) {
00102             try {
00103                 foreach ($filters as $field => $value) {
00104                     if (isset($this->_mapAttributes[$field])) {
00105                         $field = $this->_mapAttributes[$field];
00106                     }
00107 
00108                     $collection->addFieldToFilter($field, $value);
00109                 }
00110             } catch (Mage_Core_Exception $e) {
00111                 $this->_fault('filters_invalid', $e->getMessage());
00112             }
00113         }
00114 
00115         $result = array();
00116         foreach ($collection as $customer) {
00117             $data = $customer->toArray();
00118             $row  = array();
00119 
00120             foreach ($this->_mapAttributes as $attributeAlias => $attributeCode) {
00121                 $row[$attributeAlias] = (isset($data[$attributeCode]) ? $data[$attributeCode] : null);
00122             }
00123 
00124             foreach ($this->getAllowedAttributes($customer) as $attributeCode => $attribute) {
00125                 if (isset($data[$attributeCode])) {
00126                     $row[$attributeCode] = $data[$attributeCode];
00127                 }
00128             }
00129 
00130             $result[] = $row;
00131         }
00132 
00133         return $result;
00134     }

update ( customerId,
customerData 
)

Update customer data

Parameters:
int $customerId
array $customerData
Returns:
boolean

Reimplemented in Mage_Customer_Model_Customer_Api_V2.

Definition at line 143 of file Api.php.

00144     {
00145         $customer = Mage::getModel('customer/customer')->load($customerId);
00146 
00147         if (!$customer->getId()) {
00148             $this->_fault('not_exists');
00149         }
00150 
00151         foreach ($this->getAllowedAttributes($customer) as $attributeCode=>$attribute) {
00152             if (isset($customerData[$attributeCode])) {
00153                 $customer->setData($attributeCode, $customerData[$attributeCode]);
00154             }
00155         }
00156 
00157         $customer->save();
00158         return true;
00159     }


Member Data Documentation

$_mapAttributes [protected]

Initial value:

 array(
        'customer_id' => 'entity_id'
    )

Definition at line 36 of file Api.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:03 2009 for Magento by  doxygen 1.5.8