Skip to main content
added 909 characters in body
Source Link

Try

$address_data = array (
            'firstname' => 'fname here',
            'lastname' => 'lastname here',
            'street' => '123 test st',
            'city' => 'city here',
            ...
        );

$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
// Set customer
$customer->setEmail($this->_userEmail);
$customer->setPassword($this->_userPassword);
...

$address = Mage::getModel('customer/address');
$address->setData($address_data)
        ->setIsDefaultBilling('1')
        ->setIsDefaultShipping('0')
        ->setSaveInAddressBook('1');

$customer->addAddress($address);

try {
    $customer->save();
}
catch (Exception $ex) {
    $this->_error($ex->getMessage());
    return;
}

You need to assign the customer id to the address

protected function _registerUser()
{
    .....

    // Try create customer
    try {

        
        $customer->setConfirmation(null);
        $customer->save();
        if($customer->getId()){
           $address->setCustomerId($customer->getId()); 
           $address->save();
        }

        ...

See Programmatically adding new customers to the Magento store

You need to assign the customer id to the address

protected function _registerUser()
{
    .....

    // Try create customer
    try {

        
        $customer->setConfirmation(null);
        $customer->save();
        if($customer->getId()){
           $address->setCustomerId($customer->getId()); 
           $address->save();
        }

        ...

See Programmatically adding new customers to the Magento store

Try

$address_data = array (
            'firstname' => 'fname here',
            'lastname' => 'lastname here',
            'street' => '123 test st',
            'city' => 'city here',
            ...
        );

$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
// Set customer
$customer->setEmail($this->_userEmail);
$customer->setPassword($this->_userPassword);
...

$address = Mage::getModel('customer/address');
$address->setData($address_data)
        ->setIsDefaultBilling('1')
        ->setIsDefaultShipping('0')
        ->setSaveInAddressBook('1');

$customer->addAddress($address);

try {
    $customer->save();
}
catch (Exception $ex) {
    $this->_error($ex->getMessage());
    return;
}

You need to assign the customer id to the address

protected function _registerUser()
{
    .....

    // Try create customer
    try {

        
        $customer->setConfirmation(null);
        $customer->save();
        if($customer->getId()){
           $address->setCustomerId($customer->getId()); 
           $address->save();
        }

        ...

See Programmatically adding new customers to the Magento store

Source Link

You need to assign the customer id to the address

protected function _registerUser()
{
    .....

    // Try create customer
    try {

        
        $customer->setConfirmation(null);
        $customer->save();
        if($customer->getId()){
           $address->setCustomerId($customer->getId()); 
           $address->save();
        }

        ...

See Programmatically adding new customers to the Magento store