Post by MarkF » Sat Mar 21, 2009 8:52 am

Hi!

I'd like to display a welcome message to the customer on the account home page after logging in.

I can't seem to work out how to access the customer firstname - can anyone give me some pointers?

I've tried @$customer_info['firstname'] in the account.tpl file, but no luck! :(

Thanks
Mark :)

New member

Posts

Joined
Tue Mar 17, 2009 9:54 pm

Post by fido-x » Sat Mar 21, 2009 12:46 pm

Can be done by following these instructions.

Insert the following lines into "catalog/controller/account/account.php":

Code: Select all

$this->load->model('account/customer');
$customer_info = $this->model_account_customer->getCustomer($this->customer->getId());
$this->data['text_welcome'] = sprintf($this->language->get('text_welcome'), $customer_info['firstname']);
before

Code: Select all

$this->id = 'content';
Then insert the following into "catalog/language/english/account/account.php":

Code: Select all

$_['text_welcome'] = 'Welcome back <b>%s</b>';
Then insert the following into "catalog/view/theme/default/template/account/account.tpl":

Code: Select all

<div style="margin-bottom: 10px; border-bottom: 1px solid #DDDDDD;"><?php echo $text_welcome; ?></div>
before

Code: Select all

<p><b><?php echo $text_my_account; ?></b></p>

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by MarkF » Sat Mar 21, 2009 5:45 pm

hey Fido - thanks - that works a treat! ;D

I appreciate the help; I'm learning from this too!

Regards
Mark :)

New member

Posts

Joined
Tue Mar 17, 2009 9:54 pm

Post by allsop » Sun Jun 07, 2009 3:27 am

Nice. Is there any way to have the account name welcome message show on every page?

New member

Posts

Joined
Fri Jun 05, 2009 1:17 am

Post by halalan » Tue Jun 09, 2009 8:38 pm

Question to fido-x
You custom mods are great and beneficial. The one problem I question is for each time a person upgrades to a new version any mods have to be usually redone. Isn't it better to create them so the can be added under

ADMIN/EXTENSIONS/MODULES

This way they can be turned on or off? It just seems to be a better way for implementing your great customizations even when they are as simple as having the customers FIRST NAME appear. Plus its a great way at gaining a better following for opencart.

Helping Each Other With Knowledge....
WHPOA.NET CTOA.NET CEMETERYTN.COM


User avatar
New member

Posts

Joined
Sat Mar 28, 2009 3:13 am
Location - U.S.A.

Post by make-oc » Fri Jun 12, 2009 11:43 am

Hi there

Here is my approach to this issue–a bit simpler I'd say…

User data are traditionally session data, so I'd go into:
system/library/customer.php ~line 30 and just add this

Code: Select all

