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

Add variable to homepage

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 01-03-2011, 11:13 AM
 
Ayla Ayla is offline
 

Newbie
  
Join Date: Jan 2011
Posts: 9
 

Question 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!
__________________
// Ayla

X-Cart 4.4.1
Reply With Quote
  #2  
Old 01-03-2011, 01:50 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,201
 

Default 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
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #3  
Old 01-04-2011, 08:29 AM
 
Ayla Ayla is offline
 

Newbie
  
Join Date: Jan 2011
Posts: 9
 

Thumbs up 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!

//
__________________
// Ayla

X-Cart 4.4.1
Reply With Quote
  #4  
Old 01-04-2011, 09:48 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,201
 

Default Re: Add variable to homepage

Use the xcart built in functions. For this - func_query(); - will return an array with the results
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #5  
Old 01-04-2011, 10:04 AM
 
Ayla Ayla is offline
 

Newbie
  
Join Date: Jan 2011
Posts: 9
 

Default 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);
__________________
// Ayla

X-Cart 4.4.1
Reply With Quote
  #6  
Old 01-04-2011, 10:08 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,201
 

Default Re: Add variable to homepage

$products = func_query("SELECT * FROM $sql_tbl[products] ORDER BY field ASC");
$smarty->assign("new_products", $products);
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #7  
Old 01-04-2011, 10:14 AM
 
Ayla Ayla is offline
 

Newbie
  
Join Date: Jan 2011
Posts: 9
 

Default Re: Add variable to homepage

Perfect.
__________________
// Ayla

X-Cart 4.4.1
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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 07:17 PM.

   

 
X-Cart forums © 2001-2020