import product programmly

本文介绍了一个Magento系统的功能,用于向系统中添加新客户。通过设置特定的网站ID和商店信息,该功能能够创建新的客户记录,并保存客户的姓名、电子邮件等基本信息。此外,还实现了为新客户生成随机密码的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 public function addCustomer($data) {
    	Mage::app()->setCurrentStore(1);
    	$websiteId = 1;
    	$store = Mage::app()->getStore();
    	if (!$this->customerExists($data['email'])) {
	    	$customer = Mage::getModel("customer/customer");
	    	
	    	$customer->setWebsiteId = $websiteId;
	    	$customer->setStore($store);
	    	$old_password = $this->randomPassword();
	    	// If new, save customer information
	    	$customer->setData('firstname',$data['firstname']);
	    	$customer->setData('lastname' , $data['lastname']);
	    	$customer->setData('email',$data['email']);
	    	$customer->setPassword($old_password);
	    	$customer->setData('old_password', $old_password);
	    	
	    	$customer->save();
	    	$write = Mage::getSingleton('core/resource')->getConnection('core_write');
	    	$sql = "update old_customer set status = 1 where email = ?";
	    	$write->query($sql,array($data['email']));
	    	var_dump($customer->getEmail() . ' import successed. password:' . $customer->getOldPassword());
	    }
    }

 生成随机的密码

 function randomPassword() {
    	$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
    	$pass = array(); //remember to declare $pass as an array
    	$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    	for ($i = 0; $i < 8; $i++) {
    		$n = rand(0, $alphaLength);
    		$pass[] = $alphabet[$n];
    	}
    	return implode($pass); //turn the array into a string
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值