I'm editing a theme named AquaCart, installed in OpenCart 1.5.5.1. I also integrated Twitter Bootstrap's fixed top navbar. I already modified the navbar and put the Login / Logout menu there, and it's doing fine. This project is for my own online store.
I don't have any PHP skills yet, only HTML+CSS. I have managed to put the login/logout button on my new navbar menu by copying codes from my current theme's header.tpl
file and editing the header.php
file (from the catalog\english\common\header.php
).
Now, I am polishing the menu and wanted to add some custom menu/link named Sign Up!. I want this Sign Up! menu link to show as Logout link when a user is already logged in.
My current edit shows the logged-in user's name in a <li>
, and a logout menu in a second <li>
. This is not what I really want. I want to show the Logout link in place of the Sign Up! link when a user is logged in.
Here is my current header.tpl
edit:
<ul>
<ul>
<li>
<a href="#">My Account</a><!--Shall be shown only when user is logged in-->
<ul>
<?php if (!$logged) { ?>
<?php echo $text_welcome; ?>
<?php } else { ?>
<?php echo $text_logged; ?>
<?php } ?>
<li class="divider"></li>
<li><a href="#">Store Front</a></li>
<li><a href="#">Blog Page</a></li>
</ul>
</li>
<li><a href="index.php?route=account/register">Sign Up!</a></li>
</ul>
</ul>
My header.php
from the catalog\language folder of opencart. text_logged
and text_welcome
was already edited.
<?php
// header.php from catalog\language\english\common\header.php
$_['text_home'] = 'Online Shop';
$_['text_wishlist'] = 'Wish List (%s)';
$_['text_shopping_cart'] = 'Shopping Cart';
$_['text_search'] = 'Search';
$_['text_welcome'] = '<li><a href="%s">Login</a></li>
<li><a href="index.php?route=account/register">Sign Up!</a></li>';
$_['text_logged'] = '<li><a href="%s">%s</a></li>
<li><a href="%s">Logout</a></li>';
$_['text_account'] = 'My Account';
$_['text_checkout'] = 'Checkout';
?>
The above code is rendered like so...
..and I wanted to make the sign Up! link to become Logout when a user is logged in.
I don't know PHP yet, but I'm struggling on studying the PHP files of OpenCart installation, and I've found this string from my header.php
file found in catalog\controller\common
:
$this->data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->url->link('account/logout', '', 'SSL'));
I am thinking of duplicating that, but don't know what to duplicate and modify. And what are other files involved?
UPDATE:
I've now added a new Text name "Sign Up" and "Login", so I may not be confused, and I can easily substitute it to my Text Link.
So far.. I've added: In my catalog\english\common\header.php
:
$_['text_login'] = 'Login';
$_['text_signup'] = 'Sign Up!';
And in my catalog\controller\header.php
.
$this->data['text_login'] = $this->language->get('text_login');
$this->data['text_signup'] = $this->language->get('text_signup');
UPDATE 2:
I've re-marked up my Menu, based from shadyxx opinion, I've changed the menu a bit. So for "not Logged-in Users"... This menu should be echoed...
Marked up like this:
<div class="nav-collapse collapse">
<ul>
<li><a href="#">Login</a></li>
<li><a href="#">Register</a></li>
</ul>
</div>
And for LOGGED-IN USERS, this menu should be echoed...
Marked up like this:
<div>
<ul>
<ul>
<li>
<a href="#">Account></b></a>
<ul>
<li>%s</a></li>
<li class="divider"></li>
<li>Shopping Cart</a></li>
<li>Checkout</a></li>
</ul>
</li>
<li>Logout</a></li>
</ul>
</ul>
</div>
In my catalog\controller\common\header.php
:
$this->data['signup'] = sprintf($this->language->get('text_signup'), $this->url->link('account/register', '', 'SSL'));
$this->data['login_register'] = sprintf($this->language->get('text_login_register'), $this->url->link('account/login', '', 'SSL'), $this->url->link('account/register', '', 'SSL'));
$this->data['logged_in'] = sprintf($this->language->get('text_logged_in'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->data['text_shopping_cart'] = $this->language->get('text_shopping_cart'), $this->data['shopping_cart'] = $this->url->link('checkout/cart'), $this->url->link('account/logout', '', 'SSL'));
In my catalog\language\english\common\header.php
$_['text_login_register']
= '<div>
<ul>
<li>Login</a></li>
<li>Register</a></li>
</ul>
</div>';
$_['text_logged_in']
= '<div>
<ul>
<ul>
<li>
<a href="#">Account<b class="caret"></b></a>
<ul>
<li><a href="%s">%s</a></li>
<li class="divider"></li>
<li><a href="%s">Shopping Cart</a></li>
<li><a href="%s">Checkout</a></li>
</ul>
</li>
<li><a href="%s">Logout</a></li>
</ul>
</ul>
</div>';
In my header.tpl
<?php if (!$logged) { ?>
<?php echo $login_register; ?>
<?php } else { ?>
<?php echo $logged_in; ?>
<?php } ?>
So, what's not working, using the above codes is the checkout menu. The checkout menu is redirecting a user to the Shopping Cart Page.
I've just copy pasted the above codes. I've tried to understand the use of the existing code and by trial and error.