X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Extra Fields 4.1.x products_t.tpl (https://forum.x-cart.com/showthread.php?t=25143)

Cpt.Crashtastic 09-21-2006 12:47 PM

Extra Fields 4.1.x products_t.tpl
 
I sacrificed 25 points for the soloution as I couldn't get there myself. Thanks to the Xcart Team

By default, the extra field values are not assignd to the Smarty template engine on the products page (they are shown only on the product details page). In order to achieve such a functionality, the following modification to the 'products.php' file is required:

insert the next code
Code:

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, $sql_tbl[extra_fields].service_name as service_name 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_fields].active='Y' AND $sql_tbl[extra_field_values].productid = '$v[productid]'");
}
}


just before the following line:

$smarty->assign("products",$products);


Then extra fields will be assigned to the '/skin1/customer/main/products_t.tpl' Smarty template and you'll be able to operate with the values. For example, you may show all extra fields for the product if you insert the following code (into the '/skin1/customer/main/products_t.tpl' template)

{foreach from=$products[product].extra_fields item="ef"}
{if $ef.value ne ''}
<br>{$ef.field}: {$ef.value}
{/if}
{/foreach}


before the next one:

{if $active_modules.Feature_Comparison ne '' && $products[product].fclassid > 0}


If you need to display only certain extra field which has the 'minPrice' service name, then you are supposed to use the next code:

{foreach from=$products[product].extra_fields item="ef"}
{if $ef.value ne '' && $ef.service_name eq 'minPrice'}
<br>{$ef.field}: {$ef.value}
{/if}
{/foreach}

Hope that helps

balinor 09-21-2006 12:58 PM

Re: Extra Fields 4.1.x products_t.tpl
 
Funny...there must be 500 posts asking for this functionality in 4.1 and it looks like it still isn't there by default :(

HEK 10-30-2006 03:04 PM

Re: Extra Fields 4.1.x products_t.tpl
 
nn... it doesnt work...why??
I'm now using 4.1.3

KeeYoung Hartley 01-11-2007 11:49 AM

Re: Extra Fields 4.1.x products_t.tpl
 
I added the code

Code:

{foreach from=$products[product].extra_fields item="ef"}
{if $ef.value ne ''}
<br>{$ef.field}: {$ef.value}
{/if}
{/foreach}


into '/skin1/customer/main/products.tpl' instead of products_t.tpl and it works.

Thank you!

bradjd 01-26-2007 11:24 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Quick Comment:

Using the above mod you can also use the following to output a specified output

for values:
{$products[product].extra_fields[0].value}

for field titles:
{$products[product].extra_fields[0].field}

this is slightly different than the syntax for the product page variables

-Thanks for the contribution Cpt, saved me lots of time

jhoyssa 01-29-2007 04:43 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Hi

Thanks for the post, this helped me to clear out the system a bit, but there's still something that I can't get to work.

Since I didn't have any service_name-column in the database (what's with that?) and I needed to check out the value regardless to the activity, I modified the lines suggested in the original post a bit and put them into my products.php:

Code:

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]'");
}
}
$smarty->assign("products",$products);


This thing works like a charm on the customer/main/products.tpl and I can simply refer to the variable I need by using $products[product].extra_fields[8].value. Anyhow, I'd need the same information on the featured products-lists, but for some reason(s) all the extra fields are not to be used in customer/main/products_t.tpl, although the original posting suggests just that.

By putting the line
Code:

