Contributions

Features (Category Index)
Search: 

Nicer Resized Product Images combined with Random New Products and Buy Now button

Nicer Resized Product Images combined with Random New Products and Buy Now button
----------
New code in case someone else has the same problem I had in looking for an all in one for their new_products.php file in the future.

This is a combination of three contributions applied over the latest version of osCommerce as of March 2008. version osCommerce Online Merchant v2.2 Release Candidate 2a. This contribution combines the following:

* Random images on homepage / on new_products.php
* Resized images with FAST cache file for faster loading
* BUY NOW feature for each item on the new_products.php page.


1. Changing new items to Random Products:
Open the file new_products.php which is found at /catalog/includes/modules/
Find both instances of
CODE
p.products_date_added desc

Change both
CODE
p.products_date_added desc

to
CODE
RAND()

That completes the random images on your new_products.php modification.

2. Resizing images:
There are THREE steps to resizing the images on your new_products.php file.

FIRST:
Go to [via FTP] your /catalog/ install directory create a folder calling it 'img_cache'.
Next chmod this file to 777 so it is writable.

SECOND:
Go to catalog/includes/configure.php and at bottom, just before
CODE
?>

ADD:
CODE
/** Cache Resized Images BEGIN**/
define('DIR_WS_PRODUCT_IMAGE_CACHE_FS_PATH',DIR_FS_CATALOG . '/img_cache');
define('DIR_WS_PRODUCT_IMAGE_CACHE_HTTP_PATH',HTTP_SERVER . DIR_WS_HTTP_CATALOG . '/img_cache');
/** Cache Resize Images FINISH **/


THIRD:
Open the file new_products.php which is found at /catalog/includes/modules/ and FIND
CODE
$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'])));



REPLACE this completely with the following:
CODE
/** Cache Resized Images BEGIN**/
$fileToResize = DIR_FS_CATALOG . DIR_WS_IMAGES . $new_products['products_image'];
$resizedImageResult = resizeImage($fileToResize,SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
$resizedImage = $resizedImageResult[0];
$resizedImageWidth = $resizedImageResult[1];
$resizedImageHeight = $resizedImageResult[2];

$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($resizedImage, $new_products['products_name'], $resizedImageWidth, $resizedImageHeight) . '</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']))

/** Cache Resize Images FINISH **/


3. Adding the "BUY NOW" button
FIRST:
Find a .gif image on the internet suitable for your website or create one on your own. Name it button_buy_now.gif
Place this file into catalog/includes/languages/english/images/buttons/


SECOND:
Open the file new_products.php which is found at /catalog/includes/modules/.

Your are going to add
CODE
.'<br>'. '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $new_products['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> '

so it looks like the code found below in THIRD.

THIRD:
You are going to change the end of the following code
CODE
'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image($resizedImage, $new_products['products_name'], $resizedImageWidth, $resizedImageHeight) . '</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']))


So it looks like this
CODE
'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image($resizedImage, $new_products['products_name'], $resizedImageWidth, $resizedImageHeight) . '</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'])) .'<br>'. '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $new_products['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> ');


Here is my final version of new_products.php. REMEMBER I have additional modifications so see my website www.BudoMall.com for an example.

CODE
<?php
/*
$Id: new_products.php 1806 2008-01-11 22:48:15Z hpdl $

osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com

Copyright (c) 2008 osCommerce

Modifications by Johnpaul Williams
*Random images
*Resized images
*Buy now button feature
Released under the GNU General Public License
*/
?>
<!-- new_products //-->
<?php
$info_box_contents = array();
$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));

new contentBoxHeading($info_box_contents);

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 RAND() 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 RAND() limit " . MAX_DISPLAY_NEW_PRODUCTS);
}

$row = 0;
$col = 0;
$info_box_contents = array();
while ($new_products = tep_db_fetch_array($new_products_query)) {
/** Cache Resize Images BEGIN**/
$fileToResize = DIR_FS_CATALOG . DIR_WS_IMAGES . $new_products['products_image'];
$resizedImageResult = resizeImage($fileToResize,SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
$resizedImage = $resizedImageResult[0];
$resizedImageWidth = $resizedImageResult[1];
$resizedImageHeight = $resizedImageResult[2];

$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($resizedImage, $new_products['products_name'], $resizedImageWidth, $resizedImageHeight) . '</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'])) .'<br>'. '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $new_products['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> ');

/** Cache Resize Images FINISH **/
$col ++;
if ($col > 2) {
$col = 0;
$row ++;
}
}

new contentBox($info_box_contents);
?>
<!-- new_products_eof //-->

Expand All / Collapse All

