Shop - Browse Category

 

On the left side of the shop pages we show the category list. When the customer clicks on a category on the left side she can see all products in that category. The shop main page include this navigation from include/leftNav.php and as mentioned before, the one responsible to get the list of categories for this navigation is the formatCategories() function in library/category-functions.php

In summary here is what formatCategories() do :

  1. Get all the children categories
  2. Get the parent category and other categories on the same level as the parent
  3. Keep looping to get the parent's parent until we reach the top level category

This function is actually a bit too complex for handling two level deep categories. However in the future i want this shop to handle categories more than two level deep so i made this function so it can cope with that.

Okay, let's not talk about this function too much and move on with the code for leftNav.php

Source code : include/leftNav.php

<?php
if (!defined('WEB_ROOT')) {
   exit;
}

// get all categories
$categories = fetchCategories();

// format the categories for display
$categories = formatCategories($categories, $catId);
?>
<ul>
<li><a href="<?php echo $_SERVER['PHP_SELF']; ?>">All Category</a></li>
<?php
foreach ($categories as $category) {
   extract($category);
   // now we have $cat_id, $cat_parent_id, $cat_name

   $level = ($cat_parent_id == 0) ? 1 : 2;
   $url = $_SERVER['PHP_SELF'] . "?c=$cat_id";

   // for second level categories we print extra spaces to give
   // indentation look
   if ($level == 2) {
      $cat_name = '&nbsp; &nbsp; &raquo;&nbsp;' . $cat_name;
   }

   // assign id="current" for the currently selected category
   // this will highlight the category name
   $listId = '';
   if ($cat_id == $catId) {
      $listId = ' id="current"';
   }

?>
<li<?php echo $listId; ?>><a href="<?php echo $url; ?>"><?php echo $cat_name; ?></a></li>
<?php
}
?>
</ul>

 

The categories are printed as unordered lis ( <ul> ). I guess you already know that unordered list usually shows up like this :

  • list one
  • list two
    • child 1
    • child 2

But thanks to CSS ( Cascading Style Sheet ) we can alter how the browser display the list and give them than boxy look. I must admit that i'm a beginner to css and i learn this from projectseven.com, so if you want to know how the css works you can visit the site later.

Next up is the product browsing.

 

Find freelance programmers at ScriptLance.com - Search worldwide

cheap professional Commercial carpet cleaning here | Personalized debt consolidation plans |
 

 

Online Shop - Main Page PHP MySQL Shopping Cart Tutorial : Online Shop - Browse Category Online Shop - View Product List
Google
 
Web www.phpwebcommerce.com
 

At long last i'm finally able to update this site. Now the shopping cart can handle payment through paypal. As always you have any critiques, questions, comments or problems about this tutorial please tell me. Click here to send your feedback. And if you like this tutorial please link to this site. It will really help a lot :-)

 

"I made an extra $378 last week promoting just 1 site. Click here to see which site is it. Join today!"



PHP MySQL Shopping Cart Tutorial
Copyright © 2005 - 2010 www.phpwebcommerce.com