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

Extra Field to show on Email receipt only

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #11  
Old 03-25-2005, 12:26 PM
  rubberneck's Avatar 
rubberneck rubberneck is offline
 

Senior Member
  
Join Date: Feb 2003
Posts: 161
 

Default ?

Ok, when I use that code, I get an error complaining about the {/if}. Don't I need an openning {if} of some sort?

Is there any reason it should matter which file I'm putting this in? Like if I put it in order_data.tpl, versus an email.tpl?

Thanks so much for all of your help.
__________________
--
Version 4.0.17 Gold
Version 4.1 Gold
Version 4.4 Gold
Reply With Quote
  #12  
Old 03-25-2005, 10:15 PM
 
dsparks dsparks is offline
 

Advanced Member
  
Join Date: Nov 2002
Posts: 34
 

Default

Well, this one was fun...

It seems that the extra field information is not saved with the order data when an order is placed or generated when the order is read back from the database.

What I did was just pull the extra field information when the order is regenerated for display.

A real fix would be to store the extra field data along with the order when it is saved in case the extra field data is changed at a later date.

Oh well, maybe next time.



To change this you will need to do the following:


1) Enable the Extra Fields module under the Administration area, Modules section.

2) Create your extra fields under the Products area, Extra Fields section

3) Then pick a product you want to test with and add some extra field data to it, and save it.

4) Change the file /include/func.php around line 2601 in function func_order_data, right after the code:


Code:
foreach ($products as $k=>$v) {

add the following additional code:

Code:
if ($active_modules["Extra_Fields"]) { $productid = $v["productid"]; $extra_fields = func_query("SELECT $sql_tbl[extra_fields].*, $sql_tbl[extra_field_values].value as field_value, IF($sql_tbl[extra_field_values].fieldid > 0, 'Y', '') as is_value FROM $sql_tbl[extra_fields] LEFT JOIN $sql_tbl[extra_field_values] ON $sql_tbl[extra_fields].fieldid = $sql_tbl[extra_field_values].fieldid AND $sql_tbl[extra_field_values].productid = '$productid' ORDER BY $sql_tbl[extra_fields].fieldid"); } else $extra_fields = array(); $v["extra_fields"] = $extra_fields;


5) then, change the file /skin1/main/order_info.tpl around line 68 to see the extra field data on screen order displays:

after the code:
Code:
<TR> <TD valign="top">{$lng.lbl_quantity}</TD> <TD valign="top">{$products[prod_num].amount} item(s)</TD> </TR>

add this code:

Code:
{if $active_modules.Extra_Fields ne ""} {section name=field loop=$products[prod_num].extra_fields} {if $products[prod_num].extra_fields[field].field_value} <TR><TD> {$products[prod_num].extra_fields[field].field} </TD><TD> {$products[prod_num].extra_fields[field].field_value} </TD></TR> {/if} {/section} {/if}

6) then, change the file /skin1/mail/order_data.tpl around line 23, look for the code:

Code:
{/section}

which is the end section for the code section {section name=prod_num loop=$products}

and insert the following code right above it:

Code:
{if $active_modules.Extra_Fields ne ""} {section name=field loop=$products[prod_num].extra_fields} {if $products[prod_num].extra_fields[field].field_value} {$products[prod_num].extra_fields[field].field}: {$products[prod_num].extra_fields[field].field_value} {/if} {/section} {/if}


7) Find an order or create a new order that has the product with the extra field on it and is should now display the new extra field data.

I did not include an example on how to modify the html version of the invoice, but you should be able to take the code above and insert it into that file and make it work.

Also, there is no checking to see whether the SHOW flag in the extra fields maintenance is on or off, but you can add or leave that out where needed.


Hope this works for you....
__________________
X-Cart Gold: v4.0.17
Reply With Quote
  #13  
Old 03-27-2005, 09:24 PM
  rubberneck's Avatar 
rubberneck rubberneck is offline
 

Senior Member
  
Join Date: Feb 2003
Posts: 161
 

Default hot damn!

That's fantastic, thanks so much. I hadn't imagined that it would be so complex.

Don't want to push my luck, but I have 2 more related questions:

1. how can I allow HTML in the extra fields? it appears to parse it out by default

2. how can I change the extra fields to a text box, instead of a single line field? I found the tpl file to edit in /modules/extra_fields, but when I change it, it does not show the existing text when I save or go back in to modify. It appears to be saving ok, just not refilling the form field

Thanks again!
__________________
--
Version 4.0.17 Gold
Version 4.1 Gold
Version 4.4 Gold
Reply With Quote
  #14  
Old 03-27-2005, 09:33 PM
  rubberneck's Avatar 
