[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Programmatically Change the Telephone number on an exisiting user in Magento

Posted on 2013-05-22
4
Medium Priority
?
3,310 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article was initially published on Monitis Blog, you can read it here . When it comes to deciding which approach to website performance monitoring is best for your business, unfortunately, like so many options in life . . . it depends. In th…
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 walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

649 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