X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Random Products - 2 Products Per Row - In Place of Featured (https://forum.x-cart.com/showthread.php?t=914)

okdpminc 12-09-2002 04:28 PM

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?

DogTags 12-10-2002 07:22 AM

I don't have a solution, but you're right. Random products would be a great feature. :)

funkydunk 12-10-2002 08:33 AM

The code must be in there already as it uses it for the recommended products.

okdpminc 12-10-2002 01:57 PM

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. :)

B00MER 12-10-2002 04:04 PM

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:

okdpminc 12-11-2002 09:15 AM

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

funkydunk 12-11-2002 10:38 AM

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:

<?
// give it all available products to work with
$products_id = func_query("SELECT productid FROM $sql_tbl[products] WHERE forsale='Y' and avail>0");

// set the variables
$str = "";
$numberRandoms=10; // set this to how many you want to show

// the witchcraft
$query_condition = " AND (";
srand((double)microtime()*1000000);
$rnd = rand(0, count($products_id)-1);
$query_condition .= "productid='".$products_id[$rnd][productid]."'";
for($i = 0; $i < $numberRandoms - 1; $i++) {
        $rnd = rand(0, count($products_id)-1);
        if (!ereg("'".$products_id[$rnd][productid]."'", $query_condition)) {
                  $query_condition .= " OR productid='".$products_id[$rnd][productid]."'";
          }
}
// finish off the query
    $query_condition .= ")";

// runs the new random query against the database
    $query = "SELECT * FROM $sql_tbl[products] WHERE forsale='Y' AND avail>0".$query_condition;

// give the product array to smarty to make it available sitewide.
$randoms = func_query($query);
$smarty->assign("randoms",$randoms);
?>


You will then need to include this in the home page by modifying the appropriate templates.

okdpminc 12-11-2002 07:30 PM

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.

funkydunk 12-12-2002 05:05 AM

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 ""}
{include file="customer/main/welcome.tpl" randoms=$randoms}

to replace the featured products

Then amend customer/main/welcome.tpl to:

Code:

{* $Id: welcome.tpl,v 1.21 2002/09/10 12:36:34 zorg Exp $ *}
{if ($active_modules.Greet_Visitor ne "") AND ($smarty.cookies.GreetingCookie ne "")}
<h3>{$lng.lbl_welcome_back}, {$smarty.cookies.GreetingCookie} </h3>
{else}
<h3>{$lng.lbl_welcome_to} { $config.Company.company_name }</h3>
{/if}
{$lng.txt_welcome}



{if $active_modules.Bestsellers ne "" and $config.Modules.bestsellers_menu ne "Y"}
{include file="modules/Bestsellers/bestsellers.tpl"}
{/if}



{include file="customer/main/randoms.tpl" randoms=$randoms}


then creat a new template
customer/main/randoms.tpl

Code:

{* $Id: randoms.tpl,v 1.13 2002/05/20 06:55:20 lucky Exp $ *}
{capture name=dialog}
{include file="customer/main/products.tpl" products=$randoms}
{/capture}
{include file="dialog.tpl" title=$lng.lbl_random_products content=$smarty.capture.dialog extra="width=100%"}


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.

okdpminc 12-12-2002 05:15 PM

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?

funkydunk 12-12-2002 10:26 PM

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 :)

deb 12-28-2002 12:10 PM

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

funkydunk 12-29-2002 01:16 AM

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.

DogTags 12-29-2002 04:54 AM

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. :)

funkydunk 12-29-2002 09:41 AM

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.

DogTags 12-29-2002 10:15 AM

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

mikew 01-10-2003 06:22 PM

Any one tried this on the 3.3.x yet?

funkydunk 01-10-2003 11:48 PM

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

Jonny 01-12-2003 07:03 AM

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.

funkydunk 01-12-2003 08:01 AM

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

Jonny 01-12-2003 09:28 AM

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.

dfaa 01-16-2003 11:42 PM

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

funkydunk 01-16-2003 11:54 PM

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

dfaa 01-17-2003 12:17 AM

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')

funkydunk 01-17-2003 12:34 AM

okay - sorry..amateur mistake :oops:

amend the code to:

Code:

<?
// give it all available products to work with
$products_id = func_query("SELECT productid FROM $sql_tbl[products] WHERE forsale='Y' and avail>0");

// set the variables
$str = "";
$numberRandoms=10; // set this to how many you want to show

