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?


All times are GMT -8. The time now is 09:50 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.