{$products[product].extra_fields|@debug_print_var
in the products_t.tpl it tells that the array is empty.

Trying everything, I gave
Code:

{$extra_fields|@debug_print_var}
a shot too, but it shows only three extra fields and their contents, but there are actually nine (and I'd need the last one of course :)). Is there a LIMIT somewhere or what does this mean?

Did I mess up something when I modified the query-part in the products.php? Or should it be assigned also somewhere else to work in the products_t.tpl? The featured products list is used in multicolumn format.

carlisleglass 06-12-2007 01:41 AM

Re: Extra Fields 4.1.x products_t.tpl
 
remove the following from the statement

AND $sql_tbl[extra_fields].active='Y'

and it will pick up all your extra fields not just the active ones (in other words the ones with the show box ticked).

You can also put the same statement in your featured_products.php so that extra fields are available to them as well.

UPDATE: add again the same coding into include/search.php just above $smarty->assign("products",$products); and you will have extra fields in your search results also.

vtonya 06-12-2007 10:57 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Carlisleglass, thanks, but i didn't understand.
Can you please write in advance what code should i add to the search.php or to some other files so it'll have extra fields in my search results also

spwestwood 09-21-2007 07:21 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Where does the code need to be placed if you want an extra field in one of the emails (skin1/mail/html/drop_shipper_email.tpl)?

I have the following code to put in the email template:
{if $products[product].extra_fields ne ''}
{foreach from=$products[product].extra_fields item=extra_field}
{if $extra_field.service_name eq "Kit Contents"}
{$extra_field.field}: {$extra_field.value}
{/if}
{/foreach}
{/if}

But I need to know where to place the code to assign the extra fields to the Smart template engine.
I hava already added an extra field to the cart by adding the code in "include/func/func.cart.php". What is the similar for email?

Thanks, Sam

7thdesire 02-05-2008 04:00 PM

Re: Extra Fields 4.1.x products_t.tpl
 
has anyone got this to work on

4.1.9 in products_t.tpl

davidsaldana 03-16-2008 01:50 PM

Re: Extra Fields 4.1.x products_t.tpl
 
I got this to work in 4.1.9. The only problem is that you are not able to set the order. Its not using the service name nor the order by function. It must just be pulling the info straight from the database in the order it was added. Really need a way to fix this. Anyone have any ideas?

Also, need a way to not show some extra fields. Tried to hardcode, but couldnt get it to work.

-DS

Duramax 6.6L 03-16-2008 03:20 PM

Re: Extra Fields 4.1.x products_t.tpl
 
When you set up the extra fields, you can select the position of the extra field.

If you number them the way you want, they should show up in that order.

davidsaldana 03-16-2008 03:45 PM

Re: Extra Fields 4.1.x products_t.tpl
 
Quote:

Originally Posted by Duramax 6.6L
When you set up the extra fields, you can select the position of the extra field.

If you number them the way you want, they should show up in that order.


This is true, for the product pages, but not for this mod. they are showing up in the order they were entered into the database.

-ds

toltion 06-14-2008 03:03 PM

Re: Extra Fields 4.1.x products_t.tpl
 
Just add "ORDER BY $sql_tbl[extra_fields].orderby")" to the end of the SQL query in products.php to use the sort order -

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, $sql_tbl[extra_fields].service_name as service_name, $sql_tbl[extra_fields].active as active 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]' ORDER BY $sql_tbl[extra_fields].orderby");
}
}

I also added "$sql_tbl[extra_fields].active as active FROM $sql_tbl[extra_fields]," so I can still specify to show the field value if it's active right on the .tpl.

TanyaG 07-17-2008 06:34 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Can I use this code for product.tpl (4.1.9)?
Many thanks,

toltion 07-17-2008 07:28 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Product.tpl is already set up to show extra fields, the code is meant for other templates that show products but don't show extra fields (by default).

And the code does work for 4.1.9.

Tony

TanyaG 07-17-2008 07:36 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Thank you very much Tony. I▓ve placed the code to product.php and product.tpl and all I▓ve got is:
1 : 1
Any ideas what I▓ve done wrong?
Many thanks,

qrichou 07-25-2008 09:42 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Hi,

I need to get this working in the cart i have added :

#
# Get products Extra field data
#
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, $sql_tbl[extra_fields].service_name as service_name 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_fields].active='Y' AND $sql_tbl[extra_field_values].productid = '$v[productid]'");
}
}
$smarty->assign("products",$products);

to the cart.php and tried it in the include/cart_procsess.php but it does not show up in the view cart, anyone have any ideas?

Also added {$products[product].extra_fields[1].field}{$products[product].extra_fields[1].value} to the cart.tpl

Many Thanks

ChristineP 01-26-2009 08:14 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Am I understanding that X-Cart included the above code to product.tpl for extra fields? Without adding the above mod, I've tried calling out an extra field in my product.tpl as {$product.extra_fields.6.value}, but it doesn't work. Do you have a suggestion?

Quote:

Originally Posted by toltion
Product.tpl is already set up to show extra fields, the code is meant for other templates that show products but don't show extra fields (by default).

And the code does work for 4.1.9.

Tony


toltion 01-26-2009 08:23 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Hi Christine,

You need to LOOP through the Extra fields and display the one using an {if} statement -

Code:

        {section name=field loop=$extra_fields}
        {if $extra_fields[6].value ne ""}
        {$extra_fields[6].value}
        {/if}
        {/section}


ChristineP 02-24-2009 06:35 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Hi toltion,

How does this work for multiple extra fields on the product.tpl page?


Quote:

Originally Posted by toltion
Hi Christine,

You need to LOOP through the Extra fields and display the one using an {if} statement -

Code:

        {section name=field loop=$extra_fields}
        {if $extra_fields[6].value ne ""}
        {$extra_fields[6].value}
        {/if}
        {/section}



toltion 02-24-2009 07:06 AM

Re: Extra Fields 4.1.x products_t.tpl
 
The code allows you to selectively display any extra field. I sometimes like to display the extra fields in different locations on the template, so I run the code at the top of the page and assign variables to the values. In this code I chose to identify the extra_fields by their Service Name instead of index position in the loop -
Code:

{section name=field loop=$extra_fields}
{if $extra_fields[field].service_name eq "NO_SHIP_AIR"}
    {if $extra_fields[field].field_value ne ""}{assign var="no_ship_air" value="Y"}{/if}
{/if}
{if $extra_fields[field].service_name eq "CLEARANCE_PRICE"}
    {if $extra_fields[field].field_value ne ""}{assign var="clearance_price" value="Y"}{/if}
{/if}
{/section}


Then I can display the variables "no_ship_air" & "clearance_price" anywhere on the page using {if $no_ship_air ne ""}{$no_ship_air}{/if}.

ChristineP 02-24-2009 08:54 AM

Re: Extra Fields 4.1.x products_t.tpl
 
With your suggested code, I believe I have the "loop through" working in /modules/Extra_Fields/product.tpl, though I haven't been able to place each of my extra fields separately in customer/main/product.tpl.

This is what I have for my product.tpl
{if $active_modules.Extra_Fields ne ""}
{include file="modules/Extra_Fields/product.tpl"}

When I tried adding just one field name, there was no change
{if $active_modules.Extra_Fields ne ""}{$product.extra_fields.11.value}
{include file="modules/Extra_Fields/product.tpl"}

Can you see what I'm missing to call out individual extra fields where I need in my customer/main/product.tpl?

Christine

Quote:

Originally Posted by toltion
The code allows you to selectively display any extra field. I sometimes like to display the extra fields in different locations on the template, so I run the code at the top of the page and assign variables to the values. In this code I chose to identify the extra_fields by their Service Name instead of index position in the loop -
Code:

{section name=field loop=$extra_fields}
{if $extra_fields[field].service_name eq "NO_SHIP_AIR"}
    {if $extra_fields[field].field_value ne ""}{assign var="no_ship_air" value="Y"}{/if}
{/if}
{if $extra_fields[field].service_name eq "CLEARANCE_PRICE"}
    {if $extra_fields[field].field_value ne ""}{assign var="clearance_price" value="Y"}{/if}
{/if}
{/section}


Then I can display the variables "no_ship_air" & "clearance_price" anywhere on the page using {if $no_ship_air ne ""}{$no_ship_air}{/if}.


toltion 02-24-2009 10:20 AM

Re: Extra Fields 4.1.x products_t.tpl
 
In customer/main/product.tpl, you have to replace -

{include file="modules/Extra_Fields/product.tpl"}

With the code I suggested.

You are basically looping through the extra fields directly on product.tpl instead of including "modules/Extra_Fields/product.tpl".

ChristineP 02-24-2009 11:12 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Awesome! I have one more piece to this that I need working. I have a custom button that I'm trying to get working for 3 of my extra fields. Here's what I've done with trying to add my custom button .tpl:

In customer/main/product.tpl I commented out
<!--{if $active_modules.Extra_Fields ne ""}
{include file="modules/Extra_Fields/product.tpl"}
{/if}-->

and added from your code suggestion
<table align="left" cellspacing="0" cellpadding="0">
{section name=field loop=$extra_fields}
<td>{if $extra_fields[field].service_name eq "products_PDF"}
{include file="buttons/pdf_button.tpl" href="javascript:window.open $extra_fields[field].field_value=products_PDF" style="button"}
{/if}</td>
<td>&nbsp;&nbsp;</td>
<td>{if $extra_fields[field].service_name eq "products_manual"}
{$extra_fields[field].field_value eq "products_manual"}
{/if}</td>
<td>&nbsp;&nbsp;</td>
<td>{if $extra_fields[field].service_name eq "product_image"}
{$extra_fields[field].field_value eq "product_image"}
{/if}</td>
{/section}
</table>