// the witchcraft
$query_condition = " AND (";
srand((double)microtime()*1000000);
$rnd = rand(0, count($products_id)-1);
$query_condition .= "$sql_tbl[products].productid='".$products_id[$rnd][productid]."'";
for($i = 0; $i < $numberRandoms - 1; $i++) {
        $rnd = rand(0, count($products_id)-1);
        if (!ereg("'".$products_id[$rnd][productid]."'", $query_condition)) {
                  $query_condition .= " OR $sql_tbl[products].productid='".$products_id[$rnd][productid]."'";
          }
}
// finish off the query
    $query_condition .= ")";

// runs the new random query against the database
    // $query = "SELECT * FROM $sql_tbl[products] WHERE forsale='Y' AND avail>0".$query_condition;
   
$query = "SELECT * FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 AND $sql_tbl[products].productid=$sql_tbl[pricing].productid".$query_condition;

// give the product array to smarty to make it available sitewide.
$randoms = func_query($query);
$smarty->assign("randoms",$randoms);
?>


Cameron 03-02-2003 09:49 PM

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

funkydunk 03-02-2003 10:18 PM

Thanks.

It should be showing 10 products though. :?

Cameron 03-02-2003 10:58 PM

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

funkydunk 03-02-2003 11:14 PM

cant remember why I wrote this now :? , but very useful instead of featured products and to have a different looking front page every visit.

okdpminc 03-03-2003 07:05 PM

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! :)

funkydunk 03-03-2003 10:38 PM

Really glad you like it and it works for you. :D

timtrolious 03-17-2003 07:33 PM

Quote:

Originally Posted by funkydunk
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.


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

funkydunk 03-17-2003 10:04 PM

if you use the code in http://forum.x-cart.com/viewtopic.php?p=10593#10593 this will work for featured products aswell.

davesphoto 06-28-2003 08:39 AM

I keep getting an error with my random.php:

Quote:

Parse error: parse error, unexpected T_STRING in /www/d/davesphoto/htdocs/store/customer/random.php on line 16

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

davesphoto 06-28-2003 10:44 AM

I have got it working but I am doing the random part in the SQL query. My random.php is now:

Code:

<?
// the database query
$query = "SELECT * FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 AND $sql_tbl[products].productid=$sql_tbl[pricing].productid ORDER BY RAND() LIMIT 2 ";


// give the product array to smarty to make it available sitewide.
$randoms = func_query($query);
$smarty->assign("randoms",$randoms);
?>


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: .

70challenger 06-29-2003 01:08 AM

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.

70challenger 06-29-2003 09:18 AM

Where do I put this? it seems to be the only step I cant figure out.
thanks

Quote:

Originally Posted by B00MER
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:


70challenger 07-07-2003 11:13 AM

Could someone help me with this?

toonarific 07-07-2003 12:59 PM

From this post

Code:

this is the current sql not the new stuff. the new stuff will be more complex than this. 

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:

<?
// give it all available products to work with
$products_id = func_query("SELECT productid FROM $sql_tbl[products] WHERE forsale='Y' and avail>0");

// set the variables
$str = "";
$numberRandoms=10; // set this to how many you want to show

// the witchcraft
$query_condition = " AND (";
srand((double)microtime()*1000000);
$rnd = rand(0, count($products_id)-1);
$query_condition .= "productid='".$products_id[$rnd][productid]."'";
for($i = 0; $i < $numberRandoms - 1; $i++) {
  $rnd = rand(0, count($products_id)-1);
  if (!ereg("'".$products_id[$rnd][productid]."'", $query_condition)) {
        $query_condition .= " OR productid='".$products_id[$rnd][productid]."'";
    }
}
// finish off the query
    $query_condition .= ")";

// runs the new random query against the database
    $query = "SELECT * FROM $sql_tbl[products] WHERE forsale='Y' AND avail>0".$query_condition;

// give the product array to smarty to make it available sitewide.
$randoms = func_query($query);
$smarty->assign("randoms",$randoms);
?>


You will then need to include this in the home page by modifying the appropriate templates.


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

groovico 07-19-2003 09:19 AM

Quote:

Originally Posted by davesphoto
I have got it working but I am doing the random part in the SQL query. My random.php is now:

Code:

<?
// the database query
$query = "SELECT * FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 AND $sql_tbl[products].productid=$sql_tbl[pricing].productid ORDER BY RAND() LIMIT 2 ";


// give the product array to smarty to make it available sitewide.
$randoms = func_query($query);
$smarty->assign("randoms",$randoms);
?>


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: .


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.