您的位置:首页 > 其它

magento注册

2015-09-06 21:44 525 查看
1.地址保存

$_custom_address=array(
'firstname'=>'Branko',
'lastname'=>'Ajzele',
'street'=>array(
'0'=>'Sampleaddresspart1',
'1'=>'Sampleaddresspart2',
),
'city'=>'Osijek',
'region_id'=>'',
'region'=>'',
'postcode'=>'31000',
'country_id'=>'HR',/*Croatia*/
'telephone'=>'0038531555444',
);
$customAddress=Mage::getModel('customer/address')
//$customAddress=newMage_Customer_Model_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());
}

[/code]
2。

publicfunctioncreatePostAction()参考

得到空的customer

$customer=Mage::getModel('customer/customer')->setId(null);

if($this->getRequest()->getParam('is_subscribed',false)){
$customer->setIsSubscribed(1);
}

$customer->getGroupId();

$customer->setPassword($this->getRequest()->getPost('password'));
$customer->setConfirmation($this->getRequest()->getPost('confirmation'));
$customer->save();

3.publicfunctionimportFromTextArray(array$row)



4.完成的新建例子

$customer_email='test@testemail.com';//emailadressthatwillpassbythequestionaire

$customer_fname='test_firstname';//wecansetatemporyfirstnamehere

$customer_lname='test_lastname';//wecansetatemporylastnamehere

$passwordLength=10;//thelenghtofautogeneratedpassword

$customer=Mage::getModel('customer/customer');

$customer->setWebsiteId(Mage::app()->getWebsite()->getId());

$customer->loadByEmail($customer_email);/**Checkiftheemailexistonthesystem.*IfYES,itwillnotcreateauseraccount.*/

if(!$customer->getId()){//settingdatasuchasemail,firstname,lastname,andpassword

$customer->setEmail($customer_email);

$customer->setFirstname($customer_fname);

$customer->setLastname($customer_lname);

$customer->setPassword($customer->generatePassword($passwordLength));}

try{//thesavethedataandsendthenewaccountemail.

$customer->save();

$customer->setConfirmation(null);

$customer->save();

$customer->sendNewAccountEmail();

}catch(Exception$ex){}



5.有一个好例子

$_customer=Mage::getModel('customer/customer');
$_customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$_customer->setEmail('joe@bloggs.com');
$_customer->setFirstname('Joe');
$_customer->setLastname('bloggs');
$_customer->password_hash=md5("password123");
try{
$_customer->save();
$_customer->setConfirmation(null);
$_customer->save();
}catch(Exception$e){
//Zend_Debug::dump($e->getMessage());
}

//addtheirdetails
$address=Mage::getModel("customer/address");
$address->setCustomerId($_customer->getId());
$address->firstname=$_customer->firstname;
$address->lastname=$_customer->lastname;
$address->postcode="4999";
$address->telephone="0038531444888";
$address->company="Somecompanyt";
$address->street="Unknown";
$address->city="Unknown";
$address->country_id="AU";
$address->setIsDefaultBilling(true);
$address->save();
/*Subscribethemtothenewsletter*/
$subscriber=Mage::getModel('newsletter/subscriber')->loadByEmail($email);
$subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
$subscriber->setSubscriberEmail($email);
$subscriber->setSubscriberConfirmCode($subscriber->RandomSequence());
$subscriber->setStoreId(Mage::app()->getStore()->getId());
$subscriber->setCustomerId($_customer->getId());
$subscriber->save();



6.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: