?
Solved

Programmatically Change the Telephone number on an exisiting user in Magento

Posted on 2013-05-22
4
Medium Priority
?
3,232 Views
Last Modified: 2016-03-02
I have code that sucessfully sets the phone number when creating a new user in Magento programmatically.

$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
            
  //setting data such as email, firstname, lastname, and password
$customer->firstname = $firstname;
$customer->lastname = $lastname;
$customer->email = $email;
$customer->password_hash = md5($password);
if($customer->save())
{
      $address = Mage::getModel("customer/address");
      $address->setCustomerId($customer->getId());
      $address->setFirstname($customer->firstname);
      $address->setLastname($customer->lastname);
      $address->setTelephone("55555555555);
                  $address->save();
      echo $customer->firstname." ".$customer->lastname." information is saved!";
}            

However, I can't my code to work on an existing customer:                  
      
$customer = Mage::getModel('customer/customer');
$customer->loadByEmail($email);
if($customer->getId())
{
      $address = Mage::getModel("customer/address");  
      $address->setTelephone($points);
      $address->save();
}

What am I doing wrong?
0
Comment
Question by:kenozzy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 39193033
Try using
$address->setSaveinAddressBook('1');

Open in new window

before saving the $address.
0
 

Author Comment

by:kenozzy
ID: 39195340
Ok, here's the code with your addition... this does update the phone number, but it creates a new address every time.

	$customer = Mage::getModel('customer/customer');
	$customer->loadByEmail($email);
	if($customer->getId()) 
	{
		$address = Mage::getModel("customer/address"); 
  	                  $address->setCustomerId($customer->getId());
		$address->setTelephone($points);
		$address->setSaveinAddressBook('1'); 
		$address->save();
                  }

Open in new window

0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 2000 total points
ID: 39197056
What we do is delete the address that we are modifying and then when it creates the new one...
0
 

Author Closing Comment

by:kenozzy
ID: 39215887
Deleting first worked great.
0

Featured Post

DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question