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)
-   -   Extra Fields on Products.tpl (https://forum.x-cart.com/showthread.php?t=34611)

DrQuietus 10-14-2007 11:13 PM

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

DrQuietus 10-15-2007 08:09 AM

Re: Extra Fields on Products.tpl
 
no help here? someone, anyone?

DrQuietus 10-27-2007 05:41 AM

Re: Extra Fields on Products.tpl
 
Nobody wants to help me with this? at least to tell me where I can find the answer? Pretty please with sugar on top?

balinor 10-27-2007 07:42 AM

Re: Extra Fields on Products.tpl
 
I assume you have been through this:

http://forum.x-cart.com/showthread.php?t=9540

DrQuietus 10-27-2007 09:02 AM

Re: Extra Fields on Products.tpl
 
Yes I went through that post. The extra fields are showing up fine when I call them individually, but there is something wrong with my loop or my if the extra field has a value then show it statement (don't know how to explain that better sorry). I can go through the whole process of calling individual extra fields for the certain types of products in each category, but this seems like a horrible waste of time. I just want to call the extra fields that have a value and show those, so the table is changing by itself for every category. The code as it is, does not show any extra fields. Is there something wrong with it that you can see? Like changing the {section name=field loop=$products[prod_num].extra_fields} to a foreach or something?

DrQuietus 06-18-2008 10:59 PM

Re: Extra Fields on Products.tpl
 
Six months later...I had another site to make, this one I could not get away with hard coding the extra fields and I found the solution.

In products.tpl I finally made a table that outputs a <th> with the extra field names, and <td> with the extra field values, and excludes the extra fields without a value. This only works if all the products in the current category have the same extra fields, which was the case with this project. Combined with the bcse buy now mod, this makes for a fast and easy way for customers to order a bunch of products.

Code:

<table width="100%" cellpadding="2" cellspacing="0" class="productlisttable">
<tr>
    <th>Part #</th>

{section name=product loop=$products}
{if $smarty.section.product.first}
{foreach from=$products[product].extra_fields item=extra_field name=field}
   
    {if $extra_field.value ne  ''}
    <th>{$extra_field.field}</th>
    {/if}

{/foreach}
{/if}
{/section}

    <th>{$lng.lbl_price}</th>
    <th>Place Your Order</th>
</tr>

{section name=product loop=$products}
<tr {cycle values="class='odd', class='even'"}>

<td>
{$products[product].productcode}
</td>

{if $products[product].extra_fields ne ''}
{foreach from=$products[product].extra_fields item=extra_field}

{if $extra_field.value ne  ''}
<td>{$extra_field.value}</td>
{/if}

{/foreach}
{/if}


<td>
{include file="currency.tpl" value=$products[product].taxed_price}
</td>

<td class="purchasingbutton">

{if $usertype eq "C" and $config.Appearance.buynow_button_enabled eq "Y"}
{include file="customer/main/bcse_buy_now.tpl" product=$products[product] format_mode="list"}
{/if}

</td>

</tr>

{/section}
</table>



All times are GMT -8. The time now is 02:41 PM.

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