1

It all starts with the createPostAction:

public function createPostAction()
{
    /** @var $session Mage_Customer_Model_Session */
    $session = $this->_getSession();
    if ($session->isLoggedIn()) {
        $this->_redirect('*/*/');
        return;
    }
    $session->setEscapeMessages(true); // prevent XSS injection in user input
    if (!$this->getRequest()->isPost()) {
        $errUrl = $this->_getUrl('*/*/create', array('_secure' => true));
        $this->_redirectError($errUrl);
        return;
    }

    $customer = $this->_getCustomer();

    try {
        $errors = $this->_getCustomerErrors($customer);

        if (empty($errors)) {
            $customer->cleanPasswordsValidationData();
            $customer->save();
            $this->_dispatchRegisterSuccess($customer);
            $this->_successProcessRegistration($customer);
            return;
        } else {
            $this->_addSessionError($errors);
        }
    } catch (Mage_Core_Exception $e) {
        $session->setCustomerFormData($this->getRequest()->getPost());
        if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
            $url = $this->_getUrl('customer/account/forgotpassword');
            $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
            $session->setEscapeMessages(false);
        } else {
            $message = $e->getMessage();
        }
        $session->addError($message);
    } catch (Exception $e) {
        $session->setCustomerFormData($this->getRequest()->getPost())
            ->addException($e, $this->__('Cannot save the customer.'));
    }
    $errUrl = $this->_getUrl('*/*/create', array('_secure' => true));
    $this->_redirectError($errUrl);
}

And I guess that customer data is retrieved inside $this->_GetCustomer():

protected function _getCustomer()
{
    $customer = $this->_getFromRegistry('current_customer');
    if (!$customer) {
        $customer = $this->_getModel('customer/customer')->setId(null);
    }
    if ($this->getRequest()->getParam('is_subscribed', false)) {
        $customer->setIsSubscribed(1);
    }
    /**
     * Initialize customer group id
     */
    $customer->getGroupId();

    return $customer;
}

But here comes the problem. In which command does Magento process the POST request? Here is my guess for each command:

  1. $customer = $this->_getFromRegistry('current_customer'); This one gets the current customer from registry.

  2. This paragraph means, if the current customer doesn't exist, you assign an empty model to it. If it exits, check from the POSTed data whether to subscribe to the newsletter.:

    if (!$customer) {
        $customer = $this->_getModel('customer/customer')->setId(null);
    }
    if ($this->getRequest()->getParam('is_subscribed', false)) {
        $customer->setIsSubscribed(1);
    }
    
  3. $customer->getGroupId(); gets the group id.

But where is the main information of a customer processed? Is it inherent in the _getFromRegistry?

Digging deeper, the function is:

protected function _getFromRegistry($path)
{
    return Mage::registry($path);
}

public static function registry($key)
{
    if (isset(self::$_registry[$key])) {
        return self::$_registry[$key];
    }
    return null;
}

It seems only a simple global storage service. So is it inherent in the _getModel? But again I found nothing about getRequest() in the Customer model.

So where is the interaction between the frontend and the backend? Where does the POSTed data go? I can only see the explicit one $this->getRequest()->getParam('is_subscribed', false), but where are the others?

3

You need to look into the try, catch section. There is where magic happens.

    try {
        $errors = $this->_getCustomerErrors($customer);

        if (empty($errors)) {
            $customer->cleanPasswordsValidationData();
            $customer->save();
            $this->_dispatchRegisterSuccess($customer);
            $this->_successProcessRegistration($customer);
            return;
        } else {
            $this->_addSessionError($errors);
        }
    } 

There is mainly two important steps within this code block.

  1. $this->_getCustomerErrors($customer) This call is what you are looking for. This function is defined inside AccountController class itself. This class validates each posted data and if they seems good, will add that to the customer instance that we have retrieved from the call $this->_getCustomer() (that happends just above the try,catch code block).

  2. If there is no validation error present, then it will save the data to the table by invoking this call $customer->save(). Since $customer instance now holds all data which is posted by the form (that is what happens in the first step), this action will save all those data into the database.

Hope that helps

| improve this answer | |

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.