我需要使用magento批量更新客户街头地址。为此我在客户网格控制器中写了bultupdate函数。这是查询,但它不起作用。如何更改此查询以使用customerid更新街道地址
public function massUpdateAction()
{
$customerIds = $this->getRequest()->getParam('customer');
$street_type = $this->getRequest()->getParam('street');
if (!is_array($customerIds)) {
$this->_getSession()->addError($this->__('Please select customer(s).'));
} else {
if (!empty($customerIds)) {
try {
foreach ($customerIds as $customerId) {
Mage::getSingleton('customer/address')
->updateAttributes($customerIds, array('billing_street_full' => $street_type), $storeId);
}
$this->_getSession()->addSuccess(
$this->__('Total of %d record(s) have been Updated.', count($customerIds))
);
} catch (Exception $e) {
$this->_getSession()->addError($e->getMessage());
}
}
}
$this->_redirect('*/*/index');
}
答案 0 :(得分:1)
试试这个:
try {
foreach ($customerIds as $customerId) {
$addresses = Mage::getModel('customer/customer')->load($customerId)->getAddressesCollection();
foreach ($addresses as $address) {
$address->setData('billing_street_full', $street_type)->save();
}
}
$this->_getSession()->addSuccess(
$this->__('Total of %d record(s) have been Updated.', count($customerIds))
);
} catch (Exception $e) {
$this->_getSession()->addError($e->getMessage());
}