Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Oct 2007
    Posts
    66
    Plugin Contributions
    0

    Default Adding custom field to Order Confirmation Email

    Hi All! I have added a custom field to the order table and would like it to show up on the order confirmation emails. I have added it to display in the admin/orders.php and that works fine. I am having trouble with the code for the email. Here is what I have so far. In the classes/order.php file, I have added the field to the $order_query, and added it to the $this->info = array.

    In the send_order_email function.. here is the part I have changed (only the line starting with 'Web...):

    PHP Code:
    //intro area
        
    $email_order EMAIL_TEXT_HEADER EMAIL_TEXT_FROM STORE_NAME "\n\n" .
        
    $this->customer['firstname'] . ' ' $this->customer['lastname'] . "\n\n" .
        
    EMAIL_THANKS_FOR_SHOPPING "\n" EMAIL_DETAILS_FOLLOW "\n" .
        
    EMAIL_SEPARATOR "\n" .
        
    EMAIL_TEXT_ORDER_NUMBER ' ' $zf_insert_id "\n" .
        
    EMAIL_TEXT_DATE_ORDERED ' ' strftime(DATE_FORMAT_LONG) . "\n" .
        
    'Web Stylist: ' $this->info['stylist'] . "\n\n" .
        
    EMAIL_TEXT_INVOICE_URL ' ' zen_href_link(FILENAME_ACCOUNT_HISTORY_INFO'order_id=' $zf_insert_id'SSL'false) . "\n\n"
    On the plain text email that goes to the admins, only the title shows up, but no data shows after it. It does exist in the database.

    If it matters, Im using 1.3.9h.

    Any ideas?


  2. #2
    Join Date
    Jan 2004
    Posts
    58,246
    Blog Entries
    3
    Plugin Contributions
    106

    Default Re: Adding custom field to Order Confirmation Email

    Please share the rest of the code changes you've made.

    Thanks for sharing the information that you DID share. At least that was much more than lots of people include in their posts.

    It would be helpful if you posted all the other changes you made in the file, and where they're located. They probably need to be in the create_order() or create_order_products() methods. Putting them before that probably won't accomplish much, especially if it's in the query() method since that's related to *completed* orders, not new orders ... again, it depends on what exactly you're doing and why and when and how. And hopefully you're talking about the /includes/classes/order.php file, and NOT the admin version of the file.

    Also, the code you quoted shows that you're only adding the information to the text-only emails, not the HTML-formatted emails. Just in case that matters to you.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donations always welcome: www.zen-cart.com/donate

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Oct 2007
    Posts
    66
    Plugin Contributions
    0

    Default Re: Adding custom field to Order Confirmation Email

    I'll try to add a bit more of what I did to get to this place.

    For the "$this->info array" in the includes/classes/order.php, I added the last line here:

    PHP Code:
        $this->info = array('currency' => $order->fields['currency'],
                            
    'currency_value' => $order->fields['currency_value'],
                            
    'payment_method' => $order->fields['payment_method'],
                            
    'payment_module_code' => $order->fields['payment_module_code'],
                            
    'shipping_method' => $order->fields['shipping_method'],
                            
    'shipping_module_code' => $order->fields['shipping_module_code'],
                            
    'coupon_code' => $order->fields['coupon_code'],
                            
    'cc_type' => $order->fields['cc_type'],
                            
    'cc_owner' => $order->fields['cc_owner'],
                            
    'cc_number' => $order->fields['cc_number'],
                            
    'cc_expires' => $order->fields['cc_expires'],
                            
    'date_purchased' => $order->fields['date_purchased'],
                            
    'orders_status' => $order_status->fields['orders_status_name'],
                            
    'last_modified' => $order->fields['last_modified'],
                            
    'total' => $order->fields['order_total'],
                            
    'tax' => $order->fields['order_tax'],
                            
    'ip_address' => $order->fields['ip_address'],
                            
    'stylist' => $order->fields['stylist']
                            ); 
    At the top of the order.php, I added stylist field to the $order_query.

    In the $sql_data_array array I added the last line:
    PHP Code:
        $sql_data_array = array('customers_id' => $_SESSION['customer_id'],
                                
    'customers_name' => $this->customer['firstname'] . ' ' $this->customer['lastname'],
                                
    'customers_company' => $this->customer['company'],
                                
    'customers_street_address' => $this->customer['street_address'],
                                
    'customers_suburb' => $this->customer['suburb'],
                                
    'customers_city' => $this->customer['city'],
                                
    'customers_postcode' => $this->customer['postcode'],
                                
    'customers_state' => $this->customer['state'],
                                
    'customers_country' => $this->customer['country']['title'],
                                
    'customers_telephone' => $this->customer['telephone'],
                                
    'customers_email_address' => $this->customer['email_address'],
                                
    'customers_address_format_id' => $this->customer['format_id'],
                                
    'delivery_name' => $this->delivery['firstname'] . ' ' $this->delivery['lastname'],
                                
    'delivery_company' => $this->delivery['company'],
                                
    'delivery_street_address' => $this->delivery['street_address'],
                                
    'delivery_suburb' => $this->delivery['suburb'],
                                
    'delivery_city' => $this->delivery['city'],
                                
    'delivery_postcode' => $this->delivery['postcode'],
                                
    'delivery_state' => $this->delivery['state'],
                                
    'delivery_country' => $this->delivery['country']['title'],
                                
    'delivery_address_format_id' => $this->delivery['format_id'],
                                
    'billing_name' => $this->billing['firstname'] . ' ' $this->billing['lastname'],
                                
    'billing_company' => $this->billing['company'],
                                
    'billing_street_address' => $this->billing['street_address'],
                                
    'billing_suburb' => $this->billing['suburb'],
                                
    'billing_city' => $this->billing['city'],
                                
    'billing_postcode' => $this->billing['postcode'],
                                
    'billing_state' => $this->billing['state'],
                                
    'billing_country' => $this->billing['country']['title'],
                                
    'billing_address_format_id' => $this->billing['format_id'],
                                
    'payment_method' => (($this->info['payment_module_code'] == '' and $this->info['payment_method'] == '') ? PAYMENT_METHOD_GV $this->info['payment_method']),
                                
    'payment_module_code' => (($this->info['payment_module_code'] == '' and $this->info['payment_method'] == '') ? PAYMENT_MODULE_GV $this->info['payment_module_code']),
                                
    'shipping_method' => $this->info['shipping_method'],
                                
    'shipping_module_code' => (strpos($this->info['shipping_module_code'], '_') > substr($this->info['shipping_module_code'], 0strpos($this->info['shipping_module_code'], '_')) : $this->info['shipping_module_code']),
                                
    'coupon_code' => $this->info['coupon_code'],
                                
    'cc_type' => $this->info['cc_type'],
                                
    'cc_owner' => $this->info['cc_owner'],
                                
    'cc_number' => $this->info['cc_number'],
                                
    'cc_expires' => $this->info['cc_expires'],
                                
    'date_purchased' => 'now()',
                                
    'orders_status' => $this->info['order_status'],
                                
    'order_total' => $this->info['total'],
                                
    'order_tax' => $this->info['tax'],
                                
    'currency' => $this->info['currency'],
                                
    'currency_value' => $this->info['currency_value'],
                                
    'ip_address' => $_SESSION['customers_ip_address'] . ' - ' $_SERVER['REMOTE_ADDR'],
                                
    'stylist' => $_SESSION['referral_code']
                                ); 
    I did see that this only shows up on the text only emails, but i figured I would go one step at a time.

    Thanks!

    -Steve

  4. #4
    Join Date
    Jan 2004
    Posts
    58,246
    Blog Entries
    3
    Plugin Contributions
    106

    Default Re: Adding custom field to Order Confirmation Email

    The $order_query at the top of the file is in the query() method (a "function" inside a class is called a "method"). That method is only used when loading an existing order, such as on the customer order-history page. So has no relevance for new orders and corresponding order-confirmation emails.

    Stuffing values into the $sql_data_array is only appropriate or necessary if you've created a database field to store that information.

    To affect order-confirmation emails, you'll need to add your value to the $this->info array around line 350, which is inside the cart() method.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donations always welcome: www.zen-cart.com/donate

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Oct 2007
    Posts
    66
    Plugin Contributions
    0

    Default Re: Adding custom field to Order Confirmation Email

    Quote Originally Posted by DrByte View Post
    The $order_query at the top of the file is in the query() method (a "function" inside a class is called a "method"). That method is only used when loading an existing order, such as on the customer order-history page. So has no relevance for new orders and corresponding order-confirmation emails.

    Stuffing values into the $sql_data_array is only appropriate or necessary if you've created a database field to store that information.

    To affect order-confirmation emails, you'll need to add your value to the $this->info array around line 350, which is inside the cart() method.
    In my order.php at line 337:
    $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID,

    and at line 388
    $this->customer = array('firstname' => $customer_address->fields['customers_firstname'],

    Should it be added to the customer array?

  6. #6
    Join Date
    Jan 2004
    Posts
    58,246
    Blog Entries
    3
    Plugin Contributions
    106

    Default Re: Adding custom field to Order Confirmation Email

    No, as I said, add it to the $this->info array. That spans from about 336-357 or so in v1.3.9h. So, 350 is one of many lines on which you could put it.

    If you put it in the $this->customer array at 388, then you can't refer to it as $this->info['stylist']
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donations always welcome: www.zen-cart.com/donate

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Oct 2007
    Posts
    66
    Plugin Contributions
    0

    Default Re: Adding custom field to Order Confirmation Email

    I added it to the $this->info array at line 337 and it showed up on the order confirmation email!!!



    Now I just need to get it to show up on the HTML emails. Any ideas on that. I have looked at the email templates "email_template_checkout.html" and I believe that is the one to modify.

  8. #8
    Join Date
    Jan 2004
    Posts
    58,246
    Blog Entries
    3
    Plugin Contributions
    106

    Default Re: Adding custom field to Order Confirmation Email

    In the order.php file you'll see several lines like this:
    Code:
        $html_msg['EMAIL_FIRST_NAME'] = $this->customer['firstname'];
    And you'll see $EMAIL_FIRST_NAME in the email template.

    The system will replace $EMAIL_FIRST_NAME with whatever you set as the value of $html_msg['EMAIL_FIRST_NAME']
    So, following that pattern, pick something for your custom info, and add your stuff to the files as needed.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donations always welcome: www.zen-cart.com/donate

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  9. #9
    Join Date
    Oct 2007
    Posts
    66
    Plugin Contributions
    0

    Default Re: Adding custom field to Order Confirmation Email

    Just to finish up and show what I did for others in the future. On the order.php file, I added:
    PHP Code:
    $html_msg['STYLIST'] = $this->info['stylist']; 
    at line 949 which was in the //intro area of the confirmation email.

    On the email_template_checkout.html I added the $STYLIST to a spot I wanted it to show up.

    All seems to be working now, thanks DrByte.



    Looks like we owe you some cups of coffee for this one.

  10. #10
    Join Date
    Jan 2004
    Posts
    58,246
    Blog Entries
    3
    Plugin Contributions
    106

    Default Re: Adding custom field to Order Confirmation Email

    Glad you got it sorted out!
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donations always welcome: www.zen-cart.com/donate

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Customize Order Confirmation Email - Add Field
    By Toot4fun in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 28 Mar 2010, 08:00 PM
  2. How did you hear about us field in Order Confirmation Email
    By zepher in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 23 Mar 2010, 02:47 PM
  3. Confirmation Email - adding custom field
    By OllieBarnett in forum General Questions
    Replies: 1
    Last Post: 10 Feb 2010, 11:47 PM
  4. Adding a Field to the Order Confirmation
    By Will.hollaway in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 30 Jul 2008, 11:27 PM
  5. How to override header_php.php or how to add a new field to order confirmation email
    By monkeytown in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 25 Jan 2008, 06:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •