OpenCart header navigation (three level list)

Recently, I had a bite of Open Cart to build a new website for a client. Its still in development, but the outcome seems promising. I have to say, as much as I had heard about Open Cart, it really is a great piece of web application. My journey with shopping carts have been restless. I have had tough times with OSCommerce, played enough with ZenCart, dealt with the terrible NiagaKit, and even adventured on my favorite enterprise level Magento. While Magento is still the best for me, Open Cart is just the next one for me. Reason why Open Cart is behind Magento is only because of the number of features that it has. For my carts that need enterprise love, I use Magento for them. For all others, Open Cart is my choice now.

So, I was modding a custom made theme for a client who will be selling products on his very own Open Cart. I realized that it did not have header navigation. Actually, it did not have category list tables. The current category.tpl template file calls the categories available for the viewed page only. While Open Cart will be implementing listed categories in the next version, my client couldn’t wait. So I had to do what I had to do.

Google! Thats where I found Craig Murrays neat category list code. The code works, but apparently he limited it to two level navigation only. The parent and a child. I think for a shopping cart, the maximum navigation levels should be three rather than two. In my clients case who was selling hijabs, she needed three level navigation. eg: hijab -> the type of hijab -> the material. So I took Craig’s code and modified it into a three-level navigation. The generated list item will look something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<ul>
   <li>First Level</li>
   <li>First Level
      <ul>
         <li>Second Level</li>
         <li>Second Level
            <ul>
               <li>Third Level</li>
               <li>Third Level</li>
            </ul>
         </li>
         <li>Second Level</li>
       </ul>
   </li>
   <li>First Level</li>
</ul>

Once you have this list, you can give it some CSS touch and use Superfish or most other jQuery scripts to add the animation effect for added functionality. Now here is the PHP code to generate this list (along with descriptions on what each line does):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php 
 
$this->load->model('tool/seo_url');
 
$results = $this->model_catalog_category->getCategories();  									// get the categories
 
if ($results) {$output = '<ul class="you-can-define-a-class-here-for-your-javascripts">';}  									// if there are categories available, start off with the unordered list tag
 
foreach ($results as $result) {																	// for each result
	$output .= '<li>';																			// put a list item tag
	$new_path = $result['category_id'];															// get the id of this category
	$unrewritten = HTTP_SERVER.'index.php?route=product/category&path=' . $new_path;			// if the seo url is disabled, this will be the path
	$rewritten = $this->model_tool_seo_url->rewrite($unrewritten);								// otherwise, it will be this one
	$output .= '<a href="' . $rewritten . '">' . $result['name'] . '</a>';						// finally, generate the category name and wrap its link
 
	$sub_results = $this->model_catalog_category->getCategories($new_path);						// if this result has a sub-list, get the set of new categories
 
	if ($sub_results) {$output .= '<ul>';}														// if this is a subresult, start off with an unordered list tag
 
	foreach ($sub_results as $sub_result) {														// for each of this subresult item
		$output .= '<li>';																		// put a list item tag
		$new_sub_path = $sub_result['category_id'];												// get its category
		$sub_unrewritten = $unrewritten.'_'. $new_sub_path;										// if the seo is disabled, this will be the path
		$sub_rewritten = $this->model_tool_seo_url->rewrite($sub_unrewritten);					// otherwise, it will be this one
		$output .= '<a href="' . $sub_rewritten . '">' . $sub_result['name'] . '</a>';			// now, generate the category name and wrap its link
 
		$third_sub_results = $this->model_catalog_category->getCategories($new_sub_path);		// if this result has a sub-list, get the set of new categories
 
		if ($third_sub_results) {$output .= '<ul>';}											// if this is a subresult, start off with an unordered list tag
 
		foreach ($third_sub_results as $third_sub_result) {										// for each of this third level item
			$output .= '<li>';																	// give it an opening list tag
			$third_sub_path = $third_sub_result['category_id'];									// get its category
			$third_sub_unrewritten = $sub_unrewritten.'_'.$third_sub_path;						// if seo is disabled, this is the path
			$third_sub_rewritten = $this->model_tool_seo_url->rewrite($third_sub_unrewritten);	// if its enabled, this will be the path
			$output .= '<a href="'.$third_sub_rewritten.'">'.$third_sub_result['name'].'</a>';	// call the category name and wrap with its link
			$output .= '</li>';																	// now close this list item
		}
 
		if ($third_sub_results) {$output .= '</ul>';}											// if this was the third list, clost the list
			$output .= '</li>';																	// then or otherwise, close the second level list tag
	}
	if ($sub_results) {$output .= '</ul>';}														// if all sub results have been listed, close the second level
		$output .= '</li>';																		// then or otherwise close first list parent
}
if ($results) {$output .= '</ul>';}																// then close the first level list table
echo $output; 																					// now produce the results
?>

