Post by masterross » Tue May 21, 2019 7:46 am

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!

New member

Posts

Joined
Mon Jan 02, 2017 7:07 pm

Post by straightlight » Tue May 21, 2019 9:12 am

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

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com contractor officials representative


Administrator

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by masterross » Tue May 21, 2019 3:40 pm

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.

New member

Posts

Joined
Mon Jan 02, 2017 7:07 pm

Post by masterross » Tue May 21, 2019 5:23 pm

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.

New member

Posts

Joined
Mon Jan 02, 2017 7:07 pm

Post by straightlight » Tue May 21, 2019 7:53 pm

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.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com contractor officials representative


Administrator

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by masterross » Tue May 21, 2019 8:42 pm

Thank for the hint mate!

This really do the job!

Regards!

New member

Posts

Joined
Mon Jan 02, 2017 7:07 pm
Who is online

Users browsing this forum: No registered users and 61 guests