Public Member Functions | |
__construct () | |
items ($customerId) | |
create ($customerId, $addressData) | |
info ($addressId) | |
update ($addressId, $addressData) | |
delete ($addressId) | |
Protected Attributes | |
$_mapAttributes |
Definition at line 34 of file Api.php.
__construct | ( | ) |
create | ( | $ | customerId, | |
$ | addressData | |||
) |
Create new address for customer
int | $customerId | |
array | $addressData |
Reimplemented in Mage_Customer_Model_Address_Api_V2.
Definition at line 93 of file Api.php.
00094 { 00095 $customer = Mage::getModel('customer/customer') 00096 ->load($customerId); 00097 /* @var $customer Mage_Customer_Model_Customer */ 00098 00099 if (!$customer->getId()) { 00100 $this->_fault('customer_not_exists'); 00101 } 00102 00103 $address = Mage::getModel('customer/address'); 00104 00105 foreach ($this->getAllowedAttributes($address) as $attributeCode=>$attribute) { 00106 if (isset($addressData[$attributeCode])) { 00107 $address->setData($attributeCode, $addressData[$attributeCode]); 00108 } 00109 } 00110 00111 if (isset($addressData['is_default_billing'])) { 00112 $address->setIsDefaultBilling($addressData['is_default_billing']); 00113 } 00114 00115 if (isset($addressData['is_default_shipping'])) { 00116 $address->setIsDefaultShipping($addressData['is_default_shipping']); 00117 } 00118 00119 $address->setCustomerId($customer->getId()); 00120 00121 $valid = $address->validate(); 00122 00123 if (is_array($valid)) { 00124 $this->_fault('data_invalid', implode("\n", $valid)); 00125 } 00126 00127 try { 00128 $address->save(); 00129 } catch (Mage_Core_Exception $e) { 00130 $this->_fault('data_invalid', $e->getMessage()); 00131 } 00132 00133 return $address->getId(); 00134 }
delete | ( | $ | addressId | ) |
Delete address
int | $addressId |
Reimplemented in Mage_Customer_Model_Address_Api_V2.
Definition at line 220 of file Api.php.
00221 { 00222 $address = Mage::getModel('customer/address') 00223 ->load($addressId); 00224 00225 if (!$address->getId()) { 00226 $this->_fault('not_exists'); 00227 } 00228 00229 try { 00230 $address->delete(); 00231 } catch (Mage_Core_Exception $e) { 00232 $this->_fault('not_deleted', $e->getMessage()); 00233 } 00234 00235 return true; 00236 }
info | ( | $ | addressId | ) |
Retrieve address data
int | $addressId |
Reimplemented in Mage_Customer_Model_Address_Api_V2.
Definition at line 142 of file Api.php.
00143 { 00144 $address = Mage::getModel('customer/address') 00145 ->load($addressId); 00146 00147 if (!$address->getId()) { 00148 $this->_fault('not_exists'); 00149 } 00150 00151 $result = array(); 00152 00153 foreach ($this->_mapAttributes as $attributeAlias => $attributeCode) { 00154 $result[$attributeAlias] = $address->getData($attributeCode); 00155 } 00156 00157 foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { 00158 $result[$attributeCode] = $address->getData($attributeCode); 00159 } 00160 00161 00162 if ($customer = $address->getCustomer()) { 00163 $result['is_default_billing'] = $customer->getDefaultBillingAddress() == $address->getId(); 00164 $result['is_default_shipping'] = $customer->getDefaultShippingAddress() == $address->getId(); 00165 } 00166 00167 return $result; 00168 }
items | ( | $ | customerId | ) |
Retrive customer addresses list
int | $customerId |
Definition at line 51 of file Api.php.
00052 { 00053 $customer = Mage::getModel('customer/customer') 00054 ->load($customerId); 00055 /* @var $customer Mage_Customer_Model_Customer */ 00056 00057 if (!$customer->getId()) { 00058 $this->_fault('customer_not_exists'); 00059 } 00060 00061 $result = array(); 00062 foreach ($customer->getAddresses() as $address) { 00063 $data = $address->toArray(); 00064 $row = array(); 00065 00066 foreach ($this->_mapAttributes as $attributeAlias => $attributeCode) { 00067 $row[$attributeAlias] = isset($data[$attributeCode]) ? $data[$attributeCode] : null; 00068 } 00069 00070 foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { 00071 if (isset($data[$attributeCode])) { 00072 $row[$attributeCode] = $data[$attributeCode]; 00073 } 00074 } 00075 00076 $row['is_default_billing'] = $customer->getDefaultBillingAddress() == $address->getId(); 00077 $row['is_default_shipping'] = $customer->getDefaultShippingAddress() == $address->getId(); 00078 00079 $result[] = $row; 00080 00081 } 00082 00083 return $result; 00084 }
update | ( | $ | addressId, | |
$ | addressData | |||
) |
Update address data
int | $addressId | |
array | $addressData |
Reimplemented in Mage_Customer_Model_Address_Api_V2.
Definition at line 177 of file Api.php.
00178 { 00179 $address = Mage::getModel('customer/address') 00180 ->load($addressId); 00181 00182 if (!$address->getId()) { 00183 $this->_fault('not_exists'); 00184 } 00185 00186 foreach ($this->getAllowedAttributes($address) as $attributeCode=>$attribute) { 00187 if (isset($addressData[$attributeCode])) { 00188 $address->setData($attributeCode, $addressData[$attributeCode]); 00189 } 00190 } 00191 00192 if (isset($addressData['is_default_billing'])) { 00193 $address->setIsDefaultBilling($addressData['is_default_billing']); 00194 } 00195 00196 if (isset($addressData['is_default_shipping'])) { 00197 $address->setIsDefaultShipping($addressData['is_default_shipping']); 00198 } 00199 00200 $valid = $address->validate(); 00201 if (is_array($valid)) { 00202 $this->_fault('data_invalid', implode("\n", $valid)); 00203 } 00204 00205 try { 00206 $address->save(); 00207 } catch (Mage_Core_Exception $e) { 00208 $this->_fault('data_invalid', $e->getMessage()); 00209 } 00210 00211 return true; 00212 }
$_mapAttributes [protected] |