Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

New Products For August box HELP!!


digi

Recommended Posts

hello all,

 

In my front page of my shop I have the "New Products For August" box in the middle, how do I make it so that it picks random products everytime, so its not always the same? (evertime a user comes, its different products on the homepage, or if I hit refresh it changes?)

 

I am useing oscommerce version MS1.

 

thanks

 

digi

*Outlined in chalk everone looks the same*

 

Currently useing OSC 2.2 MS1

running on Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_jk/1.2.0 mod_perl/1.26 PHP/4.3.3 FrontPage/5.0.2 mod_ssl/2.8.12 OpenSSL/0.9.6b

Link to comment
Share on other sites

I think in catalog/includes/modules/new_products.php if you change all instances of

 

tep_db_query

 

to

 

tep_random_select

 

it should do the trick although you might get two of the same random products come up at once!? would need some extra checks to stop this.

Reddy to Rumble

 

Thank you osCommerce and all who Contribute to her!

Link to comment
Share on other sites

hello rumble.

thanks for the quick reply,

 

when I changed the instances like you said I got the following error.

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/html/shop/catalog/includes/functions/database.php on line 99

 

when I goto the database.php file on line 99, there is tep_db_query instance. I changed this to tep_random_select (there where 2).

 

I uploaded everything and it gave me more fatel errors, in application top and stuff, but I put everything back to what it was before so I dont mess everything up.

 

 

digi

*Outlined in chalk everone looks the same*

 

Currently useing OSC 2.2 MS1

running on Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_jk/1.2.0 mod_perl/1.26 PHP/4.3.3 FrontPage/5.0.2 mod_ssl/2.8.12 OpenSSL/0.9.6b

Link to comment
Share on other sites

ok, after hours of painful work here is the working code that will make this all happen, (just in case someone searchs this forum for this problem agin)

 

replace the code in file:

 

catalogincludesmodulesnew_products.php

 

change your whole new_products.php file to:

 

<?php

/*

$Id: new_products.php,v 1.33 2003/02/12 23:55:58 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 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() 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 = '" . $new_products_category_id . "' and p.products_status = '1' order by rand() DESC limit " . MAX_DISPLAY_NEW_PRODUCTS);

}

 

$row = 0;

$col = 0;

$info_box_contents = array();

while ($new_products = tep_db_fetch_array($new_products_query)) {

$new_products['products_name'] = tep_get_products_name($new_products['products_id']);

$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 ++;

}

}

 

new contentBox($info_box_contents);

?>

<!-- new_products_eof //-->

 

 

 

digi

*Outlined in chalk everone looks the same*

 

Currently useing OSC 2.2 MS1

running on Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_jk/1.2.0 mod_perl/1.26 PHP/4.3.3 FrontPage/5.0.2 mod_ssl/2.8.12 OpenSSL/0.9.6b

Link to comment
Share on other sites

it should do the trick although you might get two of the same random products come up at once!? would need some extra checks to stop this.

 

I have refreshed the page at least 50 times, and no 2 products have showed up at one time,

 

I am just wondering what would happen when september comes and I dont add any new products? does the "new products for **" just disappear?

*Outlined in chalk everone looks the same*

 

Currently useing OSC 2.2 MS1

running on Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_jk/1.2.0 mod_perl/1.26 PHP/4.3.3 FrontPage/5.0.2 mod_ssl/2.8.12 OpenSSL/0.9.6b

Link to comment
Share on other sites

  • 2 weeks later...
ok, after hours of painful work here is the working code that will make this all happen, (just in case someone searchs this forum for this problem agin)

 

replace the code in file:

 

catalogincludesmodulesnew_products.php

 

change your whole new_products.php file to:

 

You rock! Thanks a bunch for this code!

Have you ever gotten any help from these forums? Be part of the community and help out by answering a question or 2.

Pass on what you know about OSC to someone who needs help.

Link to comment
Share on other sites

Thanks Digi, for the code!

 

Now, i am currently looking for a slightly modified version of this code so that the first line (3) items are the latest products for the month, and the 2nd and 3rd lines are the random products, like what you have dome in this code!

 

Thanks in advance!

Link to comment
Share on other sites

great code! Where do I go to change the "New Products for (MONTH)" ? I would like to change this text.

 

catalog/includes/languages/english/default.php

somewhere around LINE 14 change:

define('TABLE_HEADING_NEW_PRODUCTS', 'New Products For %s');

Have you ever gotten any help from these forums? Be part of the community and help out by answering a question or 2.

Pass on what you know about OSC to someone who needs help.

Link to comment
Share on other sites

  • 1 month later...

Am i wrong or does this code along with the contrib select everything in the database (with status 1) and then chose randomly the limit number? This means you will get old itmes as well as new ones. Has any one come up with code for choosing randomly new items only? Like the way the "what's new" box works.

Link to comment
Share on other sites

hello domaingirls,

 

yes, this code takes any product form the database and sticks it in the whats new for ** month box.

 

with this code, you should very easily modify it to pull only "new" products for the month, (like whats new boX).

 

I just didnt have enough new products every month to have it setup like that, so I did it this way,

 

digi

*Outlined in chalk everone looks the same*

 

Currently useing OSC 2.2 MS1

running on Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_jk/1.2.0 mod_perl/1.26 PHP/4.3.3 FrontPage/5.0.2 mod_ssl/2.8.12 OpenSSL/0.9.6b

Link to comment
Share on other sites

hello domaingirls,

 

yes, this code takes any product form the database and sticks it in the whats new for ** month box.

 

with this code, you should very easily modify it to pull only "new" products for the month, (like whats new boX).

 

I just didnt have enough new products every month to have it setup like that, so I did it this way,

 

digi

Hey digi,

 

it sounds easy but it was over my head. You would need to have it pull a certain number of rows from the datbase sorted by when it was added, then randomize that list and limit it to the number of items you want displayed and output it. I couldn't code it. any help?

Link to comment
Share on other sites

Hello DomainGirls,

 

I have been very busy lately, but I will see what I can wip up for you!

*Outlined in chalk everone looks the same*

 

Currently useing OSC 2.2 MS1

running on Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_jk/1.2.0 mod_perl/1.26 PHP/4.3.3 FrontPage/5.0.2 mod_ssl/2.8.12 OpenSSL/0.9.6b

Link to comment
Share on other sites

  • 3 months later...

You could do this with subqueries, but that would limit you to mySQL 4.2 or later I think.

 

You could also randomize the resulting array from mySQL - say pull out the last 90 products added and then randomize the array, using then the resultant MAX display values. This might be the most compatible method.

 

Most people have taken the easy way out (me included) and simply changed the New Products box to a "Product Selections" box and gone to rand()...

 

-t

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...