Post by Ljubo » Sun Aug 26, 2012 4:16 pm

hi all,
I am pretty much novice in php, but I do modify a bit various templates by trial and error method.

I am stuck now with the following problem and desperately need some help from you guys:
1. template has a top menu with class designed outlook and hover effect. however, a completely different class is designed if the link is active.
2. so, I have managed to differ it by php if function in the header.tpl file under <ul> section, like as follows:

Code: Select all

<li<?php if($currentpage == $home) {echo " class=menu_1_active";} else {echo " class=menu_1";}?>><a href="<?php echo $home; ?>"><?php echo $text_home;?></a></li>
<li>...
3. in header.php file of controller folder, I have inserted the line:

Code: Select all

$currentpage = $_SERVER['REQUEST_URI'];
just before the line>

Code: Select all

$this->data['title'] = $this->document->getTitle();
the result is an error with message that variable $currentpage is not defined.

if I insert the line:

Code: Select all

$this->data['currentpage'] = $this->$_SERVER['REQUEST_URI'];
before the line:

Code: Select all

$this->data['currentpage'] = $this->$_SERVER['REQUEST_URI'];
it gets me back with neither an error nor desired effect.

What am I doing wrong here?

Can anybody help with instructions how and where to name/define different pages / links in the opencart system?

Help is extremely appreciated.

Thank you!

Active Member

Posts

Joined
Mon Jan 31, 2011 10:07 pm
Location - Serbia

Post by MarketInSG » Sun Aug 26, 2012 6:56 pm

Code: Select all

$this->data['currentpage'] = $this->request->server['REQUEST_URI'];
alternatively, to just get the route, you use at your template file will do.

Code: Select all

