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)

Allan Martel 06-10-2005 03:39 PM

Replacing "Featured Products" with "Recommend
 
I have (finally) managed to replace the "Featured Products" with "Recommended Products" on home.php - now 6 products are displayed at random instead of the static "Featured Products"

My next goal would be to make this now display the pricing information and the "Buy Now" button, in 2 rows of 3 products.

I'm pretty sure that this would just be editing the recommends.tpl file.....any help would be appreciated!

Heres what I did:

in skin1/customer/home.tpl, add
Code:

{include file="modules/Recommended_products/recommends.tpl"}
under

Code:

{include file="customer/home_main.tpl"}

In skin1/customer/main/welcome.tpl

remove

Code:

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

and finally, in home.php add:

Code:

if(!empty($active_modules["Recommended_Products"]))
        include "./recommends.php";


under
Code:

if (empty($products))
        include "./featured_products.php";


This was done in 4.0.11

Hope this helps someone!

Allan

balinor 09-02-2005 01:40 PM

Works well, thanks :)

salsabeel 09-23-2005 04:08 PM

Re: Replacing "Featured Products" with "Recom
 
Quote:

Originally Posted by Allan Martel
My next goal would be to make this now display the pricing information and the "Buy Now" button, in 2 rows of 3 products.


Allan,

Were you able to get this to work? Look forward to your reply, thanks!

BoomBoomBap 11-20-2005 04:33 PM

This is a great mod!

A couple notes from my own implementation:

If you only want the above mod to appear on the homepage, use the following code in:
skin1/customer/home.tpl
Code:

{if $main eq "catalog" and $current_category.category eq ""}
{include file="modules/Recommended_products/recommends.tpl"}
{/if}

it seems that otherwise this will also appear on the categories (and perhaps some other) pages.

If you want to limit the number of random items that appear then you will want to use customer recommends.php. Personally, I created recommends_home.php and made the following modification:

open recommends_home.php

Code:

find:
ORDER BY RAND(NOW()+$rnd) LIMIT ".$config["Modules"]["number_of_recommends"]);

replace with:
ORDER BY RAND(NOW()+$rnd) LIMIT 20");

note: this appears twice on the page


NightFire 01-09-2006 06:16 AM

The mod doesn't works for me.
Did exactly what was descriped above. But getting this error:

Code:

Warning: Smarty error: unable to read resource: "modules/Recommended_products/recommends.tpl" in /......./public_html/shop/Smarty-2.6.9/Smarty.class.php on line 1088


Recommends.tpl
Code:

{* $Id: recommends.tpl,v 1.4.2.1 2005/10/31 14:10:44 max Exp $ *}
{if $recommends}
{capture name=recommends}
{section name=num loop=$recommends}
<LI>
<FONT class="ItemsList">{$recommends[num].product}</FONT>
</LI>
{/section}
{/capture}
{include file="dialog.tpl" title=$lng.lbl_recommends content=$smarty.capture.recommends extra="width=100%"}
{/if}


Maree 01-17-2006 10:58 PM

I cant get this working either - same error message as above

BoomBoomBap 01-18-2006 10:18 AM

Try emptying out the recommends.tpl file and just placing some text in there to see if the file is being found. If you get the same error make sure that your file is indeed at this location: modules/Recommended_products/recommends.tpl

Case sensitive!

amy2203 01-19-2006 02:11 AM

I just tried this and got the same error, it is a case-sensitive issue. In my store 3.5.10 the file is

modules/Recommended_Products/recommends.tpl

Note the capital P of Recommended_Products - That it generating the error,

hth

Maree 01-19-2006 03:43 AM

Thanks Amy - that was the problem.

The following notes are for others who are looking at this hack-

I now have recommended products randomly displaying in a 2 column 200 thumbnail format (thanks to Balinors Mod in Completed Mods). I've also added a hack to pull the price up

2 problems with doing all this -recommended products is displaying products that are hidden but available for sale - and the price is not displayed in the nicely formated including GST display that was on featured products.

So the best way I feel is to request xcart to add a checkbox in future releases so that featured products can be dispayed randomy from the whole active product catalogue or a user nominated array.

Hope this helps someone else

webadmin-jj 02-04-2006 07:11 AM

X-Cart Gold 4.01

So I think I might be getting closer to what I'm looking for. So much discussion on this topic, but none of it exactly what I need.

The situation:
-Featured products set to random
-Featured products module display called in the welcome.tpl

Result:
Featured products module boundaries and header show up, but it's empty

1. Why is is empty when I've told X-Cart to randomly select?
2. Once I get it past that point, how would I manually select items for display in featured items?

Thanks.

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.

NightFire 06-15-2006 06:30 AM

Quote:

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


The featured products are shown from the welcome.tpl file
Check if this line is included into your customer/main/welcome.tpl file:

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

xcarter 06-15-2006 06:35 AM

Thanks for replying.
Yes of course it is there. I just check.

