Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Random selection of different products


Guest

Recommended Posts

Hi

 

I need big help to rotate random selection of different products on the home page.

 

I asked this question few months ago and was given very helpful links, which I sent to my IT man to deal with. He said it's not possible to rotate the products on the version I have (osCommerce 2.2-MS2)

 

Is this true? I think it should work but I'm not an IT person. If someone could take me through all the steps of how to do this, I would really really appreciate it.

 

Please help me..... :(

Link to comment
Share on other sites

Make a backup of /includes/modules/new_products.php.

 

Open that file and file this section of code starting on line 24:

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, 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 where products_status = '1' 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, 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_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' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

}

 

Change it to:

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, 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 where products_status = '1' 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, 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_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' order by RAND() limit " . MAX_DISPLAY_NEW_PRODUCTS);

}

I'm not positive this will work but its worth a try.

Other great Open Source (Free) programs: (Free as in free speech not free beer)

The Gimp - An image program. | Firefox - All you have to do is add the Web Developer add-on to make this web browser complete. | FileZilla - An ftp program. | Inkscape - A good program to create images with. | Thunderbird - An email program. | Openoffice.org - An office suite that is compatible with MS Office. | Abiword - Another office suite. | Audacity - A sound recording tool. | ddp's Picks | Wordpress - An easy to use blogging software. | Joomla - An easy to use CMS that has ecommerce plug-ins. | Drupal - Another CMS

How do I find these programs? Google Search!

Link to comment
Share on other sites

  • 1 year later...
Make a backup of /includes/modules/new_products.php.

 

Open that file and file this section of code starting on line 24:

Change it to:

 

I'm not positive this will work but its worth a try.

 

Thank you also from Indy Online Pet Store, I have been trying to do the same and now thanks to this, I have. I have Os 2.2 MS2 with the RC1 /includes/module/new_products.php file installed, and it works on mine also. Thank you again!

 

Thanks

 

Mike

Link to comment
Share on other sites

  • 2 months later...

I have recoded my /modules/new_products.php as follows:

 

$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, 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 where products_status = '1' 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, 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,". 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' order by RAND()limit " . MAX_DISPLAY_NEW_PRODUCTS);

}

 

and now have a Parse error: syntax error, unexpected T_new on line 18.

Can anybody help this newbie please?

Link to comment
Share on other sites

Make a backup of /includes/modules/new_products.php.

 

Open that file and file this section of code starting on line 24:

Change it to:

 

I'm not positive this will work but its worth a try.

 

THANKS SO MUCH!!! :thumbsup:

 

ppl like you keep designers like me who have no idea on how to code alive. :'(

 

I just got yelled at by my customer for not showing random products on this web site. After many failed attemts, I came to this forum and searched for this code. Your instructions were spot on and all I had to do was a simple copy and paste.

 

Thanks again for your help! :thumbsup: :thumbsup: :thumbsup:

Link to comment
Share on other sites

Make a backup of /includes/modules/new_products.php.

 

Open that file and file this section of code starting on line 24:

Change it to:

 

I'm not positive this will work but its worth a try.

 

I've been pounding my head for just about a month now looking for a solution that I just found here!

 

Thanks. Now another problem. the page is no longer showing the product information..... any ideas?

 

my site is at www.budomall.com

 

my code is as follows

<?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

 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, 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 where products_status = '1' 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, 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_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' 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)) {
/** Cached Resized Images Hack Start **/
$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> ');

/** Cached Resized Images Hack End **/ 
$col ++;
if ($col > 2) {
  $col = 0;
  $row ++;
}
 }

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

Link to comment
Share on other sites

  • 2 weeks later...
Thanks. Now another problem. the page is no longer showing the product information..... any ideas?
Same problem here, tried another contribution but the products name isn't displayed when using random products.

Is there a solution for this?

 

Tnx

Link to comment
Share on other sites

It seems that most (if not all) 'random product' mods have the same problem.

This (above) script is perfect for me but I would like it that the names are displayed.

 

Tnx

 

Sorry - I completely forgot to re-post to this thread. I've created a completely new set up for the Random Products solution. It is under contributions as "Nicer Resized Product Images combined with Random New Products and Buy Now button" at http://addons.oscommerce.com/info/5824

 

Basically my site http://www.BudoMall.com has a new code for the file /catalog/includes/modules//new_products.php which looks like the following.

 

<?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 //-->

 

As for the Random products. I only made VERY simple changes to get it to work.

1. Changing new items to Random Products:

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

Find both instances of

p.products_date_added desc

 

Change both

p.products_date_added desc

 

to

RAND()

 

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

Link to comment
Share on other sites

  • 2 years later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...