if($this->request->get['route'] == 'common/home') { //add your class }


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by Ljubo » Sun Aug 26, 2012 8:38 pm

thank you - thank you - thank you !

my idea with your modified string did not work at the end (probably because I dont know to what line in header.php I should put it), BUT...
your alternative solution did the magic!!!

Thank you again very much.

here is full line of it (in anyone might be interested):

Code: Select all

<li<?php if($this->request->get['route'] == 'common/home') {echo " class=menu_1_active";} else {echo " class=menu_1";}?>><a href="<?php echo $home; ?>"><?php echo $text_home;?></a></li>
now, it works perfectly if the url ends with common/home.
but, if you type in the tld url (like: http://www.mywebaddress.com, mywebaddress is representing my real web address), an error pops up saying NOTICE UNDEFINED INDEX ROUTE IN...
how to solve this problem?

another thing that is important.
except for the links of home and contact, I am going to have there few more links that would lead to, lets say, homepages of additional stores using multistore feature of oc.
in other words, store2, store3, store4,... are in the top menu as links - the link goes to homepages of linked stores...
I guess, but am not sure, that other stores address would be like: store2.mainstore.com, store3.mainstore.com...
so, here is the issue of retreiving this links for the sake of changing the li class of active store.

if you need some additional info or clarifications, please ask.

Hmmm... I am rethinking of it....
here is again my top menu:
home - store1 - store2 - store3 - contact
1. home
it would basically be some general bla-bla of one or few pages, without categories, products... anything. just general stuff and links to other stores
2. store1
store1 specific products with categories
3. store2
store2 specific products with categories
4. contact
general contact info that is valid for all stores

so, the menu item store2 (for example), should be li classed active if the visitor is surfing around anywhere its products.
Perhaps defining/naming or whatever the variable using the subdomain url of store2.mainstore.com.
I do nto know it this is possible and how it could be done.

Active Member

Posts

Joined
Mon Jan 31, 2011 10:07 pm
Location - Serbia

Post by MarketInSG » Sun Aug 26, 2012 8:41 pm

to know if they are on domain.com use

Code: Select all

 if (!isset($this->request->get['route'])) { you are at home page }


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by MarketInSG » Sun Aug 26, 2012 8:43 pm

if you want to recognise them by domain names, you can just use

Code: Select all

if($this->server->request['SERVER_NAME'] == 'example.com') { do what you like } else { dont do it }


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by Ljubo » Sun Aug 26, 2012 8:53 pm

great! thank you again.
I will try it once I make those subdomains and enable multi store in oc.

do you have an idea why I got those error messages explained earlier?

Active Member

Posts

Joined
Mon Jan 31, 2011 10:07 pm
Location - Serbia

User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by Ljubo » Sun Aug 26, 2012 9:43 pm

that is for sure.

can you help me out with it?

Active Member

Posts

Joined
Mon Jan 31, 2011 10:07 pm
Location - Serbia

User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by Ljubo » Mon Aug 27, 2012 3:13 pm

thanks for getting back.

actually, it is 1.5.3.1 with custom template that I am modifying.
more or less, until now I am managing to do some changes without breaking the code.

now, I am stuck with this.
basically, let me repeat myself.
I inserted new top-menu1 navigation bar on top of the site, like:
home - store2 - store3 - store4 - store5 - ... - store 10 - contact us

1. there are two css classes for top-menu1 items. first one is for default/passive outlook, and the other is for when the link is active.
now, my trouble is finding the way to display the correct div class (default and active one depending if the link is active or not).
something like, if the current page is equal to a link1, then class1active, else class1.
please note that I have separate classes for every single menu item (their borders are with different colors and when hover or active each of them are with different background color).
your help with:

Code: Select all

<li<?php if($this->request->get['route'] == 'common/home') {echo " class=menu_1_active";} else {echo " class=menu_1";}?>><a href="<?php echo $home; ?>"><?php echo $text_home;?></a></li>
did the trick but with side effect of not working at all if the home page url is without common/home end, i.e. if it is ending with "/" or "".
then the error shows up: NOTICE: UNDEFINED INDEX: ROUTE IN .... /VQMOD/VQCACHE/....

At the moment, I would need a hint how to get rid of this error... as well as perhaps some instructions with a way how to define/name some/any link and later on to call it like I did in this if function.
I still did not get to test your other hint (to recognize by domain name) because I have not established multi store yet. Just now I am moving contents to other hosting company so that I could be able to enable and test what you proposed.

thank you!

Active Member

Posts

Joined
Mon Jan 31, 2011 10:07 pm
Location - Serbia

Post by MarketInSG » Mon Aug 27, 2012 8:19 pm

Code: Select all

if (!isset($this->request->get['route'])) { you are at home page }
I mentioned this above. To get if you are at home page, use that. So the total code should be

Code: Select all

if (isset($this->request->get['route']) && $this->request->get['route'] == 'route here') { //class here } elseif (!isset($this->request-get['route'])) { //this is home page } 


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by Ljubo » Mon Aug 27, 2012 8:47 pm

do you mean like this?

Code: Select all

<li<?php if(!isset($this->request->get['route'])) && $this->request->get['route'] == 'common/home') {echo " class=menu_1_active";} elseif (!isset($this->request-get['route'])) {echo " class=menu_1";}?>><a href="<?php echo $home; ?>"><?php echo $text_home;?></a></li>
thanks

corrected to:

Code: Select all

<li<?php if(!isset($this->request->get['route']) && $this->request->get['route'] == 'common/home') {echo " class=menu_1_active";} elseif (!isset($this->request->get['route'])) {echo " class=menu_1";}?>><a href="<?php echo $home; ?>"><?php echo $text_home;?></a></li>
but still not working...

the truth is somewhere out there...
will be back in few minutes with good news, I hope.

OK, I HAVE MANAGED TO WORK JUST AS I WANTED, here is the code:

Code: Select all

<li<?php if(isset($this->request->get['route']) && $this->request->get['route'] == 'common/home') {echo " class=menu_1_active";} else {echo " class=menu_1";}?>><a href="<?php echo $home; ?>"><?php echo $text_home;?></a></li>
THANKS A MILLION!

let me ask few more things:
1. if in future, I manage the links to finish more SEO friendly, like 'home' instead of 'common/home' and do appropriate changes in the code above, shall it all work ok?
2. what would be the exact code for the item store2 to be classed active (in top menu) as long as the visitor is on store2 shop?

Active Member

Posts

Joined
Mon Jan 31, 2011 10:07 pm
Location - Serbia

Post by MarketInSG » Mon Aug 27, 2012 10:17 pm

actually your codes all aren't correct...

to know if user is at homepage you need

Code: Select all

if ((isset($this->request->get['route']) && $this->request->get['route'] == 'common/home') || !isset($this->request->get['route'])) { //this is the home page
}
this will check if user is at common/home ELSE if not, user does not have route set, user is at home. till then, experiment and try. to learn, you will have to try yourself. I can't give you the answers to everything :)


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by Ljubo » Mon Sep 03, 2012 10:02 pm

thank you for your help, I appreciate it and think that there are some valuable information for others as well.

I have finally enabled the multi store feature of the opencart. I had problems setting it all up on a web hosting server without a registered domain name.
All is set once the hosting is on a certain domain name, not without any.
So, making the menu item active is very simple for the way I designed the shop.
Since the menu item represents the separate store of the oc, along with own header.tpl files, all I had to do is to set the fixed value for the menu/store item in its header.tpl file.

Still, I will have to play a bit more with Contact menu item...
and it is done, just like the previos code of mine instead of common/home I put the route of information/contact.

Now all works perfectly.
Thank you for your help.

Active Member

Posts

Joined
Mon Jan 31, 2011 10:07 pm
Location - Serbia
Who is online

Users browsing this forum: Semrush [Bot] and 89 guests