Luca Becchetti
Luca Becchetti

Reputation: 1280

Access logged user prestashop

I'm new on prestashop, I have a separated php page in the same host of the prestashop installation, how can I access the logged prestashop user from this page?

thanks!

Upvotes: 0

Views: 294

Answers (2)

waren0809
waren0809

Reputation: 111

As pointed out by Melvita, you first need to include config.inc.php and use the Context object

What is stored by the Context?

These objects are always accessible through the context:

Language. Set with the customer or employee language.
Country. Default country.
Currency. Set with the customer currency or the shop's default currency.
Shop. Current shop.
Cookie. Cookie instance.
Link. Link instance.
Smarty. Smarty instance.

These objects are only accessible for the customer Context:

Customer. Existing customer retrieved from the cookie or default customer.
Cart. Current cart.
Controller. Current controller instance.

These objects are only accessible for the administrator Context: Employee. Current employee.

<?php
include(dirname(__FILE__) . '/config/config.inc.php');
$context = Context::GetContext();  //call getContext() from context class
$customer = $context->customer;    //get logged customer info
$customerName = $customer->firstname; //get user first name
$customerLastName = $customer->lastname; //get user last name
//to see all information that the context object can give you on your customer, just so a var_dump on $customer

?>    

Source : http://doc.prestashop.com/display/PS16/Using+the+Context+Object#UsingtheContextObject-WhatisstoredbytheContext?

Upvotes: 1

ggg
ggg

Reputation: 1192

As N.Wouda told you, you have to use the context, by exemple to get the email of current user logged :

<?php
include(dirname(__FILE__) . '/config/config.inc.php');
$c = Context::getContext();
$emailOfLoggedUser = $c->customer->email;
echo $emailOfLoggedUser;
?>

Upvotes: 1

Related Questions