Page 1 of 1

Help with passing data

Posted: Tue May 21, 2019 7:46 am
by masterross
Hi guys,
Recently I implemented OneSignal to OC 2.3 but I need some help.
I want to pass customer's name to OneSignal dashboard.
So I added:
$data['real_name'] = $activity_data['name'];

in
catalog/controller/account/login.php:

Code: Select all

                        // Add to activity log
                        if ($this->config->get('config_customer_activity')) {
                                $this->load->model('account/activity');

                                $activity_data = array(
                                        'customer_id' => $this->customer->getId(),
                                        'name'        => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
                                );

                                $data['real_name'] =  $activity_data['name'];
                                $this->model_account_activity->addActivity('login', $activity_data);
                        }
Now I want to send $real_name via:

Code: Select all

<script>
OneSignal.push(function() {
  OneSignal.sendTags({
    real_name: '<?php echo $real_name ?>'
  }).then(function(tagsSent) {
    // Callback called when tags have finished sending
    console.log("tagsSent: " + tagsSent.real_name);
  });
});
</script>
But where should I add the JS code to be triggered on a successful login?

Thank you!

Re: Help with passing data

Posted: Tue May 21, 2019 9:12 am
by straightlight
But where should I add the JS code to be triggered on a successful login?
catalog/view/theme/<your_theme>/template/common/header.tpl file.

Source: https://documentation.onesignal.com/doc ... e-examples

Re: Help with passing data

Posted: Tue May 21, 2019 3:40 pm
by masterross
Thanks mate,
But I've already added OneSignal SDK and it works.
But this is additional info (tags) which I want to be sent only on successful login.
That's why I get real_name var which should be sent in catalog/view/theme/default/template/account/login.tpl on sucessul login.
But dont know how to check is the login successful.

Re: Help with passing data

Posted: Tue May 21, 2019 5:23 pm
by masterross
OK, found a solution.
I have targeted the wrong controller file.
I added:

Code: Select all

 $data['real_name'] = $this->customer->getFirstName() . ' ' . $this->customer->getLastName();
in catalog/controller/account/account.php

And

Code: Select all

<script>
OneSignal.push(function() {
  OneSignal.sendTags({
    real_name: '<?php echo $real_name ?>'
  }).then(function(tagsSent) {
    // Callback called when tags have finished sending
    console.log("tagsSent: " + tagsSent.real_name);
  });
});
</script>
in account.tpl

Now is OK.

Re: Help with passing data

Posted: Tue May 21, 2019 7:53 pm
by straightlight
This is indeed the right controller. However, it will constantly provide the real name parameter each times the customer will log in into his account while your request is about whenever the customer has just logged in.

In the POST method of the account/login.php file, you need to add a session super global with: $this->session->data . Then, in the account/account.php file, in the index() method, you need to add:

Code: Select all

if (!empty($this->session->data['your_array_key'])) {
	// Your PHP code here
	
	unset ($this->session->data['your_array_key']);
}
Then, in your account/account.tpl file,

above:

Code: Select all

<script>
you need to add:

Code: Select all

<?php if (!empty($real_name)) { ?>
Then, after:

Code: Select all

</script>
add:

Code: Select all

<?php } ?>
This will resolved the issue.

Re: Help with passing data

Posted: Tue May 21, 2019 8:42 pm
by masterross
Thank for the hint mate!

This really do the job!

Regards!