Magento作成ユーザコードCreating a new customer in Magento(RESTful,PHP)

2697 ワード

$customer = Mage::getModel('customer/customer');
//$customer  = new Mage_Customer_Model_Customer();
 
$password = 'iks123456';
$email = '[email protected]';
 
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($email);
//Zend_Debug::dump($customer->debug()); exit;
 
if(!$customer->getId()) 
{
    $customer->setEmail($email);
    $customer->setFirstname('ikeepstudying');
    $customer->setLastname('Liang');
    $customer->setPassword($password);
}
 
try 
{
    $customer->save();
    $customer->setConfirmation(null);
    $customer->save();
    $customer->sendNewAccountEmail();
 
    //Make a "login" of new customer
    Mage::getSingleton('customer/session')->loginById($customer->getId());
}
 
catch (Exception $ex) {
    //Zend_Debug::dump($ex->getMessage());
}   


$user = Mage::getSingleton('customer/session')->getCustomer();
echo '<pre>'; print_r($user); echo '</pre>';

 
詳細:
$address = Mage::getModel("customer/address");
$address->setCustomerId($customer->getId())
        ->setFirstname($customer->getFirstname())
        ->setMiddleName($customer->getMiddlename())
        ->setLastname($customer->getLastname())
        ->setCountryId('HR')
		//->setRegionId('1') //state/province, only needed if the country is USA
        ->setPostcode('31000')
        ->setCity('Osijek')
        ->setTelephone('0038511223344')
        ->setFax('0038511223355')
        ->setCompany('Inchoo')
        ->setStreet('Kersov')
        ->setIsDefaultBilling('1')
        ->setIsDefaultShipping('1')
        ->setSaveInAddressBook('1');
 
try{
    $address->save();
}
catch (Exception $e) {
    Zend_Debug::dump($e->getMessage());
}

 
データベース操作リファレンス:Magentoデータベースクエリー速記
 
詳細:
Programatically create customer and order in Magento with full blown One Page Checkout process under the hood
Programmatically adding new customers to the Magento store
 
原文:Magento作成ユーザーコードCreating a new customer in Magento(RESTful,PHP)