View Single Post
  #1  
Old 02-26-2016, 03:31 PM
 
rob@equivox.com rob@equivox.com is offline
    
Join Date: Jan 2016
Posts: 1
 

Default How to add extra field values to the product list page

Thought I would share this since the older answers do not really work...in XCart 4.7, if you want to have extra fields on the product listing page, you must add the fields to the product loop in products.php...i struggled with this for a few days, but with xcart support's help, i was able to craft this very simple code for my extra fields to show on the product listing page...

In products.php

just before the line

$smarty->assign('cat_products', isset($products) ? $products : array());

add this code and be sure to change the values to match your extra fields...

foreach($products as $c => $v) {
$products[$c]['calories'] = func_query_first_cell("SELECT value FROM $sql_tbl[extra_field_values] WHERE productid='$v[productid]' AND fieldid = '2'");
$products[$c]['protein'] = func_query_first_cell("SELECT value FROM $sql_tbl[extra_field_values] WHERE productid='$v[productid]' AND fieldid = '3'");
$products[$c]['fat'] = func_query_first_cell("SELECT value FROM $sql_tbl[extra_field_values] WHERE productid='$v[productid]' AND fieldid = '5'");
$products[$c]['carbs'] = func_query_first_cell("SELECT value FROM $sql_tbl[extra_field_values] WHERE productid='$v[productid]' AND fieldid = '4'");
}
$smarty->assign('calories', $calories);
$smarty->assign('protein', $protein);
$smarty->assign('fat', $fat);
$smarty->assign('carbs', $carbs);

pay attention to the 'fieldid' in the script...it is at the end of each line and you must figure out which fieldid in the database you want to have the value from...look in the table 'xcart_extra_field_values' and look at the 'fieldid' column and match that to the extra field you are trying to show[/b]

in my example, i have some food stuff...

Calories, Fat, Protein, Carbs...they are all extra fields and i went into the aforementioned tabled and got their 'fieldid's and then i put them into this script...

THEN in products_t.tpl
add these smarty tags wherever you want to show the extra field values...be sure to add these tags inside the {foreach}{/foreach} loop

{$product.calories}
{$product.protein}
{$product.fat}
{$product.carbs}
__________________
rs
Reply With Quote