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)
-   -   Add variable to homepage (https://forum.x-cart.com/showthread.php?t=57333)

Ayla 01-03-2011 11:13 AM

Add variable to homepage
 
I'm totally new to X-Cart but have a great deal of PHP/HTML experience.

I am trying to write some custom code to display products on the homepage (there are very few products in this store) and I have set up the debug window to show includes AND variables... but I don't seem to have access to the $products variable from the homepage.

How can I add the products array variable to the homepage so I can loop through them?

Or rather where can you set which var's are available on each page? (in case there are other pages I need to tweak)

Many thanks!

cflsystems 01-03-2011 01:50 PM

Re: Add variable to homepage
 
In the php file showing the page in question. You have to assign it as smarty variable. To customize xcart you will need not only php but also smarty knowledge - www.smarty.net

In general for your question you can do this

$products = "sql query to get the products array";
$smarty->assign("new_products", $products);

which will give you $new_products array available for that page

Ayla 01-04-2011 08:29 AM

Re: Add variable to homepage
 
Thank you! That is exactly what I was looking for. In reference to the line below, does it just need a SQL query or the returned results from mysql_query()?

Quote:

$products = "sql query to get the products array";

Thanks for your help!

//

cflsystems 01-04-2011 09:48 AM

Re: Add variable to homepage
 
Use the xcart built in functions. For this - func_query(); - will return an array with the results

Ayla 01-04-2011 10:04 AM

Re: Add variable to homepage
 
So to recap (with a demo query) this is all it needs?:

Quote:

$products = func_query("SELECT * FROM `products` ORDER BY `field` ASC");
$smarty->assign("new_products", $products);

cflsystems 01-04-2011 10:08 AM

Re: Add variable to homepage
 
$products = func_query("SELECT * FROM $sql_tbl[products] ORDER BY field ASC");
$smarty->assign("new_products", $products);

Ayla 01-04-2011 10:14 AM

Re: Add variable to homepage
 
Perfect.


All times are GMT -8. The time now is 07:45 AM.

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