View Single Post
  #56  
Old 09-12-2007, 12:56 PM
 
robertswww robertswww is offline
 

X-Adept
  
Join Date: Jul 2003
Posts: 586
 

Default Re: Printing 'Customer Notes' on invoices

Below, I prepared a Step-by-Step install guide for those using X-Cart version 4.0.19

Thanks to Cheri and Lucent88 for the meat of the code and Roblen, PHPdev and Loon for getting us started on this great mod!

I added additional details, line numbers and a few tweaks. It's a lot of files to change, but the changes are easy and this Mod will add this necessary element that was missing from the order management end. Plus, there's not a single SQL Patch! Just backup your site first, or work on a copy of the files involved.

What this Mod does: When the customer goes to Checkout and enters something in "Customer Notes", like special shipping instructions, those notes are encrypted along with the credit card information and written to the database. This information is typically hidden from your order fulfillment staff and does not appear on the customer's invoice. Below is a way to make the Customer Notes data independent of the Credit Card encryption and easily accessible to all necessary parties.

FYI: You can name the new field whatever you want to, just be consistent. Here's what 3 of us chose for the new field name:
Cherie: order_first
Lucent: order_comment
Robert: customer_comments

OPTIONAL: Change your language label via Admin-->Languages for "lbl_customer_notes" if you so desire...
My old Value: Customer notes
My new Value: <b>Customer Notes</b>


1. Locate File: include/func.php - add new field (customer_comments) to function: func_place_order (deep in code about line 2980+/-)

Find this Code:
Code:
# # This function creates order entry in orders table # function func_place_order($payment_method, $order_status, $order_details, $extra = array(), $extras = array()) {
Replace with this Code:
Code:
# # This function creates order entry in orders table # function func_place_order($payment_method, $order_status, $order_details, $customer_comments, $extra = array(), $extras = array()) {

2. Locate File: include/func.php (same file and function as above) - add "Customer_Comment" checkout form field name (about line 3160 +/-)