Nicer Resized Product Images combined with Random New Products and Buy Now button gojuryu 18 Mar 2008

Nicer Resized Product Images combined with Random New Products and Buy Now button
----------
New code in case someone else has the same problem I had in looking for an all in one for their new_products.php file in the future.

This is a combination of three contributions applied over the latest version of osCommerce as of March 2008. version osCommerce Online Merchant v2.2 Release Candidate 2a. This contribution combines the following:

* Random images on homepage / on new_products.php
* Resized images with FAST cache file for faster loading
* BUY NOW feature for each item on the new_products.php page.


1. Changing new items to Random Products:
Open the file new_products.php which is found at /catalog/includes/modules/
Find both instances of
CODE
p.products_date_added desc

Change both
CODE
p.products_date_added desc

to
CODE
RAND()

That completes the random images on your new_products.php modification.

2. Resizing images:
There are THREE steps to resizing the images on your new_products.php file.

FIRST:
Go to [via FTP] your /catalog/ install directory create a folder calling it 'img_cache'.
Next chmod this file to 777 so it is writable.

SECOND:
Go to catalog/includes/configure.php and at bottom, just before
CODE
?>

ADD:
CODE
/** Cache Resized Images BEGIN**/
define('DIR_WS_PRODUCT_IMAGE_CACHE_FS_PATH',DIR_FS_CATALOG . '/img_cache');
define('DIR_WS_PRODUCT_IMAGE_CACHE_HTTP_PATH',HTTP_SERVER . DIR_WS_HTTP_CATALOG . '/img_cache');
/** Cache Resize Images FINISH **/


THIRD:
Open the file new_products.php which is found at /catalog/includes/modules/ and FIND
CODE
$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'])));



REPLACE this completely with the following:
CODE
/** Cache Resized Images BEGIN**/
$fileToResize = DIR_FS_CATALOG . DIR_WS_IMAGES . $new_products['products_image'];
$resizedImageResult = resizeImage($fileToResize,SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
$resizedImage = $resizedImageResult[0];
$resizedImageWidth = $resizedImageResult[1];
$resizedImageHeight = $resizedImageResult[2];

$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($resizedImage, $new_products['products_name'], $resizedImageWidth, $resizedImageHeight) . '</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']))

/** Cache Resize Images FINISH **/


3. Adding the "BUY NOW" button
FIRST:
Find a .gif image on the internet suitable for your website or create one on your own. Name it button_buy_now.gif
Place this file into catalog/includes/languages/english/images/buttons/


SECOND:
Open the file new_products.php which is found at /catalog/includes/modules/.

Your are going to add
CODE
.'<br>'. '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $new_products['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> '

so it looks like the code found below in THIRD.

THIRD:
You are going to change the end of the following code
CODE
'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image($resizedImage, $new_products['products_name'], $resizedImageWidth, $resizedImageHeight) . '</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']))


So it looks like this
CODE
'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image($resizedImage, $new_products['products_name'], $resizedImageWidth, $resizedImageHeight) . '</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'])) .'<br>'. '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $new_products['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> ');


Here is my final version of new_products.php. REMEMBER I have additional modifications so see my website www.BudoMall.com for an example.

CODE
<?php
/*
$Id: new_products.php 1806 2008-01-11 22:48:15Z hpdl $

osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com

Copyright (c) 2008 osCommerce

Modifications by Johnpaul Williams
*Random images
*Resized images
*Buy now button feature
Released under the GNU General Public License
*/
?>
<!-- new_products //-->
<?php
$info_box_contents = array();
$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));

new contentBoxHeading($info_box_contents);

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 RAND() 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 RAND() limit " . MAX_DISPLAY_NEW_PRODUCTS);
}

$row = 0;
$col = 0;
$info_box_contents = array();
while ($new_products = tep_db_fetch_array($new_products_query)) {
/** Cache Resize Images BEGIN**/
$fileToResize = DIR_FS_CATALOG . DIR_WS_IMAGES . $new_products['products_image'];
$resizedImageResult = resizeImage($fileToResize,SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
$resizedImage = $resizedImageResult[0];
$resizedImageWidth = $resizedImageResult[1];
$resizedImageHeight = $resizedImageResult[2];

$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($resizedImage, $new_products['products_name'], $resizedImageWidth, $resizedImageHeight) . '</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'])) .'<br>'. '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $new_products['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> ');

/** Cache Resize Images FINISH **/
$col ++;
if ($col > 2) {
$col = 0;
$row ++;
}
}

new contentBox($info_box_contents);
?>
<!-- new_products_eof //-->

Note: Contributions are used at own risk.