Home | Store | osCommerce Tutorials

osCommerce New Products Display Module Customization Tips (2)

In previous osCommerce New Products Module tutorials, we already learned some basic customization. Let's do a bit complicated customization of the osCommerce New Products Module.

We are going to add "Add to Cart" buttons to each new products. This is a very common osCommerce New Products customization that we have seen in many osCommerce templates. This allows visitors to buy products directly from the New Products area without going through the Products Information page.

Some templates are using very complicated methods and changing the codes quite heavily. Since we learned the codes structure very well, we should be able to add minimum codes to accomplish the result.

Adding Add to Cart to osCommerce New Products Display

Take a look at the following codes again:

$row = 0;
$col = 0;
$info_box_contents = array();
while ($new_products = tep_db_fetch_array($new_products_query)) {

$info_box_contents[$row][$col] = array(

'align' => 'center',

'params' => 'class="smallText" width="33%" valign="top"',

'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' .
$new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES .
$new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH,
SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO,
'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a><br>' .
$currencies->display_price($new_products['products_price'],
tep_get_tax_rate($new_products['products_tax_class_id'])));

$col ++;
if ($col > 2) {
$col = 0;
$row ++;
}
}

We learned before in many previous tutorials that the new products query is fetch into the $new_products array variable. Then using the while loop to loop through the record one by one, writting the information into the 2-dimensional $info_box_contents array.

With this knowledge, we can add a value with new index name (e.g. addcart) to the 2-dimensional $info_box_contents array:

array('align' => 'center',
'params' => 'class="smallText" width="50%" valign="top"',

'addcart' => '<a href="' . tep_href_link(FILENAME_DEFAULT,
tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' .
$new_products['products_id']) . '">' . tep_image_button('button_in_cart.gif',
IMAGE_BUTTON_IN_CART) . '</a>',

'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO,.......

The changing the codes from:

echo "<td align=" . $info_box_contents[$row][$col]["align"] . " " . $info_box_contents[$row][$col]["params"] . ">" . $info_box_contents[$row][$col]["text"] . "</td>" . "\n";

to:

echo "<td align=" . $info_box_contents[$row][$col]["align"] . " " . $info_box_contents[$row][$col]["params"] . ">" . $info_box_contents[$row][$col]["text"] . "<br /><br />" . $info_box_contents[$row][$col]["addcart"] . "</td>" . "\n";

The output of osCommerce New Products Display should look like:

osCommerce New Products customization

PHP example filenew_products_customization_example-2-1.php

Of course you can arrange the product image, production name and product price in any position you like. The next osCommerce New Product Display customization tutorial will show how to do that.

This is the end of the osCommerce New Products Display customization tips 2.