Many thanks.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
The question is how do you this in a separate file outside OpenCart?
You might be able to find something in the session:
Code: Select all
print_r($_SESSION);
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
I have now figured this out as follows:
I'm using ProcessWire as my CMS for my website (hence the external PHP file). ProcessWire uses its own session API (rather than $_SESSION) but the principle is the same. If I include the ProcessWire index.php file in 'catalog/controller/common/header.php' I am able to access the ProcessWire session and set a session variable like this...
Code: Select all
include(DIR_PROCESSWIRE . 'index.php'); // I've set this in the OpenCart config.php
if(isset($this->session->data['customer_id'])) {
// add a variable to the ProcessWire session using the 'wire' API
$wire->session->set('oc_customer_id', $this->session->data['customer_id']);
//get some website content data from ProcessWire
echo("<!--" . $wire->pages->get('/')->title . "-->");
// send data to ProcessWire session
echo("<!--" . $wire->session->get('oc_customer_id') . "-->");
}
Any thoughts on this technique would be welcome.
Thanks.
From this day forward, the Opencart API example is now available on my Github namespace: https://github.com/straightlight/openca ... pload/api/ as it includes the customer logged in example. This example assumes you are using JSON GET requests as it includes the API backward compatibility for API security purposes. This should be the final release of this feature until the OC team releases new codes.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
That's awesome, thanks for this solution. This means I now have what I need to implement a reliable system that will do what I want. My main issue was how to get OpenCart and ProcessWire talking to each other. I have done some experimenting with the OpenCart API which allows me to login and logout, retrieve data etc, but does not allow me to check if an existing user has logged in themselves.
Thanks so much for your time on this, it is much appreciated.
Code: Select all
`customer_id` = '" . (int)$customer_id . "' AND `status` = '1'
Code: Select all
`c`.`customer_id` = '" . (int)$customer_id . "' AND `c`.`status` = '1'
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
That solution would be for local APIs. The solution provided on my previous post is about remote platforms. Besides, tracking the customer online table still requires to pass the customer ID through the browser either as a GET or POST method rather than assigning a token from API.
In addition, the customer online table is not running in real time mode which means a customer could just closed his browser and the customer online table would still show the customer ID on the database until expiry.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
That is not on a different platform and does not require GET or POST, just DB credentials and a query.I have OpenCart 3.0.2.0 running at 'example.com/shop'. How can I use a PHP file outside of OpenCart (i.e. 'example.com/file.php') to check if a user has logged in?
When a customer logs out the record in the customer_online table is removed instantly, you could even run DB triggers on that.
Maybe I am missing something but you can never determine if a user closes their browser in real time otherwise we would not need session garbage collection.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Which is why, a token is rather preferred to ensure remote platforms can get in without access issues. As for the DB query, if that were true, Opencart would not need to use backward compatibility as simply connecting to the database directly from the admin towards the catalog models would of suffice which, obviously for security reasons, is not the case here.Maybe I am missing something but you can never determine if a user closes their browser in real time otherwise we would not need session garbage collection.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Users browsing this forum: NicNie and 374 guests