About Club osCommerce

Showcasing osCommerce…the good, the bad and the ugly!

Follow osc_pro on Twitter

Random Products on Front Page

Written By Gary on Apr 18 2008 · Comments (13) Follow osc_pro on Twitter

Almost daily, I see this question asked in the osCommerce Forum...

How can I have 9 random products showing in the the "New Products For..." box in the front page of my osCommerce site?

The answer is really, really simple - you need to change the SQL that selects the 9 products, like this;

Open up /includes/modules/new_products.php

Find:

PHP:
  1. p.products_date_added desc

Change to:

PHP:
  1. RAND()

Upload the file and refresh your index page. You'll get 9 random products rather than the last 9 added/amended products. A better option in my opinion would be to add a "Featured Products" contribution, as I think that no customer wants to see Random Products.


Buy Gary A Beer?
Buying me a "beer" helps me to keep my contributions updated and keep this blog alive - and you get a link from my homepage to your site. Cheers!


13 Comments

  1. I tried the script, but I still see the same old products that stay until I load something different. It made no difference. Not sure if I did something wrong.
    I used Front Page.

    Inaddition, my site is slower than molasses and I have been making lots of modifications and could use some help and or advise to improve the speed.

    Thanks

    Ron

    Comment by Ron Wilmot — August 12, 2008 @ 7:55 am


  2. Ron – never ever use a wusiwyg editor with oscommerce files. Try ultrapad or textpad or any other text editor…

    Make sure that your site uses that particular module to show the new_products, and make sure that no other contribution is contaminating it (eg featured products).

    For speeding up, it's a case of applying some code changes, making sure images are small, using 2 sizes of image if necessary, eliminatin html as much as possible. I wrote a short tutorial on it.

    Comment by Gary — August 12, 2008 @ 8:30 am


  3. How can change the: "New Products for June" on the front page?

    Comment by Martin — June 30, 2009 @ 8:36 pm


  4. includes/languages/english/index.php to change that text

    Comment by Gary — July 1, 2009 @ 12:12 pm


  5. Hello,
    I tried to do it, but I can't find "p.products_date_added desc".
    I do find "p.products_date_added desc limit" few times in that page.
    And my frontpage shows 12 items.
    I have osc 2.3.1.
    Maybe that's why?

    Comment by Alain — July 11, 2011 @ 7:46 am


  6. It's ok, it works fine.
    Thanks.

    Comment by Alain — July 11, 2011 @ 7:53 am


  7. There actually 12 items in the frontpage.
    Is it possible to se more items on that page?
    thank you.

    Comment by Alain — July 13, 2011 @ 12:20 pm


  8. This is a setting in your admin area. That is assuming the template has been correctly coded, which a lot of template are not!

    Comment by Gary — July 13, 2011 @ 3:41 pm


  9. I found it.
    Thanks.

    Comment by Alain — July 13, 2011 @ 5:37 pm


  10. Hello,
    regarding that, is it possible that products of only one category that I will choose will appear on the front page.
    thank you.

    Comment by Alain — July 15, 2011 @ 1:24 pm


  11. Gary, the mysql-based rand() command is rather slow (for large databases), is it not?
    I encountered this on a site I was working on for a friend: http://wanderr.com/jay/order-by-slow/2008/01/30/ – I used the join command, instead.

    Comment by angela — July 17, 2011 @ 8:28 am


  12. Hi Angela – yes, it can cause issues for larger databases. Instead of a simple 'rand()' you could try 'and rand()>0.9 order by rand()'

    A simple rand(), if that is not quick enough, then you would need to optimise all parts of your osCommerce shop anyway.

    Comment by Gary — July 21, 2011 @ 12:21 pm


  13. Change the SQL code in the new_products module, to look for products from X category rather than new_products_category_id

    Comment by Gary — July 21, 2011 @ 12:24 pm


Leave a comment

RSS feed for comments on this post · TrackBack URL

Hot 100 osCommerce Shops

View the osCommerce HOT 100These are the best looking, most exceptional osCommerce Stores as voted for by you.

New to osCommerce - get inspiration from these beautiful shops. Reckon your site has what it takes to become a member of the HOT 100? Submit it!