Home | Store | osCommerce Tutorials

osCommerce New Products Module - New Products Display (1)

Part 1 - Study codes structure of osCommerce New products Display


In this osCommerce tutorial, we are going to study the file structure of the New Products Display. Let's study the codes from the beginning:

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
$new_products_query = tep_db_query("select p.products_id, p.products_image,
p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price,
p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s
on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd
where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" .
(int)$languages_id . "' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
} else {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image,
p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price,
p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s
on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " .
TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id =
p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" .
(int)$new_products_category_id . "' and p.products_status = '1' and p.products_id = pd.products_id
and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added desc limit " .
MAX_DISPLAY_NEW_PRODUCTS);
}

Let's discuss the first condition.

(!isset($new_products_category_id))

Up to now, we should be quite familiar with this kind of code.

isset means is set

!isset means is not set

If you study the codes of osCommerce homepage (catalog/index.php) again, you should notice that the $new_products_category_id variable is only set when $category_depth == 'nested' (i.e. browsing Parent Categories).

The following diagram shows part of the codes of osCommerce homepage:

osCommerce $new_products_category_id

In other words, the $new_products_category_id variable will only be set when browsing the osCommerce Parent Categories.

Therefore (!isset($new_products_category_id)) will:

  • TRUE - when browsing osCommerce homepage
  • FALSE - when browsing osCommerce Parent Categories.

How about the second condition:

$new_products_category_id == '0'

Obviously, the $new_products_category_id will not be equal to zero in the default osCommerce shop. Therefore the second condition will always be FALSE.

The PHP "||" operator means "OR".

Combining the two conditions to-gether will get the following results:

  • TRUE - when browsing osCommerce homepage
  • FALSE - when browsing osCommerce Parent Categories.

The codes will then be:

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {

// Codes here will be executed
// when browsing osCommerce homepage

} else {

// Codes here will be executed
//when browsing osCommerce Parent Categories (e.g. Hardware, Softwares and DVD Movies)

}

Now, we know which codes will be executed when browsing osCommerce homepage and osCommerce Parent Categories.

In the next osCommerce tutorial, we will study the code structure of New products Display when browsing osCommerce homepage.