Home | Store | osCommerce Tutorials

osCommerce New Products Module - New Products Header (1)

Part 1 - Study code structure of osCommerce New products Header


In this osCommerce tutorial, we will study the code or file structure of the New Products Header.

Open the includes/modules/new_products.php file.

The first three lines of codes of new_products.php is used to display the osCommerce New Products Header.

$info_box_contents = array();
$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));

new contentBoxHeading($info_box_contents);

osCommerce Customization Tips:
Remove the New Products Header by commenting the above three lines of codes

Let's discuss this three lines of codes one by one.

$info_box_contents = array();

The first line simply create a new array with $info_box_contents variable name. Now this new array is empty, i.e. the new array contains no any value.

$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));

After a new array has been created. The next step is usually to add value(s) to the array. Unlike a normal variable, a key is required for each value.

The second line of code is use to assign a value to the array:

  • the value is "sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B'))"
  • the name of key of this value is "text"

If you check the value of $info_box_contents like this:

print_r ($info_box_contents);

The output of the $info_box_contents will be:

Array ( [0] => Array ( [text] => New Products For October ) )

If you like a better looking output, you can use:

echo '<pre>';
$info_box_contents = array();
$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));
print_r($info_box_contents);
echo '</pre>';

The output of the $info_box_contents will then be more readable:

Array
(
[0] => Array
(
[text] => New Products For October
)

)

Note that the $info_box_contents is a two-dimensional array. We need both row index and column index to reference to element of the array.

In the above example, the row index is "0" and the column index is "text". Therefore the value of the "New Products For October" can be obtained by:

echo $info_box_contents[0]["text"];

The output of this code will be:

New Products For October

If you do not know how the PHP sprintf() function and strftime() function work, please check the following PHP Tutorials:

Click here to read the PHP sprintf() function.

Click here to read the PHP strftime() function.

Now the $info_box_contents array contains the value of New Products Header (i.e. New products For Month). We have enough information to display the New products Header. Like previous tutorials, this is a good idea to see if we can write the codes on our own to get the same result.

In the next osCommerce tutorial, we are going to write our own codes to display the osCommerce New Products Header on the webpage. After we write our own osCommerce codes, we will also study how the original osCommerce codes work.