Home | Store | osCommerce Tutorials

osCommerce Main Categories Content File Structure

Part 3 - Study the value of $categories_string return from tep_show_category


We learned before that the tep_not_null($cPath) will be true when the URL contains the cPath, i.e. browsing Parent Categories, Sub-categories and Products. Therefore the codes will be something like:

$categories_string = '';
$tree = array();

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");

while ($categories = tep_db_fetch_array($categories_query)) {

$tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
'parent' => $categories['parent_id'],
'level' => 0,
'path' => $categories['categories_id'],
'next_id' => false);

}

 

if (tep_not_null($cPath)) {

// Codes here will be executed
//when browsing Parent Categories, Sub-Categories and Products

}

tep_show_category($first_element);

Look at the last line of code:

tep_show_category($first_element);

This line of code simply call the tep_show_category($first_element) function with the value of $first_element send into the function for processing.

Value of $categories_string

We will discuss the codes inside the curly braces of if (tep_not_null($cPath)) later. At this moment, let's focus only at the $categories_string that return from the tep_show_category() function when browsing from osCommerce homepage and Categories.

The $categories_string is a long string that will be used to print out the Main Categories content.

Value of $categories_string when browsing osCommerce Homepage

Browsing URL: http://osc.cz.cc/index.php

<a href="http://osc.cz.cc/index.php?cPath=1">Hardware-&gt;</a>&nbsp;(6)<br>
<a href="http://osc.cz.cc/index.php?cPath=2">Software-&gt;</a>&nbsp;(4)<br>
<a href="http://osc.cz.cc/index.php?cPath=3">DVD Movies-&gt;</a>&nbsp;(17)<br>

The display of the above $categories_string will look like the following:

Hardware-> (6)
Software-> (4)
DVD Movies-> (17)

The above results are also the same when browsing other visual pages (Contact Us, Conditions of Use, My Account, etc...) except Categories and Products pages.

Value of $categories_string when browsing osCommerce Hardware Parent Categories

Browsing URL: http://osc.cz.cc/index.php?cPath=1

<a href="http://osc.cz.cc/index.php?cPath=1"><b>Hardware</b>-&gt;</a>&nbsp;(6)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_17">CDROM Drives</a><br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_4">Graphics Cards</a>&nbsp;(2)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_8">Keyboards</a>&nbsp;(1)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_16">Memory</a><br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_9">Mice</a>&nbsp;(2)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_6">Monitors</a><br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_5">Printers</a>&nbsp;(1)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_7">Speakers</a><br>
<a href="http://osc.cz.cc/index.php?cPath=2">Software-&gt;</a>&nbsp;(4)<br>
<a href="http://osc.cz.cc/index.php?cPath=3">DVD Movies-&gt;</a>&nbsp;(17)<br>

The display of the above $categories_string will look like the following:

Hardware-> (6)
  CDROM Drives
  Graphics Cards (2)
  Keyboards (1)
  Memory
  Mice (2)
  Monitors
  Printers (1)
  Speakers
Software-> (4)
DVD Movies-> (17)

Value of $categories_string when browsing osCommerce Graphics Cards Sub-Categories

Browsing URL: http://osc.cz.cc/index.php?cPath=1_4

<a href="http://osc.cz.cc/index.php?cPath=1"><b>Hardware</b>-&gt;</a>&nbsp;(6)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_17">CDROM Drives</a><br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_4"><b>Graphics Cards</b></a>&nbsp;(2)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_8">Keyboards</a>&nbsp;(1)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_16">Memory</a><br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_9">Mice</a>&nbsp;(2)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_6">Monitors</a><br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_5">Printers</a>&nbsp;(1)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_7">Speakers</a><br>
<a href="http://osc.cz.cc/index.php?cPath=2">Software-&gt;</a>&nbsp;(4)<br>
<a href="http://osc.cz.cc/index.php?cPath=3">DVD Movies-&gt;</a>&nbsp;(17)<br>

The display of the above $categories_string will look like the following:

Hardware-> (6)
  CDROM Drives
  Graphics Cards (2)
  Keyboards (1)
  Memory
  Mice (2)
  Monitors
  Printers (1)
  Speakers
Software-> (4)
DVD Movies-> (17)

Value of $categories_string when browsing osCommerce Graphics Cards Product (Matrox G200 MMS)

Browsing URL: http://osc.cz.cc/product_info.php?cPath=1_4&products_id=1

<a href="http://osc.cz.cc/index.php?cPath=1"><b>Hardware</b>-&gt;</a>&nbsp;(6)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_17">CDROM Drives</a><br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_4"><b>Graphics Cards</b></a>&nbsp;(2)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_8">Keyboards</a>&nbsp;(1)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_16">Memory</a><br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_9">Mice</a>&nbsp;(2)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_6">Monitors</a><br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_5">Printers</a>&nbsp;(1)<br>
&nbsp;&nbsp;<a href="http://osc.cz.cc/index.php?cPath=1_7">Speakers</a><br>
<a href="http://osc.cz.cc/index.php?cPath=2">Software-&gt;</a>&nbsp;(4)<br>
<a href="http://osc.cz.cc/index.php?cPath=3">DVD Movies-&gt;</a>&nbsp;(17)<br>

The display of the above $categories_string will look like the following:

Hardware-> (6)
  CDROM Drives
  Graphics Cards (2)
  Keyboards (1)
  Memory
  Mice (2)
  Monitors
  Printers (1)
  Speakers
Software-> (4)
DVD Movies-> (17)

How to print out the $categories_string

As you noticed that the $categories_string has the contents of the osCommerce Main Categories, it depends on how we display the contents on the webpage. Let's see how osCommerce print out the contents:

$categories_string = '';
$tree = array();

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");

while ($categories = tep_db_fetch_array($categories_query)) {

$tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
'parent' => $categories['parent_id'],
'level' => 0,
'path' => $categories['categories_id'],
'next_id' => false);

}

 

if (tep_not_null($cPath)) {

// Codes here will be executed
//when browsing Parent Categories, Sub-Categories and Products

}

tep_show_category($first_element);

$info_box_contents = array();
$info_box_contents[] = array('text' => $categories_string);

new infoBox($info_box_contents);

The last three lines of codes in bue color are used to print out the osCommerce Main Categories. You should be very familiar with these three lines of codes. Hm..... Oh... Yes, this is same as the Main Categories Header. This is also similar to the codes in the New Products Module.

Let's explain these codes briefly once again. This three lines of codes simply create a new $info_box_contents array. Then assign the value of $categories_string into $info_box_contents with "text" key name. Finally call the infoBox function with the value of $info_box_contents sent into.

We won't explain again how the above three line of codes working. This is same as the New Products Module.