我有这样的代码:
public function editAddress($data, $id)
{
// $id - customer id, $data - data from form
$customer = Mage::getModel('customer/customer')
->load($id);
if (! $customer->getId() || ! $otherConditionIsValid) {
return $this;
}
$dataShipping = array(
'firstname' => $data['firstname'],
'middlename' => $data['middlename'],
'lastname' => $data['lastname'],
'prefix' => $data['prefix'],
'suffix' => $data['suffix'],
'company' => $data['company'],
'street' => $data['street'],
'country_id' => $data['country'],
'city' => $data['city'],
'region_id' => '',
'region' => $data['region'],
'postcode' => $data['postal'],
'country_id' => $data['country'],
'telephone' => $data['telephone'],
'fax' => $data['fax'],
);
$customerAddress = Mage::getModel('customer/address');
if ($defaultShippingId = $customer->getDefaultShipping()){
$customerAddress->load($defaultShippingId);
} else {
$customerAddress
->setCustomerId($post['customer_id'])
->setIsDefaultShipping('1')
->setSaveInAddressBook('1');
$customer->addAddress($customerAddress);
}
try {
$customerAddress
->addData($dataShipping)
->save();
} catch(Exception $e){
Mage::log('Address Save Error::' . $e->getMessage());
}
return $this;
}
它不更新数据库,而是我在magento中获取的数据数组,我非常希望你能帮助我,谢谢