Guest Posted November 6, 2006 Posted November 6, 2006 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..... :(
natewlew Posted November 6, 2006 Posted November 6, 2006 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!
Guest Posted November 12, 2006 Posted November 12, 2006 Dear Nate Thank you so much for the prodcut rotation codes... all works!!!!!!!!!!!! I'm so happy now... Thank you again
Guest Posted December 25, 2007 Posted December 25, 2007 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
lingerie Posted March 12, 2008 Posted March 12, 2008 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?
Guest Posted March 16, 2008 Posted March 16, 2008 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:
slickeddie Posted March 16, 2008 Posted March 16, 2008 Worked great and trust me I am green as a cucumber at this. Now how do I control the number of products being shown on that same page? Thanks for any help.
gojuryu Posted March 17, 2008 Posted March 17, 2008 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 //-->
Guest Posted March 18, 2008 Posted March 18, 2008 You guys are aware that there is a contribution called random products.
slickeddie Posted March 19, 2008 Posted March 19, 2008 Got it to show 6 and that's good enough for me. Changed the new_products.php; $row = 3; $col = 0; Which gave me three rows of two.
Whitespliff Posted April 2, 2008 Posted April 2, 2008 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
Whitespliff Posted April 4, 2008 Posted April 4, 2008 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
gojuryu Posted April 4, 2008 Posted April 4, 2008 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.
s_cunha78 Posted August 11, 2010 Posted August 11, 2010 Perfect, tnx a lot! I would like to random the items in the first page, but by categories, not all mixed up. Can anywone know how to do this? Best regards, Sérgio
Recommended Posts
Archived
This topic is now archived and is closed to further replies.