The scenario : I am trying to register adress information such as phone, company name , etc via ajax using the youama ajax login/registration module. Right now only email, names, password seem to be posted. I am almost there but there must be doing something wrong in this the Model file: Ajaxregister.php
I took example from inchoo recent post: http://inchoo.net/magento/programming-magento/programmaticaly-adding-new-customers-to-the-magento-store/
It says that it should use Mage::getModel('customer/address') for adress data, and not Mage::getModel('customer/customer').
However I tryed and it does not post any phone/company name in the DB.
Here is the code below:
class Youama_Ajaxlogin_Model_Ajaxregister
extends Youama_Ajaxlogin_Model_Validator
{
/**
* Init.
*/
public function _construct()
{
parent::_construct();
// Result for Javascript
$this->_result = '';
$this->_userId = -1;
// Terms and conditions has been accepted
if ($_POST['licence'] == 'ok') {
$this->setEmail($_POST['email']);
// If this email is already exist
if ($this->isEmailExist()) {
$this->_result .= 'emailisexist,';
// If this email is not exist yet.
} else {
$this->setPassword($_POST['password'], $_POST['passwordsecond']);
$this->setName($_POST['firstname'], $_POST['lastname']);
$this->setCompany($_POST['company']);
$this->setTelephone($_POST['telephone']);
$this->setNewsletter($_POST['newsletter']);
// If there are no errors
if ($this->_result == '') {
// Try register user
$this->_registerUser();
// Try subscribe user to newsletter
if ($this->_userNewsletter == true) {
$this->_subscribeUser();
}
}
}
// Terms and conditions has not been accepted
} else {
$this->_result = 'nolicence,';
}
}
/**
* Register user via Mage's API.
*/
protected function _registerUser()
{
// Empty customer object
$customer = Mage::getModel('customer/customer');
$address = Mage::getModel('customer/address');
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$address->setWebsiteId(Mage::app()->getWebsite()->getId());
// Set customer
$customer->setEmail($this->_userEmail);
$customer->setPassword($this->_userPassword);
$customer->setFirstname($this->_userFirstName);
$customer->setLastname($this->_userLastName);
$address->setCompany($this->_userCompany);
$address->setTelephone($this->_userTelephone);
// Try create customer
try {
$customer->save();
$address->save();
$customer->setConfirmation(null);
$customer->save();
$storeId = $customer->getSendemailStoreId();
$customer->sendNewAccountEmail('registered', '', $storeId);
Mage::getSingleton('customer/session')->loginById($customer->getId());
$this->_userId = $customer->getId();
$this->_result = 'success';
// Error by injected HTML/JS
} catch (Exception $ex) {
$this->_result .= 'frontendhackerror,';
}
}