Since I reverted back to the original files as were before I attempted the mod, I can't understand why this is happening.

Any other ideas??
Thanks.

fhiremark 06-16-2006 07:40 AM

looks like a nice mod, i'll have to try it. Thanks for the work.

aflores3 06-18-2006 03:50 PM

excellent mod. thank you for sharing your work. i do have one quick question.
any chance of getting this to only show recommended products when the featured products query returns no results?

chamberinternet 07-31-2006 09:42 AM

great mod ... works well in 4.1.2

only one thing that doesnt show is the price. instead it displays "Enter Your Price" ...

After looking into this it's because the 'taxed_price' field isnt passed to the $randoms smarty variable ..

Any ideas on how i can get this field passed ?

Thanks & Regards

Shafiq :sK

geckoday 07-31-2006 12:45 PM

Quote:

Originally Posted by chamberinternet
great mod ... works well in 4.1.2

only one thing that doesnt show is the price. instead it displays "Enter Your Price" ...

After looking into this it's because the 'taxed_price' field isnt passed to the $randoms smarty variable ..

Any ideas on how i can get this field passed ?

Thanks & Regards

Shafiq :sK


See my post earlier in this thread on how to do this.

http://forum.x-cart.com/viewtopic.php?t=20135&postdays=0&postorder=asc&sta rt=13

chamberinternet 07-31-2006 03:06 PM

Opps ... Missed that ..

Thanks for that :)

Regards

Shafiq :sK

chamberinternet 08-01-2006 02:33 AM

Ok ...

i've tried putting the addtional code in just before the smarty assign ..

but now i get a blank page.. :?

the code i have in random.php is as follows:

// 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);

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);
}
}
$smarty->assign("randoms",$randoms);

Can you help ?

Regards

Shafiq :sK

chamberinternet 08-01-2006 03:57 AM

I think i've sorted the issue..

I had to comment the following line:

Quote:

$randoms[$k]["tmbn_url"] = func_get_thumbnail_url($v["productid"]);

The function 'func_get_thumbnail_url' doesnt exist in v4.1.2
(By looking at the /log/x-errors_php-xxxxxx.php file)

The thumbmail still displays and the link to more product details work fine too.

Regards

Shafiq :sK

mffowler 08-01-2006 06:10 PM

This is a beauty in 4.1.2, thanks.

Can anyone get it to be category specific to the current cat. vs. random? The nice thing about this is you can use it for multiple instances. Like a "You Might Also Like..." and a sorta auto-generated cross-selling mod IF it was category specific.

Anyone?

Thanks!

- Mike

chamberinternet 08-01-2006 11:32 PM

Quote:

Originally Posted by mffowler
Can anyone get it to be category specific to the current cat. vs. random? The nice thing about this is you can use it for multiple instances. Like a "You Might Also Like..." and a sorta auto-generated cross-selling mod IF it was category specific.
- Mike


I'm after this feature too ...
Check this post out:
http://forum.x-cart.com/viewtopic.php?t=16081#16081

I'm currently playing with it in v4.1.2

CartMods.com are selling a mod that does this:
http://www.cartmods.com/product.php?productid=110

Sam @ CartMods has confirmed to me that it's compatible with 4.1.x too.

Regards

Shafiq :sK

TL408 09-18-2006 11:40 PM

Re: Replacing "Featured Products" with "Recommend
 
Has anyone try this mod with a store that has several thousand of products? My concern is that it would have a negative performance impact going though long list with thousands of items trying to randomize it......Just a thought.

-Tuan

TL408 09-23-2006 09:39 PM

Re: Replacing "Featured Products" with "Recommend
 
Awesome. I've have tried this mod as of X-cart release 4.1.3 and it work just as described. Now, if someone can point me to the right direction on how to revise the "Recommended Product" codes so that all thumbnails are referenced directly via filesystem instead of "image.php" file. Otherwise the frontpage would take forever to load all these randomized product images.
http://forum.x-cart.com/forumdisplay.php?f=18

Thanks guys.
-Tuan

stevekem 04-30-2007 12:24 AM

Re: Replacing "Featured Products" with "Recommend
 
I tried this mod on 4.1.3, but when the following lines are added below to show pricing, I get a "Fatal error: Call to undefined function: func_get_product_taxes() in /home/path/to/random.php on line 8" error:

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

Anyone know why this is happening?

dub713 06-25-2007 06:20 PM

Re: Replacing "Featured Products" with "Recommend
 
working in 4.1.7! great little mod.

dub713 07-11-2007 10:41 PM

Re: Replacing "Featured Products" with "Recommend
 
anyone have the answer to this...


i'm using this for 4 different random products on the main page... the problem is, duplicates. we've seen 2 of the same before, but i actually just saw 4 (yes, all four) random products, as the same item. if i could figure it out, i'd code it, but i can't. anyone have a solution to this??

thanks,
j


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.