Extra Fields on Products.tpl
I have seen a lot of posts about adding extra fields to various things, but I haven't been able to get what I found to work like I want it to.
I need to show on products.tpl, in a table, the extra fields that have a value.
This is the code I added to products.php:
if (!empty($active_modules["Extra_Fields"]) && !empty($products)) {
foreach($products as $k => $v) {
$products[$k]["extra_fields"] = func_query("SELECT $sql_tbl[extra_fields].field as field, $sql_tbl[extra_field_values].value as value FROM $sql_tbl[extra_fields], $sql_tbl[extra_field_values] WHERE $sql_tbl[extra_field_values].fieldid = $sql_tbl[extra_fields].fieldid AND $sql_tbl[extra_field_values].productid = '$v[productid]'");
}
}
And this is my products.tpl
{if $products}
<TABLE border=0 width=100% cellspacing="0">
<TR>
<TD align=center class="top_products">Product</TD>
{section name=field loop=$products[prod_num].extra_fields}
{if $products[prod_num].extra_fields[field].field_value}
<TD class="top_products">
{$products[prod_num].extra_fields[field].field}
</TD>
{/if}
{/section}
<TD align=center class="top_products">{$lng.lbl_price}</TD>
</TR>
{section name=product loop=$products}
<TR {cycle values="class='tr_products1', class='tr_products2'"}>
<TD align=left><A href="product.php?productid={$products[product].productid}">{$products[product].product}</A></TD>
{section name=field loop=$products[prod_num].extra_fields}
{if $products[prod_num].extra_fields[field].field_value}
<TD>
{$products[prod_num].extra_fields[field].field_value}
</TD>
{/if}
{/section}
<TD align=center><b><A href="product.php?productid={$products[product].productid}">{include file="currency.tpl" value=$products[product].taxed_price}</A></b></TD>
</TR>
{/section}
</TABLE>
{else}
{$lng.txt_no_products_found}
{/if}
Can anyone point me to the right topic, or help me to get this working? I get the extra fields to show when I call them individually but that won't work because the table will be to big, I just need to show the ones that have a value.
Thanks
|