I'm trying to execute a java-script command when the customer successfully registers an account, I tried the following, but the java-script command doesn't get executed.Used code
Does somebody now how I can achieve this? Thank you in advance.
[EDIT] I actually fixed it myself, I wanted to send some customer data to the html page via javascript. If you want to achieve this, please read my answer.
3 Answers 3
After some more digging, and thanks to the answers from kiatng and lalit mohan, I found the answer.
I wanted to list all customer details to the page via javascript.
In the mage.php file, located at Magento\apps\magento\htdocs\app:
 public static function dispatchEvent($name, array $data = array())
{
 //Custom code, this is being executed when the customer succesfully registers
 if($name == "customer_register_success")
 {
 $customer = $data['customer'];
 $customerData = Mage::getModel('customer/customer')->load($customer->getId())->getData();
 $out = "";
 foreach( $customerData as $key => $value ) {
 //this prevents the password hash to be show in the session 
 if(!$key == "password_hash")
 {
 $out .= "|" . $key . ':' . $value;
 }
 }
 //Put customer vallues in the sessions
 session_start();
 $_SESSION["data"] = $out;
 }
 //Logging to htdocs/var/log/system.log
 Mage::log('Event fired: ' . $name . "__" . $data);
 //Default code (this was already there)
 Varien_Profiler::start('DISPATCH EVENT:'.$name);
 $result = self::app()->dispatchEvent($name, $data);
 Varien_Profiler::stop('DISPATCH EVENT:'.$name);
 return $result;
}
Then in your javascript:
var customerdata = "<?php session_start(); echo $_SESSION["data"]; ?>";
This will output all customer data to a string.
- 
 Did you add the js code in the same php file?arqam– arqam2019年09月03日 09:01:58 +00:00Commented Sep 3, 2019 at 9:01
you can run profiler to debug problem by edit temporarily Mage.php file. so you can output of all events for particular request..
File: app/Mage.php
public static function dispatchEvent($name, array $data = array())
{
 Mage::log('Event: ' . $name); //not using Mage::log, as 
 //file_put_contents('/tmp/test.log','Dispatching '. $name. "\n",FILE_APPEND); //poor man's log
 Varien_Profiler::start('DISPATCH EVENT:'.$name);
 $result = self::app()->dispatchEvent($name, $data);
 #$result = self::registry('events')->dispatch($name, $data);
 Varien_Profiler::stop('DISPATCH EVENT:'.$name);
 return $result;
}
In order to execute your js, you'll need to find a way to always redirect to the page where you have your js embedded. You can do this by hard-setting the success_url. One way to do this is to listen to the event customer_success_event, as indicated in your attached image. After you have set this up, then the code is quite simple:
public funstion setCustomerRegisterSuccessUrl($observer)
{
 $successUrl = Mage::getUrl('your_module/your_controller/your_action');
 $controller = $observer->getEvent()->getAccountController();
 $controller->getRequest()->setParam('success_url', $successUrl);
}
$this->_redirectSuccess($url);where $url is by defaultcustomer/account/indexor the URL paramsuccess_url, seeMage_Core_Controller_Varien_Action ::_redirectSuccess(). So, in order to execute your js, you'll need to find a way to always redirect to the page where you have your js embedded. You can do this by hard-setting thesuccess_url.