Public Member Functions | |
create ($customerId, $addressData) | |
info ($addressId) | |
update ($addressId, $addressData) | |
delete ($addressId) |
Definition at line 34 of file V2.php.
create | ( | $ | customerId, | |
$ | addressData | |||
) |
Create new address for customer
int | $customerId | |
array | $addressData |
Reimplemented from Mage_Customer_Model_Address_Api.
Definition at line 43 of file V2.php.
00044 { 00045 $customer = Mage::getModel('customer/customer') 00046 ->load($customerId); 00047 /* @var $customer Mage_Customer_Model_Customer */ 00048 00049 if (!$customer->getId()) { 00050 $this->_fault('customer_not_exists'); 00051 } 00052 00053 $address = Mage::getModel('customer/address'); 00054 00055 foreach ($this->getAllowedAttributes($address) as $attributeCode=>$attribute) { 00056 if (isset($addressData->$attributeCode)) { 00057 $address->setData($attributeCode, $addressData->$attributeCode); 00058 } 00059 } 00060 00061 if (isset($addressData->is_default_billing)) { 00062 $address->setIsDefaultBilling($addressData->is_default_billing); 00063 } 00064 00065 if (isset($addressData->is_default_shipping)) { 00066 $address->setIsDefaultShipping($addressData->is_default_shipping); 00067 } 00068 00069 $address->setCustomerId($customer->getId()); 00070 00071 $valid = $address->validate(); 00072 00073 if (is_array($valid)) { 00074 $this->_fault('data_invalid', implode("\n", $valid)); 00075 } 00076 00077 try { 00078 $address->save(); 00079 } catch (Mage_Core_Exception $e) { 00080 $this->_fault('data_invalid', $e->getMessage()); 00081 } 00082 00083 return $address->getId(); 00084 }
delete | ( | $ | addressId | ) |
Delete address
int | $addressId |
Reimplemented from Mage_Customer_Model_Address_Api.
Definition at line 170 of file V2.php.
00171 { 00172 $address = Mage::getModel('customer/address') 00173 ->load($addressId); 00174 00175 if (!$address->getId()) { 00176 $this->_fault('not_exists'); 00177 } 00178 00179 try { 00180 $address->delete(); 00181 } catch (Mage_Core_Exception $e) { 00182 $this->_fault('not_deleted', $e->getMessage()); 00183 } 00184 00185 return true; 00186 }
info | ( | $ | addressId | ) |
Retrieve address data
int | $addressId |
Reimplemented from Mage_Customer_Model_Address_Api.
Definition at line 92 of file V2.php.
00093 { 00094 $address = Mage::getModel('customer/address') 00095 ->load($addressId); 00096 00097 if (!$address->getId()) { 00098 $this->_fault('not_exists'); 00099 } 00100 00101 $result = array(); 00102 00103 foreach ($this->_mapAttributes as $attributeAlias => $attributeCode) { 00104 $result[$attributeAlias] = $address->getData($attributeCode); 00105 } 00106 00107 foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { 00108 $result[$attributeCode] = $address->getData($attributeCode); 00109 } 00110 00111 00112 if ($customer = $address->getCustomer()) { 00113 $result['is_default_billing'] = $customer->getDefaultBillingAddress() == $address->getId(); 00114 $result['is_default_shipping'] = $customer->getDefaultShippingAddress() == $address->getId(); 00115 } 00116 00117 return $result; 00118 }
update | ( | $ | addressId, | |
$ | addressData | |||
) |
Update address data
int | $addressId | |
array | $addressData |
Reimplemented from Mage_Customer_Model_Address_Api.
Definition at line 127 of file V2.php.
00128 { 00129 $address = Mage::getModel('customer/address') 00130 ->load($addressId); 00131 00132 if (!$address->getId()) { 00133 $this->_fault('not_exists'); 00134 } 00135 00136 foreach ($this->getAllowedAttributes($address) as $attributeCode=>$attribute) { 00137 if (isset($addressData->$attributeCode)) { 00138 $address->setData($attributeCode, $addressData->$attributeCode); 00139 } 00140 } 00141 00142 if (isset($addressData->is_default_billing)) { 00143 $address->setIsDefaultBilling($addressData->is_default_billing); 00144 } 00145 00146 if (isset($addressData->is_default_shipping)) { 00147 $address->setIsDefaultShipping($addressData->is_default_shipping); 00148 } 00149 00150 $valid = $address->validate(); 00151 if (is_array($valid)) { 00152 $this->_fault('data_invalid', implode("\n", $valid)); 00153 } 00154 00155 try { 00156 $address->save(); 00157 } catch (Mage_Core_Exception $e) { 00158 $this->_fault('data_invalid', $e->getMessage()); 00159 } 00160 00161 return true; 00162 }