I hope that helps for some of you guys looking forward to add this to your Open Carts. Open Source..ftw!

Shahz

Print
  1. สเปรย์พริกไทย
    #1 written by สเปรย์พริกไทย (3 years ago)

    Personally, I adore how the style is classic and upscale as well aas practical.

    Obesiry is now the number 1 (non-communicable) disease in the developed world.
    If youve been eating wheat products all your life, a wheat-free diet may not sound too appetizing.

  2. Rufus
    #2 written by Rufus (3 years ago)

    Today, mobile video games applications running about Apple devices be the cause of more than
    30 % share already in the market. Manipulating the largest proportion of shares inside mobile video gaming market which constitutes more than 10 dollars billion has enabled the ipod-touch as well as
    the iPhone in order to defeat console online games on PCs from your perspective with the home market share.
    Additionally it is to be remembered that there was a downturn throughout the economy through the period this year to 2012 which
    resulted in a lot more00 console gaming users use iOS games apps since the latter were being available at cheaper prices.

    My homepage … castle clash hack tool – Rufus -

  3. buy beats in Hollywood
    #3 written by buy beats in Hollywood  (3 years ago)

    Today, while I was at work, my sister stole my apple ipad and tested to see if it can
    survive a 25 foot drop, just so she can be a youtube sensation.
    My apple ipad is now broken and she has 83 views. I know this is totally
    off topic but I had to share it with someone!

  4. minnesota lawyers directory
    #4 written by minnesota lawyers directory  (3 years ago)

    Excellent article! We will be linking to this great article
    on our website. Keep up the great writing.

  5. sell your home
    #5 written by sell your home  (3 years ago)

    Fantastic goods from you, man. I’ve take into accout your stuff prior to and
    you are just extremely wonderful. I actually like what you’ve obtained here, really
    like what you are saying and the best way during which you
    say it. You are making it enjoyable and you still care for to keep it smart.
    I cant wait to read much more from you. This is really
    a terrific site.

  6. fille défloreuse bonnasse
    #6 written by fille défloreuse bonnasse (3 years ago)

    Puis-je vous piquer 2 3 paragraphes pour un site internet ?

  7. Highland Beach Realtors
    #7 written by Highland Beach Realtors  (3 years ago)

    If some one desires to be updated with newest technologies afterward he must be pay a visit
    this site and be up to date all the time.

  8. clash of clans hack download free
    #8 written by clash of clans hack download free (3 years ago)

    Great blog! Do you have any suggestions for aspiring writers?

    I’m hoping to start my own website soon but I’m a little lost on everything.
    Would you advise starting with a free platform like
    Wordpress or go for a paid option? There are so
    many options out there that I’m completely overwhelmed ..
    Any tips? Thanks!

  9. social exchange
    #9 written by social exchange  (3 years ago)

    I’ve read several excellent stuff here. Certainly worth bookmarking for revisiting.
    I surprise how much effort you set to make this type of magnificent informative
    website.

  10. world at arms hack
    #10 written by world at arms hack (3 years ago)

    Great post. I was checking continuously this blog and I am impressed!

    Extremely helpful information specially the last part :) I care for such information much.
    I was seeking this certain information for a very long time.
    Thank you and good luck.

    Stop by my web page: world at arms hack

  11. Louis
    #11 written by Louis  (3 years ago)

    What you ought to do is to fill a web based form. You might hear on the internet
    and start fretting about the confidentiality of one’s information. The business handles every one
    of the orders with great confidentiality. Why will you love to utilize the
    escort services? Listed below are the answers for you.

  12. BIM Latino
    #12 written by BIM Latino (3 years ago)

    My programmer is trying to persuade me to move to .net from PHP.

    I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using WordPress on a variety of websites
    for about a year and am worried about switching to another platform.

    I have heard good things about blogengine.net.
    Is there a way I can import all my wordpress posts into it?
    Any kind of help would be greatly appreciated!

  13. music marketing and promotion
    #13 written by music marketing and promotion (3 years ago)

    I would like to thank you for the efforts you’ve put in writing this website.
    I am hoping to view the same high-grade blog posts by you later on as well.
    In fact, your creative writing abilities has inspired me to get my very own blog now
    ;)

  14. www.agrisk.Umn.Edu
    #14 written by www.agrisk.Umn.Edu (3 years ago)

    Brilliant website a large amount of excellent steam
    shower information here

    Here is my web site; Steam Shower enclosures (http://www.agrisk.Umn.Edu)

  15. sexercise routine
    #15 written by sexercise routine (3 years ago)

    I think this is one of the most vital information for me.
    Annd i’m glad reading your article. But should remark on some general
    things, The web site style is great, the articles is really ice :
    D. Good job, cheers

  16. www.youtube.com
    #16 written by www.youtube.com  (3 years ago)

    My developer is trying to peersuade me to move to .net from PHP.
    I have always disliiked the idea because off the expenses.
    But he’s tryiong none the less. I’ve been using WordPress on a number of websitees for abolut a yyear and am
    nervous about switching to another platform. I have heard fantastic things about blogengine.net.
    Is there a way I can imprt alll my wordpress content
    into it? Any help would be really appreciated!

    My web site clash of clans ultimate hack tool android & ios v.2.3 – http://www.youtube.com -

  17. greedy squirrel
    #17 written by greedy squirrel (3 years ago)

    And then Mother Nature using its negative feedback loop mechanism needs to fix the problem.

    So, to honor this timeless classic of Christmas joy,
    I have chosen for your reading pleasure, ten of my favorite quotes.
    If you pay yourself first, and then your bills, you’ll find a way to make it
    to your next pay period.

  18. squirrel food nuts
    #18 written by squirrel food nuts  (3 years ago)

    The sloth bear is the only species of bear found in South India.
    The old man went on to explain to the boy that the three men who seemed to be
    in a heated discussion weren’t really arguing. They have cash on hand to invest in anything they want, and
    everything is on sale right now.

  19. internet
    #19 written by internet  (3 years ago)

    Previously, plagiarised content often ranked higher than the original piece.
    Search engines are far more ‘intelligent’ today and effective SEO requires actual meaningful content pages, social networking, articles
    submissions, and a focused marketing effort.
    How to Hire: If your SEO company is going to specialize in digital design,
    it’s important to have a designer on board.

    My page internet

  20. www.rebelmouse.com
    #20 written by www.rebelmouse.com (3 years ago)

    Today, I went to the beach front with my kids. I found a
    sea shell and gave it to my 4 year old daughter and said
    “You can hear the ocean if you put this to your ear.” She
    placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is entirely off topic but I had to tell someone!

  21. funny cats
    #21 written by funny cats  (3 years ago)

    We always seem to run out of money if we pay our bills first
    and then look at what’s left for savings. For this reason alone, many owners want to discover a
    list of ranked dog foods. Dhole is an Asiatic wild dog, red
    in color, and found in packs.

  22. seoservicesmart.net
    #22 written by seoservicesmart.net (3 years ago)

    I’ve been exploring for a little for any high quality articles or blog posts on this sort of space .
    Exploring in Yahoo I eventually stumbled upon this web site.
    Studying this information So i’m glad to exhibit that I have an incredibly just right
    uncanny feeling I found out just what I needed.
    I so much certainly will make sure to do not forget this website and provides it a look
    on a constant basis.

  23. Martha
    #23 written by Martha (3 years ago)

    At the same time, eco-friendliness is a crucial PR issue for
    most businesses. But students who have just graduated from high school can take courses that will quickly
    get them on this career path. The various turnkey business opportunities in business consultancy include.
    A career in solar training is the best that
    one can get in the modern technological world. How do I know if a residential solar electric system would
    work on my home. Power4Home installation guide e – Book and the training videos will help you generating energy like
    a seasoned pro.

  24. Loreen
    #24 written by Loreen  (3 years ago)

    For latest information you hav to viskt woorld wide web
    andd on world-wide-web I found this web page ass a
    most excellent site for newest updates.

    Feel free to visit my weblog – clash of clans tips, Loreen,

  25. Bicycle Mini Pump
    #25 written by Bicycle Mini Pump (3 years ago)

    My partner and I stumbled over here from a different
    web page and thought I may as well check things out.
    I like what I see so now i am following you. Look forward to finding out
    about your web page for a second time.

  26. Lucia
    #26 written by Lucia (3 years ago)

    Howdy. Simply just desired to consult an instant question. I am just setting up my personal
    blog site in addition to would like to recognize where by you got ones design? Had been this no
    cost? Or maybe ended up being that compensated?
    I cannot often find anything at all as effective as this, consequently preferably you are
    able to i want to understand. Many thanks.
    PS, my own apologies. English isn’t my primary dialect.

  27. Jamika
    #27 written by Jamika (3 years ago)

    With havin so much content and articles do you ever
    run into any problems of plagorism or copyright violation? My blog has a lot of unique content I’ve
    either created myself or outsourced but it looks like a lot of it
    is popping it up all over the internet without my permission. Do you know any techniques to
    help protect against content from being stolen? I’d truly appreciate it.

    my blog post … clash of clans hack (Jamika)

  28. bart attorneys in mobile al
    #28 written by bart attorneys in mobile al (3 years ago)

    However, there is a limited period for the second appeal.
    It is recommended to hire a professional because the claim laws can vary greatly from state to state, and if you are
    not familiar with these nuances, you may not get your fully entitled payout.
    After treatment, you lie in the hospital bed not knowing when you’ll
    be able to go home.

    Stop by my web-site … bart attorneys in mobile al

  29. seo
    #29 written by seo  (3 years ago)

    As a responsible citizen of the internet,
    I use only whitehat SEO techniques. There is absolutely no SEO if there
    is not at least one central keyword or phrase highlighted in your business communication. Basically Page Rank has more to do with backlinks
    and stuff like that.

  30. truyen hinh cap
    #30 written by truyen hinh cap (3 years ago)

    Your style is really unique in comparison to other folks I’ve read stuff from.
    Thank you for posting when you have the opportunity, Guess I will just bookmark this site.

  31. youtube.com
    #31 written by youtube.com (3 years ago)

    If you feel satisfied by the answers your prospective Los Angeles injury attorney gives you, go ahead and hire them as your attorney.
    Some prefer a conventional professional fee that
    can mainly rely on how complex the case is.
    Not at all, in many occasions, car accident lawyers perform a vital role in increasing
    the claimant.

    my site … David Gruber Lawyer (youtube.com)

  32. Kari
    #32 written by Kari (3 years ago)

    For most people the thought of ultimate luxury would be to travel
    in a stretch limousine with all the comforts at hand drinks, air condition, entertainment et al.
    It will actually be possible for you to get most things free in the end and that will make it possible for you to arrange a party without any
    large cost. There are a considerable number of limo rental services
    on the web and in contrasting promotion indexes, for example Craigslist, but
    not the sum total of them are reliable.

    my blog – Richmond Virginia Cars Service (Kari)

  33. travail d assemblage a domicile
    #33 written by travail d assemblage a domicile (3 years ago)

    Excellent blog here! Also your web site loads
    up fast! What web host are you using? Can I get your affiliate link to your host?

    I wish my website loaded up as quickly as yours lol

  34. grand theft auto news
    #34 written by grand theft auto news (3 years ago)

    When someone writes an article he/she retains the
    plan of a user in his/her brain that how a user can understand
    it. Therefore that’s why this post is outstdanding. Thanks!

  35. Katherina
    #35 written by Katherina (3 years ago)

    Hello. Only wanted to consult a quick issue. I am just setting up
    my own, personal blog site as well as wish to know where
    by you have ones concept? Had been the idea free?
    Or perhaps seemed to be the item paid? I can’t manage to
    discover something as well as this place, consequently with luck , you are able to let me know.
    Thank you. PS, my own sorry. The english language is
    just not my initial terminology.

  36. castle clash hack Apk download no survey
    #36 written by castle clash hack Apk download no survey  (3 years ago)

    In Rockhampton the stage is set for the final act in the Escort murder case.

    Sam Croft and Smith were erecting their public house and “Betty”
    Ryland was doing a good trade in his store.
    Taking a thorn from the foot of a deer, then, with a word, kindly letting it go.

  37. iphone 5s free
    #37 written by iphone 5s free (3 years ago)

    Hello there. Just needed to request an instant issue. I am putting
    together my web site and want to understand exactly where you
    have the theme? Was the idea cost-free? Or has been it paid for?
    I can not manage to discover something just like this place, so with luck , you possibly can allow me to
    understand. Appreciate it. PS, my apologies. English is not our very first
    words.

  38. Search Engine optimization baltimore
    #38 written by Search Engine optimization baltimore  (3 years ago)

    May I simply say what a comfort to find somebody that genuinely understands what
    they are discussing on the net. You actually understand how to bring an issue to light and make it important.
    More people must read this and understand this side of your story.

    It’s surprising you’re not more popular since you most certainly possess the gift.

  39. Pelham Roofer
    #39 written by Pelham Roofer (3 years ago)

    You may also check out local building trade associations, building
    supply businesses and licensing authorities.
    A roofing contractor with a ‘magic touch’ is a gold mine in the
    home improvement industry. You may be dealing with two problems here if the company you hire has
    no insurance coverage.

  40. somatodrol bom
    #40 written by somatodrol bom  (3 years ago)

    Simply desire to say your article is as amazing.
    The clarity in your post is just great and i could assume you are an expert on this subject.
    Well with your permission allow me to grab your feed to keep updated with forthcoming post.
    Thanks a million and please carry on the rewarding work.

  41. Giselle
    #41 written by Giselle  (3 years ago)

    Moreover, the investigation of that reported occurrence was not pursued.
    They seem to have reached the limit of their propellant’s
    abilities. Not at all, in many occasions, car accident lawyers perform a vital
    role in increasing the claimant.

    my website :: personal injury lawyer in las vegas – Giselle,

  42. six guns cheats
    #42 written by six guns cheats (3 years ago)

    Villagers will arrive in a groups of three to six Gonados.
    I actually assistance someone to shoot your zombie for six instances as well as cutlery this to become
    more cash in the 1st around, anyone photograph the actual zombies regarding nine situations plus
    blade this from the minute area. * As each task is accomplished it will be crossed off the list.

    Feel free to visit my blog post six guns cheats

  43. free cam site
    #43 written by free cam site (3 years ago)

    It’s truly very difficult in this active life to listen news
    on Television, so I only use the web for that reason, and take the most recent news.

  44. easy money making ideas
    #44 written by easy money making ideas  (3 years ago)

    So if you have ever asked yourself “What is the fastest way to make money. Have you typed into Google “how can I earn online and come” across a few through products that seem too good to be true. Depending on the approaches that you put in place, you stand to make varying amount of money.

  45. huntington car care alexandria va
    #45 written by huntington car care alexandria va  (3 years ago)

    Belts and Hoses ‘ A broken belt or hose can leave you stranded, or worse, cause severe engine damage.
    Tiny Leaks: It is very common in car air conditioning system to develop tiny leaks, which
    may go unnoticed for months. Only certified and well trained experts and repair technicians who have years of experience of performing everything from oil changes
    to a complete engine overhaul can understand the condition of your car.

  46. Hvac Contractor Brandon Fl
    #46 written by Hvac Contractor Brandon Fl  (3 years ago)

    This is a topic that’s near to my heart… Take care!
    Exactly where are your contact details though?

  47. hyundai i30 2010
    #47 written by hyundai i30 2010 (3 years ago)

    Excellent post. I was checking continuously
    this blog and I am impressed! Extremely helpful info specially the last part :) I
    care for such information a lot. I was seeking this particular
    info for a long time. Thank you and good luck.

  48. เรียนร้องเพลง
    #48 written by เรียนร้องเพลง  (3 years ago)

    It’s awesome in support of me to have a website, which is useful for my experience.
    thanks admin

  49. Dyson Vacuum
    #49 written by Dyson Vacuum  (3 years ago)

    Its such as you read my mind! You appear to grasp so
    much approximately this, such as you wrote the guide in it or something.
    I feel that you could do with some percent to drive the message house a
    little bit, but other than that, this is excellent blog.
    A great read. I’ll certainly be back.

  50. Malorie
    #50 written by Malorie (3 years ago)

    Other meats like hot dogs and sausages are to be avoided.
    This variety of diet plan enables the consumption of carbohydrates as soon as loss of fat is seasoned.
    Users of the Paleo Cookbooks will get so much more out of changing
    their eating habits than just weight loss.

    My page – paleo diet (Malorie)

  51. You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  52. Comment Feed for this Post
Go to Top