Mage_Customer_Model_Customer_Api_V2 Class Reference

Inheritance diagram for Mage_Customer_Model_Customer_Api_V2:

Mage_Customer_Model_Customer_Api Mage_Customer_Model_Api_Resource Mage_Api_Model_Resource_Abstract

List of all members.

Public Member Functions

 create ($customerData)
 items ($filters)
 update ($customerId, $customerData)

Protected Member Functions

 _prepareData ($data)


Detailed Description

Definition at line 34 of file V2.php.


Member Function Documentation

_prepareData ( data  )  [protected]

Prepare data to insert/update. Creating array for stdClass Object

Parameters:
stdClass $data
Returns:
array

Definition at line 43 of file V2.php.

00044     {
00045         if (null !== ($_data = get_object_vars($data))) {
00046             return $_data;
00047         }
00048         return array();
00049     }

create ( customerData  ) 

Create new customer

Parameters:
array $customerData
Returns:
int

Reimplemented from Mage_Customer_Model_Customer_Api.

Definition at line 57 of file V2.php.

00058     {
00059         $customerData = $this->_prepareData($customerData);
00060         try {
00061             $customer = Mage::getModel('customer/customer')
00062                 ->setData($customerData)
00063                 ->save();
00064         } catch (Mage_Core_Exception $e) {
00065             $this->_fault('data_invalid', $e->getMessage());
00066         }
00067         return $customer->getId();
00068     }

items ( filters  ) 

Retrieve cutomers data

Parameters:
array $filters
Returns:
array

Reimplemented from Mage_Customer_Model_Customer_Api.

Definition at line 76 of file V2.php.

00077     {
00078         $collection = Mage::getModel('customer/customer')->getCollection()
00079             ->addAttributeToSelect('*');
00080 
00081         $preparedFilters = array();
00082         if (isset($filters->filter)) {
00083             foreach ($filters->filter as $_filter) {
00084                 $preparedFilters[$_filter->key] = $_filter->value;
00085             }
00086         }
00087         if (isset($filters->complex_filter)) {
00088             foreach ($filters->complex_filter as $_filter) {
00089                 $_value = $_filter->value;
00090                 $preparedFilters[$_filter->key] = array(
00091                     $_value->key => $_value->value
00092                 );
00093             }
00094         }
00095 
00096         if (!empty($preparedFilters)) {
00097             try {
00098                 foreach ($preparedFilters as $field => $value) {
00099                     if (isset($this->_mapAttributes[$field])) {
00100                         $field = $this->_mapAttributes[$field];
00101                     }
00102                     $collection->addFieldToFilter($field, $value);
00103                 }
00104             } catch (Mage_Core_Exception $e) {
00105                 $this->_fault('filters_invalid', $e->getMessage());
00106             }
00107         }
00108 
00109         $result = array();
00110         foreach ($collection as $customer) {
00111             $data = $customer->toArray();
00112             $row  = array();
00113 
00114             foreach ($this->_mapAttributes as $attributeAlias => $attributeCode) {
00115                 $row[$attributeAlias] = (isset($data[$attributeCode]) ? $data[$attributeCode] : null);
00116             }
00117 
00118             foreach ($this->getAllowedAttributes($customer) as $attributeCode => $attribute) {
00119                 if (isset($data[$attributeCode])) {
00120                     $row[$attributeCode] = $data[$attributeCode];
00121                 }
00122             }
00123 
00124             $result[] = $row;
00125         }
00126 
00127         return $result;
00128     }

update ( customerId,
customerData 
)

Update customer data

Parameters:
int $customerId
array $customerData
Returns:
boolean

Reimplemented from Mage_Customer_Model_Customer_Api.

Definition at line 137 of file V2.php.

00138     {
00139         $customer = Mage::getModel('customer/customer')->load($customerId);
00140 
00141         if (!$customer->getId()) {
00142             $this->_fault('not_exists');
00143         }
00144 
00145         foreach ($this->getAllowedAttributes($customer) as $attributeCode=>$attribute) {
00146             if (isset($customerData->$attributeCode)) {
00147                 $customer->setData($attributeCode, $customerData->$attributeCode);
00148             }
00149         }
00150 
00151         $customer->save();
00152         return true;
00153     }


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