Question

In order for me to get a Prestashop user's cart, I first need to know who the user is in my external CodeIgniter application.

I have tried various attempts like the following: http://www.prestashop.com/forums/topic/204227-webservice-and-check-if-user-is-logged-in/ and http://www.prestashop.com/forums/topic/156218-solvedish-integrating-prestashop-into-a-pre-developed-website/ and even Prestashop: Session cookies & login and http://webilyst.com/prestashop-cookie-structure/

But I could not get it working. For some reason, the moment I include config.inc.php, it redirects to the shop - instead of allowing me to get the ID required.

My question: Any idea how to get this current user ID from PrestaShop in external epplication?

Edit 1 I am using CI 2.1.4 and PrestaShop 1.5.6.x.

Edit 2 Seems like the articles I have read is for an older version of PS. That code actually gets to a point where the Shop is being initialized, and once that is done, in Shop.php, the user is redirected to the shop. I do not want this to happen - I just want to find out who the current logged in user is.

Was it helpful?

Solution

You can get the current customer ID with the following code:

include($prestashopBasePath . '/config/config.inc.php');
$context = Context::getContext();
$customerId = $context->customer->id;

The reason why you are redirected is that you execute the script from a URL that is different from the shop URL defined in back-office -> Preferences -> Set shop URL. For example the shop URL is example.com/presta and your script is in example.com/other/script.php.

The solution is to move your script to the PrestaShop directory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top