### AddedHack: get something in the Session on login
$this->session->data['myAddedSessVar__customerFirstName'] = $customer_query->row['firstname'];
# or do this if you want
$this->session->data['myAddedSessVar__customerWelcome'] = "Welcome back ".$customer_query->row['firstname'];
(I use this long naming so I don't run into problems in the Variables Scope)
To make sure the session data is destroyed when logging of I add
line~120

Code: Select all

### AddedHack: do a session destroy on logout
session_destroy();
Here I don't understand why Daniel uses this approach with unsetting individual vars

Code: Select all

unset($this->session->data['customer_id']);
And now place this anywhere you want in your layout template

Code: Select all

<?php echo $this->session->data['myAddedSessVar__customerFirstName'];

Code: Select all

<?php echo $this->session->data['myAddedSessVar__customerWelcome'];
and it will be displayed during the entire logged in session.

This is an example so you get the idea… there is room for variation…

@halalan
I'm totally with you on how things would better be placed in the core or as extensions and I understand your frustration…
Hacks become painful when upgrading, so I'll try to keep it simple and always have my "### AddedHack:" ;-)

cheers

New member

Posts

Joined
Tue Apr 07, 2009 2:17 pm

Post by allsop » Sat Jun 13, 2009 4:19 am

This is great! Thanks. You're right, it was much more simple. I keep a log of any mods I make, with all of the details. So, if I need, I can go back and repair or remove. It makes everything so much easier.

Thank you again for this.

New member

Posts

Joined
Fri Jun 05, 2009 1:17 am

Post by Daniel » Sat Jun 13, 2009 5:05 am

What horrible code!

Try:

$this->customer->getFirstName();

User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by allsop » Sat Jun 13, 2009 10:33 am

OK. Then where exactly would $this->customer->getFirstName(); be placed instead?

Thanks.

New member

Posts

Joined
Fri Jun 05, 2009 1:17 am

Post by iloveopencart » Sat Jun 13, 2009 12:41 pm

The quickest and easiest way to do this is to edit /catalog/view/theme/default/template/account/account.tpl and paste this single line of code BEFORE this line: <p><b><?php echo $text_my_account; ?></b></p>

Code: Select all

<p>Welcome back, <?php echo $this->customer->getFirstName(); ?>!</p>
********** OR **********

A better way to do this is edit /catalog/controller/account/account.php and paste this single line of code AFTER $this->data['text_newsletter'] = $this->language->get('text_newsletter');:

Code: Select all

$this->data['text_welcome'] = sprintf($this->language->get('text_welcome'), $this->customer->getFirstName());
Then add this code to /catalog/language/english/account/account.php:

Code: Select all

$_['text_welcome']       = 'Welcome back, %s!';
Finally, edit /catalog/view/theme/default/template/account/account.tpl and paste this single line of code BEFORE this line: <p><b><?php echo $text_my_account; ?></b></p>

Code: Select all

<p><?php echo $text_welcome; ?></p>
This second method is more consistent with the way the application is developed. The first method is just cheating ;) .

User avatar
Global Moderator

Posts

Joined
Thu Mar 05, 2009 11:15 pm
Location - Phoenix, AZ

Post by allsop » Sat Jun 13, 2009 10:55 pm

But doesn't the above code place a custom welcome message only on the account page? I was looking for the custom welcome message to show on all pages. :)

New member

Posts

Joined
Fri Jun 05, 2009 1:17 am

Post by iloveopencart » Sat Jun 13, 2009 11:30 pm

OK, here's the quick and dirty method. Edit /catalog/view/theme/default/template/common/layout.tpl and paste the following code wherever you want your welcome message to appear. I placed this after <div id="breadcrumb"> so it displays in the breadcrumb area (see image below).

Code: Select all

<?php if ($this->customer->isLogged()) { ?>You are logged in as <?php echo $this->customer->getFirstName(); ?> &bull; <?php } ?>
Image

User avatar
Global Moderator

Posts

Joined
Thu Mar 05, 2009 11:15 pm
Location - Phoenix, AZ

Post by Daniel » Sun Jun 14, 2009 6:31 am

i might add that to the core.

User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by Aquacide » Fri Aug 21, 2009 5:51 pm

I implemented this similar to what iloveopencart did, but with home on left and you are logged in as on the right of it, and I was wondering, how do i right justify "you are logged in as" so it shows up under the basket/checkout while the home/navigation stuffs stays on the left

Matt Egenes
http://www.aquacide.com/OpenCart
(my opencart site is still way in progress)


User avatar
Newbie

Posts

Joined
Tue Aug 11, 2009 5:40 pm


Post by iloveopencart » Fri Aug 21, 2009 10:28 pm

Try putting this after <div id="breadcrumb"> in catalog/view/theme/default/template/common/layout.tpl:

Code: Select all

<?php if ($this->customer->isLogged()) { ?><span style="float: right; text-align: right;">You are logged in as <?php echo $this->customer->getFirstName(); ?>.</span><?php } ?>

User avatar
Global Moderator

Posts

Joined
Thu Mar 05, 2009 11:15 pm
Location - Phoenix, AZ

Post by sandrotoni » Sat Aug 22, 2009 5:16 pm

iloveopencart wrote:Try putting this after <div id="breadcrumb"> in catalog/view/theme/default/template/common/layout.tpl:

Code: Select all

<?php if ($this->customer->isLogged()) { ?><span style="float: right; text-align: right;">You are logged in as <?php echo $this->customer->getFirstName(); ?>.</span><?php } ?>
Thank you !!! It works really good :)

Newbie

Posts

Joined
Sat Jul 25, 2009 4:25 pm
Who is online

Users browsing this forum: No registered users and 16 guests