Find this Code:
Code:
if(!empty($extras)) {
Replace with this Code (added just above):
Code:
$extras['Customer_Comment'] = $customer_comments; if(!empty($extras)) {

3. Locate these 3 Files: payment/payment_cc.php (about line "78") AND payment/payment_offline.php (about line 46) AND payment_giftcert.php (about line 105 after "$order_details =$ship_to;") - (Note: to capture the user's input)

(NOTE: Paypal uses payment_offline.php)

Find this Code:
Code:
$order_details = "";
Replace with this Code (added just above):
Code:
$customer_comments = $Customer_Comment; $order_details = "";

4. Locate these 3 Files: payment/payment_cc.php AND payment/payment_offline.php AND payment/payment_giftcert.php (same files as above)

Find the Code that starts with: (Note: 2 areas in payment_cc.php AND 1 area in payment_offline.php AND 1 area in payment_giftcert.php)
Code:
$orderids = func_place_order

Add the field ($customer_comments) after $order_details

Code (payment_cc.php - around line "118"):
Code:
$orderids = func_place_order(stripslashes($payment_method)." (".$module_params["module_name"].(get_cc_in_testmode($module_params)?", in test mode":"").")", "I", $order_details, $customer_comments);

Code (payment_cc.php - around line 156):
Code:
$orderids = func_place_order(stripslashes($payment_method)." (manual processing)","Q",$order_details,$customer_comments);

Code (payment_offline.php - around line 64):
Code:
$orderids = func_place_order(stripslashes($payment_method),"Q",$order_details,$customer_comments);

Code (payment_giftcert.php - around line "108"):
Code:
$orderids = func_place_order(stripslashes($payment_method),"I",$order_details,$customer_comments);

*** Now the new field, Customer_Comment, is stored with the order in the order_extras table.

5. Locate File: skin1/customer/main/checkout_notes.tpl (around line 10)

Find this Code:
Code:
<TEXTAREA cols="45" rows="6" name="Customer_Notes"></TEXTAREA>

Replace with this Code:
Code:
<TEXTAREA cols="45" rows="6" name="Customer_Comment"></TEXTAREA>

6. Create a stripslashes smarty modifier: removes slashes directly from the template when extracting the Customer Comments/Notes.

*** NOTE: if you don't add "|sslash" to the end of your string variables that call the Customer Comments/notes, then if there is a quote or apostrophe in the customer's comment it will look like this: customer\'s comment.

First, create a new file and name it "modifier.sslash.php" save it to Smarty-2.6.9/plugins/ (note: I just duplicated the file, modifier.strip.php, then renamed it and replaced its contents with the new php code below)

Include this Code:
Code:
<?php function smarty_modifier_sslash($string) { return stripslashes($string); } ?>

7. Locate these 3 Files: skin1/mail/html/order_invoice.tpl AND order_customer_complete.tpl AND order_customer_processed.tpl

*** NOTE: code: {$order.extra.Customer_Comment|replace:"\n":" "|sslash} gets rid of customer line returns. To keep line returns use: {$order.extra.Customer_Comment|sslash}, but this will stretch out the invoice (horizontally) if there is a single long sentence from the customer.

Locate File: skin1/mail/html/order_invoice.tpl (to include Customer Comments/notes in Order Invoice)

Find this Code (around line 304):
Code:
{if $config.Email.show_cc_info eq "Y" and $show_order_details eq "Y"}

Replace with this Code (added just above):
Code:
<TR> <TD colspan="3">&nbsp;<BR>{$lng.lbl_customer_notes}:<BR>{$order.extra.Customer_Comment|replace:"\n":" "|sslash}</TD> </TR> {if $config.Email.show_cc_info eq "Y" and $show_order_details eq "Y"}

Optional: To include Customer Comments/notes in the Order Complete and Order Processed emails sent to the customer...
Locate these 2 Files: order_customer_complete.tpl AND order_customer_processed.tpl

Find this Code (around line 40):
Code:
<TR> <TD colspan="3">{include file="mail/html/order_data.tpl"}</TD> </TR> </TABLE>

Replace with this Code (added just above):
Code:
<TR><TD>{$lng.lbl_customer_notes}:</TD></TR> <TR><TD colspan="3">{$order.extra.Customer_Comment|replace:"\n":" "|sslash}</TD></TR> <TR><TD>&nbsp;<P></TD></TR> <TR> <TD colspan="3">{include file="mail/html/order_data.tpl"}</TD> </TR> </TABLE>

8. Locate File: skin1/main/history_order.tpl (around line 90)

Find this Code:
Code:
<P> {$lng.lbl_order_details}:<BR> <TEXTAREA name="details" cols="70" rows="8">{$order.details|escape:quotes}</TEXTAREA>
Replace with this Code (added just above):
Code:
<P> {$lng.lbl_customer_notes}: {if $usertype ne "C"} (visible to customer and provider) {/if}<BR> <textarea name="Customer_Comment" cols="70" rows="8">{$order.extra.Customer_Comment|sslash}</textarea> {if $usertype eq "A" or ($usertype eq "P" and $active_modules.Simple_Mode)} <P> {$lng.lbl_order_details}:<BR> <TEXTAREA name="details" cols="70" rows="4">{$order.details|escape:quotes}</TEXTAREA> {/if}

9. Locate File: admin/order.php - Make admin able to edit Customer's Comment/note in the status_change mode section before func_header_location. If you don't want the admin to be able to edit the Customer's Comments/notes, then add "readonly" (without quotes) to the end of the opening textarea tag in Step 8 (see Step 10 for an example).

Find this Code (around line 134):
Code:
func_change_order_status($orderid, $status); func_header_location("order.php?orderid=$orderid&mode=status_changed"); }
Big original code Flaw discovered and Fixed here:
If you go into Admin and change the Status of an order and add a Customer Comment/Note to an existing note, it works fine, but if there is NO existing note and therefore NO khash='Customer_Comment' field, then your new Admin note will NOT get added... here is the updated code to check if the 'Customer_Comment' field exists, if Yes, the updated comment is added to the Old (existing) Comments and Inserted into the DB table, if NO, the DB table is Updated to add the field and the comment:

Replace with this Code (added just above):
Code:
$customer_comments = addslashes($Customer_Comment); $oldcomments = db_query("SELECT value FROM $sql_tbl[order_extras] WHERE orderid='$orderid' AND khash='Customer_Comment'"); if ($oldcommentsexist = mysql_fetch_array($oldcomments)) { db_query("UPDATE $sql_tbl[order_extras] SET value='$customer_comments' WHERE orderid='$orderid' AND khash='Customer_Comment'"); } else { db_query("INSERT INTO $sql_tbl[order_extras] (orderid, khash, value) VALUES ('$orderid', 'Customer_Comment', '$customer_comments')"); } func_change_order_status($orderid, $status); func_header_location("order.php?orderid=$orderid&mode=status_changed"); }

10. OPTIONAL: For AOM users only (to see notes), Locate File: skin1/modules/Advanced_Order_Management/preview.tpl

Add this Code:
Code:
<textarea name="Customer_Comment" cols="60" rows="5" readonly>{$order.extra.Customer_Comment|sslash}</textarea>

11. OPTIONAL - Gift Cert Fix If you would like to integrate the additional code to fix the Gift Cert notes flaw, continue with my Post #60 below.

That's it... good luck!
Robert

Note: Updated Steps 1, 3, 8 & 9 on Oct. 6, 2007
__________________
X-cart 4.1.10
Reply With Quote