2

How can we set Country in Customer A/c Details Manually.

I am trying to execute code as following and

So Please Suggest Answer in that criteria :

 if (!$customer->getId()) {
                $customer->setEmail($email);
                $customer->setFirstname($name);
                $customer->setLastname($lastname);
                $customer->setPassword($password); 
}
  • 1
    the Problem is, that the country is saved in the address, so you need to change and save the address – Fabian Blechschmidt Mar 6 '13 at 13:26
2

As @FabianBlechschmidt said - the customer entity doesn't have a country, the customer has an address, which has a country.

Depending on what address you wanted to update exactly, you could use something like this

$_customer = Mage::getModel('customer/customer')->load($customerId);

Then load the respective model,

$_addresssModel = $_customer->getDefaultBillingAddress();
$_addresssModel = $_customer->getDefaultShippingAddress();

Then set the country ID,

$_addresssModel->setCountryId('x')->save();
  • But How to get countryName using setCountryId ? – LuFFy Mar 6 '13 at 13:39
  • 1
    Get or Set? If you want to get the country name from the country ID, use $countryName = Mage::getModel('directory/country')->load($countryCode)->getName(); - if you want to know a list of the country codes, see pastebin.com/97sBAB4J – Ben Lessani - Sonassi Mar 6 '13 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.