rubberneck rubberneck is offline
 

Senior Member
  
Join Date: Feb 2003
Posts: 161
 

Default oops

Spoke too soon. I found the answer to question number one here:

http://forum.x-cart.com/viewtopic.php?t=13801&highlight=extra+field+html


Question two remains.

I have

Quote:
{section name=field loop=$extra_fields}
<TR>
{if $productids ne ''}<TD width="15" class="TableSubHead"><INPUT type="checkbox" value="Y" name="fields[efields][{$extra_fields[field].fieldid}]"></TD>{/if}
<TD class="FormButton" nowrap>{$extra_fields[field].field}</TD>
<TD>
<textarea type="text" cols="50" rows="4" name="efields[{$extra_fields[field].fieldid}]" value="{if $extra_fields[field].is_value eq 'Y'}{$extra_fields[field].field_value|escape:"html"}{else}{$extra_fields[field].value|escape:"html"}{/if}"></textarea></TD>
</TR>
{/section}

I know it's something dumb, but just can't figure it out. Something with 'value' I assume.
__________________
--
Version 4.0.17 Gold
Version 4.1 Gold
Version 4.4 Gold
Reply With Quote
  #15  
Old 03-27-2005, 10:48 PM
  rubberneck's Avatar 
rubberneck rubberneck is offline
 

Senior Member
  
Join Date: Feb 2003
Posts: 161
 

Default finally

duh!

Stupid HTML mistake. Posting answer for future people. thanks to the two who helped!

Quote:
{section name=field loop=$extra_fields}
<TR>
{if $productids ne ''}<TD width="15" class="TableSubHead"><INPUT type="checkbox" value="Y" name="fields[efields][{$extra_fields[field].fieldid}]"></TD>{/if}
<TD class="FormButton" nowrap>{$extra_fields[field].field}</TD>
<TD>
<textarea type="text" cols="50" rows="4" name="efields[{$extra_fields[field].fieldid}]">{if $extra_fields[field].is_value eq 'Y'}{$extra_fields[field].field_value|escape:"html"}{else}{$extra_fields[field].value|escape:"html"}{/if}</textarea></TD>
</TR>
{/section}

__________________
--
Version 4.0.17 Gold
Version 4.1 Gold
Version 4.4 Gold
Reply With Quote
  #16  
Old 03-28-2005, 04:40 AM
 
balinor balinor is offline
 

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

Default

Moving this to the Custom Mods forum.
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #17  
Old 04-10-2005, 11:54 AM
 
shwekhaw shwekhaw is offline
 

Senior Member
  
Join Date: Nov 2004
Posts: 148
 

Default

Hi dsparks:
It is a great mod you posted. But saving extra fields at the time of creating order does not work for me. I need to read the "realtime" extra field value at the time I print out invoice from order detail page. Could you please let me know if you know how to do it? I spent several hours and cannot get it working.

Here is what I did:
Copy and paste the following code from module/Extra_Fields/extra_fields.php into admin/order.php
Code:
$provider_condition = ($single_mode?"":" AND $sql_tbl[extra_fields].provider='$extra_fields_provider' "); if($productid) { $extra_fields = func_query("SELECT $sql_tbl[extra_fields].*, $sql_tbl[extra_field_values].value as field_value, IF($sql_tbl[extra_field_values].fieldid > 0, 'Y', '') as is_value FROM $sql_tbl[extra_fields] LEFT JOIN $sql_tbl[extra_field_values] ON $sql_tbl[extra_fields].fieldid = $sql_tbl[extra_field_values].fieldid AND $sql_tbl[extra_field_values].productid = '$productid' WHERE 1 $provider_condition ORDER BY $sql_tbl[extra_fields].fieldid"); } else { $extra_fields = func_query("SELECT $sql_tbl[extra_fields].* FROM $sql_tbl[extra_fields] WHERE 1 $provider_condition ORDER BY $sql_tbl[extra_fields].fieldid"); } $smarty->assign("extra_fields",$extra_fields);

Then somewhere insde /mail/html/order_invoice.tpl, I paste following code from skin1/modules/Extra_Fields/product.tpl


Code:
{section name=field loop=$extra_fields} {if $extra_fields[field].field eq "Cost"} {$extra_fields[field].field}: {$extra_field[field].field_value} {/if} {/section }

But when I print out, it shows
Cost:
No field value is not printed. I try using $product.extra_fields instead of $extra_fields and nothing prints out.
I am newbie to x-cart still learning how to cut and paste codes. If you can please help me out with this.
__________________
X-Cart Gold Plus 4.5.5
Checkout ONE
Checkout ONE DPM
BCSE CIM
Apache
Linux
Reply With Quote
  #18  
