Jump to content

[SOLVED] Hook Username?


Recommended Posts

Hi there,
I'm fairly new to Prestashop but I'm writing my own script so customers can leave testimonials.
Everything is working fine except for one thing, I'm unable to retrieve the customers first & last name that would get appended to their testimonial. How can I go about doing this?
I've figured out that "{$customerName}" works within the template files, and while I only wanted their first name and first letter of last (Eg: John D) and $customerName displays their full name, that is fine for the time being.

In short...
How can I easily retrieve their first & last name?


Thanks a lot :)

Link to comment
Share on other sites

You can access the first name and last name of the currently-logged-in customer using $cookie->customer_firstname and $cookie->customer_lastname. You can use substr($cookie->customer_lastname, 0, 1) in a PHP file to get the first letter only, or {$cookie->customer_lastname|substr:0:1} in a TPL file.

Link to comment
Share on other sites

Thanks a lot for that rocky, however I'm afraid I've given that a try already and had no success.

I've tried including init.php in several different locations however I still receive nothing with "$cookie->customer_firstname".


Yes I'm logged in, as both a test customer account aswell as admin for the backend. Any idea why I'm not getting anything with $cookie? Is there perhaps another method I could try, a session variable perhaps?

Thank you.

Link to comment
Share on other sites

I'm personally using a custom theme created by myself , so i'm just using the following code in a certain location in header.tpl :


Client:  {if $logged}
{$cookie->customer_lastname} {$cookie->customer_firstname|substr:0:1}. 
({l s='Log out' mod='blockuserinfo'})
{else}
{l s='Log in' mod='blockuserinfo'}
   {/if}
{l s='My Account' mod='blockuserinfo'}

Link to comment
Share on other sites

Thanks for the reply Ovi, however it's not the template file that I'm having issues with, I'm using the same method to disable their name.
What I'm trying to do is retrieve their name from within a php function that I've written.


Below are the main snippets of my code/files;

testimonial.php (User views this page)

<?PHP
require_once(dirname(__FILE__).'/config/config.inc.php');
require_once(dirname(__FILE__).'/header.php');
require_once(dirname(__FILE__).'/init.php');

  require_once("testimonialClass.php"); 
  $startTestimonial = new testimonial();          
?>
<body>


        <?php $startTestimonial->doProcess(); ?>


<?PHP $smarty->display(_PS_THEME_DIR_.'testimonial.tpl');  ?>
require_once(dirname(__FILE__).'/footer.php');




testimonialClass.php (Used to process data entered by user)

class testimonial {
  var $PerPage = 10;
  var $selfName = 'testimonials.php';
//   var $userName = $cookie->customer_firstname;  // Doesn't work...

// ..........More functions here, which all work fine..........

function insertMSG() {

  $name = $cookie->customer_firstname;

// ........More code here, which works fine, except it seems $name is blank.........




It seems $name is always blank, no matter where I attempt to set it.
Any ideas?

Link to comment
Share on other sites

  • 2 weeks later...
×
×
  • Create New...