X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Replacing "Featured Products" with "Recommend (https://forum.x-cart.com/showthread.php?t=14503)

dundeemedia 02-05-2006 10:24 AM

Quote:

Originally Posted by Maree
I've also added a hack to pull the price up


could you post details of that hack, as I had tried one from this forum, but it doesn't show the price, just shows the list price!

xcell67 04-16-2006 10:31 AM

my version for 4.1.0rc4

create a file called random.php and put it in your stores root

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 6 ";
// give the product array to smarty to make it available sitewide.
$randoms = func_query($query);
$smarty->assign("randoms",$randoms);
?>


The query will only pick up live items that are in stock.

Place:
Code:

include "./random.php";

under
Code:

if($active_modules["Bestsellers"])
        include $xcart_dir."/modules/Bestsellers/bestsellers.php";


in root/home.php


create skin1/customer/main/randoms.tpl

Code:

{* $Id: randoms.tpl,v 1.13 2002/05/20 06:55:20 lucky Exp $ *} <font class=big>From the Brew</font></font>

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


edit skin1/customer/home.tpl or wherever you want to place the random products and use this code to call it:

Code:

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



:lol:

xcell67 04-16-2006 09:34 PM

damnit, the query will sometimes show a product twice :x Anyone know how to modify the query so that it will only select an item once?

geckoday 04-17-2006 06:11 AM

Quote:

Originally Posted by xcell67
damnit, the query will sometimes show a product twice :x Anyone know how to modify the query so that it will only select an item once?


Try this.

Code:

SELECT $sql_tbl[products].*, (SELECT MIN($sql_tbl[pricing].price) FROM $sql_tbl[pricing] WHERE $sql_tbl[pricing].productid=$sql_tbl[products].productid  AND $sql_tbl[pricing].quantity=1 AND $sql_tbl[pricing].variantid = 0) AS price FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 ORDER BY RAND() LIMIT 6

If you use multiple languages or have categories limited to certain members you should look at the queries in recommends.php to sort out modifying the query further for those cases.

If you care about taxed prices and thumbnail images you also need to add just before the smarty assign:

Code:

if (is_array($randoms) && count($randoms) > 0) {
  foreach ($randoms as $k=>$v) {
    $randoms[$k]["tmbn_url"] = func_get_thumbnail_url($v["productid"]);
    $randoms[$k]["taxes"] = func_get_product_taxes($randoms[$k], $login);
  }
}


xcell67 04-19-2006 11:25 PM

hey gecko, thanks for your help/input

Im getting this error:

Parse error: parse error, unexpected T_VARIABLE in /home/metapot/public_html/tcart/random.php on line 3

This how my random.php currently looks like

Code:

<?
// the database query
SELECT $sql_tbl[products].*, (SELECT MIN($sql_tbl[pricing].price) FROM $sql_tbl[pricing] WHERE $sql_tbl[pricing].productid=$sql_tbl[products].productid  AND $sql_tbl[pricing].quantity=1 AND $sql_tbl[pricing].variantid = 0) AS price FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 ORDER BY RAND() LIMIT 6
// give the product array to smarty to make it available sitewide.
$randoms = func_query($query);
$smarty->assign("randoms",$randoms);
?>


geckoday 04-20-2006 05:34 AM

Sorry, I just posted the SQL part of the statement. You need to assign it to $query like this:

Code:

$query = "SELECT $sql_tbl[products].*, (SELECT MIN($sql_tbl[pricing].price) FROM $sql_tbl[pricing] WHERE $sql_tbl[pricing].productid=$sql_tbl[products].productid  AND $sql_tbl[pricing].quantity=1 AND $sql_tbl[pricing].variantid = 0) AS price FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 ORDER BY RAND() LIMIT 6 ";

xcell67 04-30-2006 03:08 AM

hey gecko, thanks for your help.

I used your code and now random.php is:

Code:

<?
// the database query
$query = "SELECT $sql_tbl[products].*, (SELECT MIN($sql_tbl[pricing].price) FROM $sql_tbl[pricing] WHERE $sql_tbl[pricing].productid=$sql_tbl[products].productid  AND $sql_tbl[pricing].quantity=1 AND $sql_tbl[pricing].variantid = 0) AS price FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 ORDER BY RAND() LIMIT 6 ";
// give the product array to smarty to make it available sitewide.
$randoms = func_query($query);
$smarty->assign("randoms",$randoms);
?>


but now the cart shows this error:

INVALID SQL: 1064 : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT MIN(xcart_pricing.price) FROM xcart_pricing WHERE xcart_
SQL QUERY FAILURE:SELECT xcart_products.*, (SELECT MIN(xcart_pricing.price) FROM xcart_pricing WHERE xcart_pricing.productid=xcart_products.productid AND xcart_pricing.quantity=1 AND xcart_pricing.variantid = 0) AS price FROM xcart_products,xcart_pricing WHERE forsale='Y' AND avail>0 ORDER BY RAND() LIMIT 6

geckoday 04-30-2006 09:14 AM

Quote:

Originally Posted by xcell67

...

but now the cart shows this error:

INVALID SQL: 1064 : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT MIN(xcart_pricing.price) FROM xcart_pricing WHERE xcart_
SQL QUERY FAILURE:SELECT xcart_products.*, (SELECT MIN(xcart_pricing.price) FROM xcart_pricing WHERE xcart_pricing.productid=xcart_products.productid AND xcart_pricing.quantity=1 AND xcart_pricing.variantid = 0) AS price FROM xcart_products,xcart_pricing WHERE forsale='Y' AND avail>0 ORDER BY RAND() LIMIT 6


What version of MySQL are you using? The subquery used requires MySQL 4.1. Also, I found an error in the query that creates duplicate rows. Here's the fixed query also rewritten to work with earlier versions of MYSQL:

Code:

$query = "SELECT $sql_tbl[products].*, MIN($sql_tbl[pricing].price)  AS price FROM $sql_tbl[products],$sql_tbl[pricing] WHERE $sql_tbl[pricing].productid=$sql_tbl[products].productid AND $sql_tbl[pricing].quantity=1 AND $sql_tbl[pricing].variantid = 0 AND forsale='Y' AND avail>0 GROUP BY $sql_tbl[products].productid ORDER BY RAND() LIMIT 6 ";

xcell67 05-04-2006 03:40 PM

thanks gecko, worked like a charm!

xcarter 06-15-2006 06:27 AM

Hi guys,

I was trying out his mod. Had no luck, then immediately reverted back to my backed up files.

Now I've lost my featured products on my home page!!! Even though I've gone back to my original site with featured products on my home page.


I'm having some trouble here trying to rectify this.

Someone please help.


All times are GMT -8. The time now is 03:28 PM.

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