Old 04-10-2005, 06:44 PM
 
shwekhaw shwekhaw is offline
 

Senior Member
  
Join Date: Nov 2004
Posts: 148
 

Default

Never mind. I learnt basic SQL and spent a couple hours to write my first sql query syntax and everything solved.

S-H-W-E-K-H-A-W
__________________
X-Cart Gold Plus 4.5.5
Checkout ONE
Checkout ONE DPM
BCSE CIM
Apache
Linux
Reply With Quote
  #19  
Old 05-23-2005, 10:36 AM
  shan's Avatar 
shan shan is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Birmingham, UK
Posts: 6,163
 

Default

Quote:
Originally Posted by dsparks
Well, this one was fun...

It seems that the extra field information is not saved with the order data when an order is placed or generated when the order is read back from the database.

What I did was just pull the extra field information when the order is regenerated for display.

A real fix would be to store the extra field data along with the order when it is saved in case the extra field data is changed at a later date.

Oh well, maybe next time.



To change this you will need to do the following:


1) Enable the Extra Fields module under the Administration area, Modules section.

2) Create your extra fields under the Products area, Extra Fields section

3) Then pick a product you want to test with and add some extra field data to it, and save it.

4) Change the file /include/func.php around line 2601 in function func_order_data, right after the code:


Code:
foreach ($products as $k=>$v) {

add the following additional code:

Code:
if ($active_modules["Extra_Fields"]) { $productid = $v["productid"]; $extra_fields = func_query("SELECT $sql_tbl[extra_fields].*, $sql_tbl[extra_field_values].value as field_value, IF($sql_tbl[extra_field_values].fieldid > 0, 'Y', '') as is_value FROM $sql_tbl[extra_fields] LEFT JOIN $sql_tbl[extra_field_values] ON $sql_tbl[extra_fields].fieldid = $sql_tbl[extra_field_values].fieldid AND $sql_tbl[extra_field_values].productid = '$productid' ORDER BY $sql_tbl[extra_fields].fieldid"); } else $extra_fields = array(); $v["extra_fields"] = $extra_fields;


5) then, change the file /skin1/main/order_info.tpl around line 68 to see the extra field data on screen order displays:

after the code:
Code:
<TR> <TD valign="top">{$lng.lbl_quantity}</TD> <TD valign="top">{$products[prod_num].amount} item(s)</TD> </TR>

add this code:

Code:
{if $active_modules.Extra_Fields ne ""} {section name=field loop=$products[prod_num].extra_fields} {if $products[prod_num].extra_fields[field].field_value} <TR><TD> {$products[prod_num].extra_fields[field].field} </TD><TD> {$products[prod_num].extra_fields[field].field_value} </TD></TR> {/if} {/section} {/if}

6) then, change the file /skin1/mail/order_data.tpl around line 23, look for the code:

Code:
{/section}

which is the end section for the code section {section name=prod_num loop=$products}

and insert the following code right above it:

Code:
{if $active_modules.Extra_Fields ne ""} {section name=field loop=$products[prod_num].extra_fields} {if $products[prod_num].extra_fields[field].field_value} {$products[prod_num].extra_fields[field].field}: {$products[prod_num].extra_fields[field].field_value} {/if} {/section} {/if}


7) Find an order or create a new order that has the product with the extra field on it and is should now display the new extra field data.

I did not include an example on how to modify the html version of the invoice, but you should be able to take the code above and insert it into that file and make it work.

Also, there is no checking to see whether the SHOW flag in the extra fields maintenance is on or off, but you can add or leave that out where needed.


Hope this works for you....

if you want to add the extra fields to the html invoices you have to do it a bit different.........


Code:
{foreach from=$product.extra_fields key=field_name item=field} {$field.field} : {$field.field_value} {/foreach}
__________________
Looking for a reliable X-cart host ?
You wont go wrong with either of these.

EWD Hosting
Hands On Hosting
Reply With Quote
  #20  
Old 10-01-2005, 06:41 AM
 
junaid junaid is offline
 

Advanced Member
  
Join Date: Dec 2003
Posts: 96
 

Default

okay here is my code but its for product.tpl i think it should work
{section name=field}
{if $extra_fields[field].active eq "Y" && $extra_fields[field].field_value}
{$extra_fields[XX].field_value}
{/if}
{/section}

remember field id does vary and may not be as in the database there do try various combinations.

also i need opinion of others on this, is there any risk showing like this or any improvement in the code.
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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 01:47 PM.

   

 
X-Cart forums © 2001-2020