0

我需要使用 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');
}
4

1 回答 1

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());
            }
于 2013-01-30T16:30:38.510 回答