RavenStar Posted February 5, 2010 Share Posted February 5, 2010 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 More sharing options...
Ovi Posted February 7, 2010 Share Posted February 7, 2010 I was about to post the same question! Very interested. Link to comment Share on other sites More sharing options...
rocky Posted February 8, 2010 Share Posted February 8, 2010 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 More sharing options...
Ovi Posted February 8, 2010 Share Posted February 8, 2010 Works like a charm, thanks a lot rocky! Link to comment Share on other sites More sharing options...
RavenStar Posted February 9, 2010 Author Share Posted February 9, 2010 What file(s) must I include for this to work? Since my module posts to an external php script and does its processing there.Thank you. Link to comment Share on other sites More sharing options...
rocky Posted February 10, 2010 Share Posted February 10, 2010 You must include init.php to use the $cookie variable. Link to comment Share on other sites More sharing options...
RavenStar Posted February 10, 2010 Author Share Posted February 10, 2010 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 More sharing options...
Ovi Posted February 10, 2010 Share Posted February 10, 2010 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 More sharing options...
RavenStar Posted February 10, 2010 Author Share Posted February 10, 2010 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 More sharing options...
rocky Posted February 11, 2010 Share Posted February 11, 2010 Trying writing the following at the top of the insertMSG() function and any other function that uses $cookie: global $cookie; Link to comment Share on other sites More sharing options...
RavenStar Posted February 22, 2010 Author Share Posted February 22, 2010 I know this is a very late reply, but I just wanted to touch base incase anyone else was experiencing the same problem as me.The last suggestion of rocky worked like a charm, I had to include $cookie as a global variable.Thanks a lot for that rocky Link to comment Share on other sites More sharing options...
ryans121 Posted February 22, 2010 Share Posted February 22, 2010 hi, i'm new in here..thanks for the solution... Link to comment Share on other sites More sharing options...
Recommended Posts