![]() |
Random Products - 2 Products Per Row - In Place of Featured
I was wondering if anybody had ever replaced the featured products on the home page with a random list of 6-8 products, two per row? My thinking is it would make the site look less static. Anyone know how to achieve this?
|
I don't have a solution, but you're right. Random products would be a great feature. :)
|
The code must be in there already as it uses it for the recommended products.
|
I'm not a programmer by any means, or I'd be happy to dig in and find it. I was just hoping somebody had already done this, or would find it an interesting challenge and share the code with all of us. :)
|
Code:
$f_products = func_query("select $sql_tbl[products].*, min($sql_tbl[pricing].price) as price from $sql_tbl[products], $sql_tbl[featured_products], $sql_tbl[pricing], $sql_tbl[categories] where $sql_tbl[products].productid=$sql_tbl[featured_products].productid and $sql_tbl[pricing].productid=$sql_tbl[products].productid AND $sql_tbl[products].categoryid=$sql_tbl[categories].categoryid AND ($sql_tbl[categories].membership='$membership' OR $sql_tbl[categories].membership='') and $sql_tbl[products].forsale='Y' and $sql_tbl[products].avail>0 and $sql_tbl[featured_products].avail='Y' and $sql_tbl[pricing].quantity=1 AND $sql_tbl[featured_products].categoryid='$f_cat' and ($sql_tbl[pricing].membership='$membership' or $sql_tbl[pricing].membership='') group by $sql_tbl[products].productid order by $sql_tbl[featured_products].product_order"); Whew what a SQL query :? http://www.php.net/manual/en/printwn/function.rand.php Little mix of rand(); and some modified or added SQL queries and its possible. :wink: |
Boomer,
Wow! Now I see why I'm not a programmer. :) Is your code snippit what we need to accomplish this, and if so, where would we paste this in at?? |
this is the current sql not the new stuff. the new stuff will be more complex than this. :wink:
need to add this into customer/home.php Code:
include "./random.php"; This will bring in a list of random products. Then we need to create this random.php in customer/ and is based on reccomends.php Code:
<? You will then need to include this in the home page by modifying the appropriate templates. |
funkydunk,
Thanks a million for the code. I made the change to my customer/home.php and created the customer/random.php, but nothing changed. I still have the same 'Featured Products' showing up as they always have. I see where you said to 'include this in the home page by modifying the appropriate templates'. Would you please explain this in more detail (i.e. which templates and what exactly to add), as not only am I not a programmer, I am VERY new to X-Cart as well. :) Looking forward to hearing from you. |
PLEASE BACKUP ALL FILES BEFOREHAND JUST IN CASE!!
I haven't tested this but I would change skin1/customer/home_main.tpl as follows: from: {elseif $main eq "catalog" and $current_category.category eq ""} {include file="customer/main/welcome.tpl" f_products=$f_products} to: Code:
{elseif $main eq "catalog" and $current_category.category eq ""} Then amend customer/main/welcome.tpl to: Code:
{* $Id: welcome.tpl,v 1.21 2002/09/10 12:36:34 zorg Exp $ *} then creat a new template customer/main/randoms.tpl Code:
{* $Id: randoms.tpl,v 1.13 2002/05/20 06:55:20 lucky Exp $ *} then creat a new lbl in the languages area named lbl_random_products with the value that y9ou want to have shown in the top of the box. |
funkydunk,
Wow, you're good....you're FUNKY good! :wink: The only problem is that my random products have "Enter your price !" instead of "Our price: $". This kind of needs addressed as we don't want the customer thinking they can pick their own price. :) Any ideas on what the last tweak to the puzzle might be? |
you would need to remove some code from the products.tpl this is covered in another post....http://forum.x-cart.com/viewtopic.php?t=1024&highlight=
thanks :) |
I'm the new person here-abouts, but why couldn't you achieve the rotating/random product selection by defining a whole list of "featured products" and then display only a set number of them? (at random, of course)
Hmmm, now how would I do this? deb |
This could be done but the idea for this was to provide a random product from the complete catalogue without having to specify them as a featured product.
|
If you have a large db, do you think this could slow down the page generation pretty badly? I mean, what if you have like 50,000 items and each time a rand-type page is called, the script has to crank through the whole 50K. Perhaps there might be a way to define a group (as mentioned by deb) from which to select rand items. I'm just thinking of the time it's going to take to create the pages. :)
|
DogTags
On a big db you are right :) , this would take some processing to do this. Another option would be (if you still wanted it sort of random) to set up some kind of rule that selected a range of products depending on the day of the week etc. The file to amend would be the randoms.php file that I created. |
Thanks, funkydunk.
Yeah, I figured as much. Maybe some items could be designated as "random" and then the rand.php file could select from that group. I dunno... |
Any one tried this on the 3.3.x yet?
|
I haven't tried this on 3.3. yet but looking at it, there is no reason why it shouldn't work as the elements that I was using for this are not altered in 3.3
|
Hi All
I managed to do this on our front page, but cheated and used PHP inside the template.. (needed to get it running quickly :wink: ) http://www.overclock.co.uk/xcart Please dont do any test orders, it isnt live yet but the emails are a pain :lol: Any comments would be good aswell. |
Now I find a place to get a wifi card from !! :lol: Let me know when you are live cos I could do with a pcmia wifi card on the cheap.
Nice looking site and good mods. I often 'cheat' by using pure php - if it is what you know it works very well indeed. Xcart is great for running out of the box but some great mods can be put in by adding some special bits yourself. Cheers |
Thanks m8
We are running on www.overclock.co.uk already but just havent implemented xcart as yet. i am running here on a complete wireless Lan, it is amazing lol no wires. we should be getting some NetGear stuff in soon aswell Jonny. |
Enter Your Price
:oops: Hi have installed these scripts among ther script and it all work great, but on The Enter your price,(under feature) i want to display the actual price , how can this bee done i have tried to modify the products.tpl and enter
<font class=TableCenterProductTitleOrange>{$lng.lbl_ente r_your_price} to <font class=TableCenterProductTitleOrange>{$products[product].price} but it only displays 0.00 Can someone help me out here http://data.eol.no |
Try this new and revised code for the randoms.php file. It now joins the product table with the pricing table - should have been in there really to start with..sorry everyone :)
Code:
removed cos it was wrong!! |
Error after new randoms.php
Hi there must be something wrong with the new code. ir runs an SQL eror.
INVALID SQL: 1052 : Column: 'productid' in where clause is ambiguous SQL QUERY FAILURE: SELECT * FROM xcart_products,xcart_pricing WHERE forsale='Y' AND avail>0 AND xcart_products.productid=xcart_pricing.productid AND (productid='8' OR productid='47' OR productid='61' OR productid='54' OR productid='40' OR productid='34' OR productid='11' OR productid='42' OR productid='60' OR productid='57') |
okay - sorry..amateur mistake :oops:
amend the code to: Code:
<? |
Funky, this code is great and your instructions are GREAT! I just read through the thread, followed the steps, used the revised random.php code and it works perfect.
But of course, I have a question. ;-) Sometimes it shows 7, 8 or 9 products. I only have 50 products added so far, so I'm thinking that once I get all 300 or so added in that it will always show 10. If not, I really don't care, because just having it randomize is SO COOL! Thanks, Cameron |
Thanks.
It should be showing 10 products though. :? |
No worries. I realized that I like having 8 products there, anyway, so I changed the value to 8. Sometimes it shows 6 or 7, but I think it is actually cool so that people coming back see a pretty dynamic page. Google spiders will probalby love it, too. :D
Cameron |
cant remember why I wrote this now :? , but very useful instead of featured products and to have a different looking front page every visit.
|
Funky, You wrote it because I asked if anybody had this feature, and you came in and knocked it out in no time. Mine also comes up one short on occasion, but it's no big deal at all. Thanks a MILLION for the great code! :)
|
Really glad you like it and it works for you. :D
|
Quote:
I have a rather large DB myself, and the random idea is cool but I'm probably going to stick with the featured products list. However, I do like the two items idea. I was wondering how we could modify the featured products tpl to allow two items to appear on one row ? I tried doing it myself within the loop, but I can't figure out how to use smarty's code to generate my own counter variable and increment it each run, so I can use a modulus comparison to print out a </TR><TR> after every second row. Any help would be appreciated.. |
if you use the code in http://forum.x-cart.com/viewtopic.php?p=10593#10593 this will work for featured products aswell.
|
I keep getting an error with my random.php:
Quote:
my line 16 is the line with the actual rand function. Could this function be disallowed by my server? This is line 16: Code:
б═ б═$rnd = rand(0, count($products_id)-1); Made the switch while live (my site doesn't get much traffic yet anyway) so I would like to get this straightened out quick. Thanks |
I have got it working but I am doing the random part in the SQL query. My random.php is now:
Code:
<? This seems easy enough to me, are there any drawbacks to doing it this way? I also added the original featured products back into the random.tpl so now I can specify one or two perminant featured products (with the X-cart module) and have two random ones. Any other sugestions? This seems too easy compared to other solutions :wink: . |
What i did i do wrong? I get this error:
Fatal error: Call to undefined function: func_query() in /home/virtual/site110/fst/var/www/html/acart/customer/random.php on line 3 I'm a little confused with random.php or randoms.php. |
Where do I put this? it seems to be the only step I cant figure out.
thanks Quote:
|
Could someone help me with this?
|
From this post
Code:
this is the current sql not the new stuff. the new stuff will be more complex than this. Where in the home.php code does the include string go, or should it be 'require' instead of 'include'? Should the random.php file go into the customer/ directory, or customer/main/ ? Thanx |
Quote:
Nope you did it the more efficient way. Using mysql to do the random select and limit is way more efficient than the other methods. Also means nothing heavy happens on the database :) I was reading this thread and thinking why don't they just use the mysql ORDER BY RAND() LIMIT 10. Saves on all the counting products, randomising seeds and stuff. Nice one. Note to others, using ORDER BY RAND() LIMIT in any sql statement will randomise your results for you. Very handy for having random offers/news/quote showing. |
All times are GMT -8. The time now is 12:34 PM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.