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

Extra Fields on Products.tpl

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 10-14-2007, 11:13 PM
  DrQuietus's Avatar 
DrQuietus DrQuietus is offline
 

Advanced Member
  
Join Date: Dec 2005
Posts: 81
 

Default 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
__________________
Dave Jones
dave@industrialwebworks.net
Mostly 4.7.2 - 4.7.5
Reply With Quote
  #2  
Old 10-15-2007, 08:09 AM
  DrQuietus's Avatar 
DrQuietus DrQuietus is offline
 

Advanced Member
  
Join Date: Dec 2005
Posts: 81
 

Default Re: Extra Fields on Products.tpl

no help here? someone, anyone?
__________________
Dave Jones
dave@industrialwebworks.net
Mostly 4.7.2 - 4.7.5
Reply With Quote
  #3  
Old 10-27-2007, 05:41 AM
  DrQuietus's Avatar 
DrQuietus DrQuietus is offline
 

Advanced Member
  
Join Date: Dec 2005
Posts: 81
 

Default 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?
__________________
Dave Jones
dave@industrialwebworks.net
Mostly 4.7.2 - 4.7.5
Reply With Quote
  #4  
Old 10-27-2007, 07:42 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default Re: Extra Fields on Products.tpl

I assume you have been through this:

http://forum.x-cart.com/showthread.php?t=9540
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #5  
Old 10-27-2007, 09:02 AM
  DrQuietus's Avatar 
DrQuietus DrQuietus is offline
 

Advanced Member
  
Join Date: Dec 2005
Posts: 81
 

Default 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?
__________________
Dave Jones
dave@industrialwebworks.net
Mostly 4.7.2 - 4.7.5
Reply With Quote
  #6  
Old 06-18-2008, 10:59 PM
  DrQuietus's Avatar 
DrQuietus DrQuietus is offline
 

Advanced Member
  
Join Date: Dec 2005
Posts: 81
 

Default 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>
__________________
Dave Jones
dave@industrialwebworks.net
Mostly 4.7.2 - 4.7.5
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 10:59 AM.

   

 
X-Cart forums © 2001-2020