Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Replacing "Featured Products" with "Recommend
 
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features
 
Thread Tools Search this Thread
  #11  
Old 02-05-2006, 10:24 AM
 
dundeemedia dundeemedia is offline
 

Advanced Member
  
Join Date: Oct 2005
Posts: 31
 

Default

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!
__________________
4.0.16 [linux]
http://www.petpassions.co.uk - pet products [live!]

X-Cart Product Uploader Rough Demo Available
http://www.dundeemedia.com/software/dmshopuploader.exe
Reply With Quote
  #12  
Old 04-16-2006, 10:31 AM
 
xcell67 xcell67 is offline
 

Senior Member
  
Join Date: Dec 2003
Posts: 149
 

Default

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"}



Reply With Quote
  #13  
Old 04-16-2006, 09:34 PM
 
xcell67 xcell67 is offline
 

Senior Member
  
Join Date: Dec 2003
Posts: 149
 

Default

damnit, the query will sometimes show a product twice Anyone know how to modify the query so that it will only select an item once?
Reply With Quote
  #14  
Old 04-17-2006, 06:11 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default

Quote:
Originally Posted by xcell67
damnit, the query will sometimes show a product twice 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); } }
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
  #15  
Old 04-19-2006, 11:25 PM
 
xcell67 xcell67 is offline
 

Senior Member
  
Join Date: Dec 2003
Posts: 149
 

Default

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); ?>
Reply With Quote
  #16  
Old 04-20-2006, 05:34 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default

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 ";
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
  #17  
Old 04-30-2006, 03:08 AM
 
xcell67 xcell67 is offline
 

Senior Member
  
Join Date: Dec 2003
Posts: 149
 

Default

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
Reply With Quote
  #18  
Old 04-30-2006, 09:14 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default

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 ";
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
  #19  
Old 05-04-2006, 03:40 PM
 
xcell67 xcell67 is offline
 

Senior Member
  
Join Date: Dec 2003
Posts: 149
 

Default

thanks gecko, worked like a charm!
Reply With Quote
  #20  
Old 06-15-2006, 06:27 AM
 
xcarter xcarter is offline
 

Senior Member
  
Join Date: Sep 2005
Posts: 146
 

Default

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.
__________________
Version 4.1.9
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 05:45 PM.

   

 
X-Cart forums © 2001-2018