The bold is my attempt for my custom button. The image of my custom button is now showing, though it's not clickable to my product.

Do you have any suggestions?

Christine

Quote:

Originally Posted by toltion
In customer/main/product.tpl, you have to replace -

{include file="modules/Extra_Fields/product.tpl"}

With the code I suggested.

You are basically looping through the extra fields directly on product.tpl instead of including "modules/Extra_Fields/product.tpl".


toltion 02-24-2009 12:49 PM

Re: Extra Fields 4.1.x products_t.tpl
 
Try this...

<table align="left" cellspacing="0" cellpadding="0">
{section name=field loop=$extra_fields}
<td>{if $extra_fields[field].service_name eq "products_PDF"}
{include file="buttons/pdf_button.tpl" href="javascript:window.open $extra_fields[field].field_value" style="button"}
{/if}</td>
<td>&nbsp;&nbsp;</td>
<td>{if $extra_fields[field].service_name eq "products_manual"}
{$extra_fields[field].field_value}
{/if}</td>
<td>&nbsp;&nbsp;</td>
<td>{if $extra_fields[field].service_name eq "product_image"}
{$extra_fields[field].field_value}
{/if}</td>
{/section}
</table>

Not too sure about your javascript window.open code. Doesn't look like that will work...

ChristineP 02-24-2009 01:09 PM

Re: Extra Fields 4.1.x products_t.tpl
 
Great job. Thanks for your help! I have the loop through working.

For my custom button, I will need to get mod work done.

Christine

chastie 03-29-2009 03:34 PM

Re: Extra Fields 4.1.x products_t.tpl
 
Thank you thank you!

Hallsons 05-30-2009 06:50 PM

Re: Extra Fields 4.1.x products_t.tpl
 
Hi,

I can't find where to insert the code in 4.1.11 as I can't find the $smarty->assign line mentioned.

Where should I insert this to call up the extra fields?

Thanks,

Chris

gb2world 05-30-2009 09:08 PM

Re: Extra Fields 4.1.x products_t.tpl
 
Are you modifying products.php? It should be near the last lines of the file. The php code goes in the products.php file, the smarty and html changes go in the template files.

Hallsons 05-31-2009 06:50 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Thanks, I didn't read that first post correctly. I've edited products.php but still don't quite understand what and where to put the rest of the code for this mod for the extra fields to show up in in the products template. I've tried and still, nothing is showing up.

Time to just quit, but thanks for your help.

Monkeyhead 06-25-2009 01:04 AM

Re: Extra Fields 4.1.x products_t.tpl
 
I'm looking at displaying some extra fields on the search display page.

Will this mod work on 4.1.12?

cherie 06-26-2009 10:06 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Unless I'm missing something I'm pretty sure this mod is not necessary with 4.1:

http://forum.x-cart.com/showthread.php?p=118321#post118321

(there are some typos in the example)

Learner 07-14-2009 03:15 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Is it possible to import from 3x-4x import?what are the fields?

telimon 07-22-2009 08:52 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Can anyone tell me if there is a patch after 4.1.8 that makes adding a field to the products_t.tpl easier, or do i still need to follow the instructions for a change from this thread?

Thanks!!!!! in advance

cherie 07-23-2009 08:27 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Quote:

Originally Posted by telimon
Can anyone tell me if there is a patch after 4.1.8 that makes adding a field to the products_t.tpl easier, or do i still need to follow the instructions for a change from this thread?

Thanks!!!!! in advance

I still think it's pretty easy.

mrerotic 08-12-2009 06:12 PM

Re: Extra Fields 4.1.x products_t.tpl
 
This isnt working on 4.2.1 any ideas how to make this work?

Learner 08-13-2009 11:16 PM

Re: Extra Fields 4.1.x products_t.tpl
 
Cherry Is it possible to import from 3x-4x import?what are the fields?

cherie 08-14-2009 06:10 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Quote:

Originally Posted by Learner
Cherry Is it possible to import from 3x-4x import?what are the fields?


Yep! It's called "Extra Fields." You should see the fields when you create the export. In 4.1 you can enable the module called "Import 3x-4x". You can then see that at the top when you go to Import/Export.

Learner 08-15-2009 05:02 AM

Re: Extra Fields 4.1.x products_t.tpl
 
Cherry I have made two extra fields 1)Pack Size 2)Attribute .How Can I import these from 3x-4x import? What are the field value name?

Can you help me?


All times are GMT -8. The time now is 08:18 PM.

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