0

$session = Mage::getSingleton('customer/session'); $customer_id = $session->getId(); $customer_data = Mage::getModel('customer/customer')->load($customer_id); print_r($customer_data);

通过此代码可以获取用户详细信息我需要知道如何使用 PHP 代码以相同的方式编辑地址、密码等用户详细信息 谢谢大家

4

3 回答 3

4

您可以使用 $customer_id 设置密码

$password = 'Any Things'
$customer = Mage::getModel('customer/customer')->load($customer_id);
$customer->setPassword($password);
$customer->save();

对于编辑地址,您必须加载地址模型

例如,如果您想编辑帐单地址:

 $customer = Mage::getModel('customer/customer')->load($customer_id);
 $address = $customer->getDefaultBilling();

 $address->setFirstname("Test");
 $address->save();

或:使用从客户对象获取的地址 ID:

   $address = Mage::getModel('customer/address')->load($customerAddressId);
   $address->setFirstname("Test"); 
   $address->save();
于 2013-05-16T12:52:45.680 回答
1

您可以使用 php 魔术 get 和 set 方法

假设设置您可以使用的密码$customer_data->setPassword('1234567');

$customer_data->save();

对于客户地址

$_custom_address = array (
'firstname' => 'firstname',
'lastname' => 'lastname',
'street' => array (
    '0' => 'Sample address part1',
    '1' => 'Sample address part2',
),
'city' => 'city',
'region_id' => '',
'region' => '',
'postcode' => '31000',
'country_id' => 'US', 
'telephone' => '0038531555444',
);

$customAddress = Mage::getModel('customer/address')

$customAddress->setData($_custom_address)
        ->setCustomerId($customer->getId())
        ->setIsDefaultBilling('1')
        ->setIsDefaultShipping('1')
        ->setSaveInAddressBook('1');

try {
    $customAddress->save();
}
catch (Exception $ex) {
    //Zend_Debug::dump($ex->getMessage());
}

欲了解更多信息http://inhoo.net/ecommerce/magento/programming-magento/programatically-create-customer-and-order-in-magento-with-full-blast-one-page-checkout-process-under-the -兜帽/

于 2013-05-16T12:44:38.820 回答
0

您可以使用 Mage_Customer_Model_Customer 类的方法:

$customerSession = Mage::getSingleton('customer/session');
$customerModel = Mage::getModel('customer/customer')->load($customerSession->getId());
$customerModel->changePassword('new_password');
于 2013-05-16T12:53:46.490 回答