demastermind Posted August 9, 2011 Share Posted August 9, 2011 Hello, I am trying to get the customers name to show in the order email. How would I make a "call" to the database table "TABLE_CUSTOMERS" to get the customers first and last name as a variable? Thanks, Luc My Installed Contributions: 1. Ultimate SEO URLs V 2-2.2d-X 2. Quantity Box on Product Info Page 3. httpbl4osc Version 1.1.0 4. QTpro for osc 2.3 5. Header Tags SEO V 3.0 (For 2.3) 6. DHTML State Selection for 2.3.1 And Good To Know: I use a 960gs fluid style sheet. I do have a honey pot on my website. Store Version: 2.3 “Pain is temporary. Quitting lasts forever." - Lance Armstrong Link to comment Share on other sites More sharing options...
germ Posted August 9, 2011 Share Posted August 9, 2011 It's already there: First name: $order->customer['firstname'] Last Name: $order->customer['lastname'] If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
demastermind Posted August 9, 2011 Author Share Posted August 9, 2011 It's already there: First name: $order->customer['firstname'] Last Name: $order->customer['lastname'] Ok, but now I am confused, I would expect this code to work, but it doesn't if (ACCOUNT_TITLE == 'true') { if ($title == 'm') { $email_order .= sprintf(EMAIL_TILE_MR, $lastname); } elseif ($title == 'w') { $email_order .= sprintf(EMAIL_TITLE_MRS, $lastname); } elseif ($title == 's') { $email_order .= sprintf(EMAIL_TITLE_MS, $lastname); } } else { $email_order .= sprintf(EMAIL_GREET_NONE, $firstname); } or this to work, but is doesn't: $email_order .= $firstname; I am trying to put the customers name in the order email before the "letter" that I've put in the email. My Installed Contributions: 1. Ultimate SEO URLs V 2-2.2d-X 2. Quantity Box on Product Info Page 3. httpbl4osc Version 1.1.0 4. QTpro for osc 2.3 5. Header Tags SEO V 3.0 (For 2.3) 6. DHTML State Selection for 2.3.1 And Good To Know: I use a 960gs fluid style sheet. I do have a honey pot on my website. Store Version: 2.3 “Pain is temporary. Quitting lasts forever." - Lance Armstrong Link to comment Share on other sites More sharing options...
germ Posted August 9, 2011 Share Posted August 9, 2011 You aren't using the correct variables. For example, your code: $email_order .= $firstname; Needs to be: $email_order .= $order->customer['firstname']; If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
demastermind Posted August 10, 2011 Author Share Posted August 10, 2011 $email_order .= $order->customer['firstname']; Can you explain how this works? The $order I'm quessing is the table and the firstname is the field, so what does customer mean? My Installed Contributions: 1. Ultimate SEO URLs V 2-2.2d-X 2. Quantity Box on Product Info Page 3. httpbl4osc Version 1.1.0 4. QTpro for osc 2.3 5. Header Tags SEO V 3.0 (For 2.3) 6. DHTML State Selection for 2.3.1 And Good To Know: I use a 960gs fluid style sheet. I do have a honey pot on my website. Store Version: 2.3 “Pain is temporary. Quitting lasts forever." - Lance Armstrong Link to comment Share on other sites More sharing options...
germ Posted August 10, 2011 Share Posted August 10, 2011 No. The file has this code: require(DIR_WS_CLASSES . 'order.php'); $order = new order; That makes the variable $order of the class order ( look in /catalog/includes/classes/order.php ). Then: $order->customer['firstname']; Is just a "field" in the variable. Or maybe more precisely a part of the $order array. Probably clear as mudd.... :blink: I'm not too good at explaining things sometimes... :blush: If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
demastermind Posted August 10, 2011 Author Share Posted August 10, 2011 No. The file has this code: require(DIR_WS_CLASSES . 'order.php'); $order = new order; That makes the variable $order of the class order ( look in /catalog/includes/classes/order.php ). Ok, now I get how that works, thanks. I got it to write the customers name before the message that I put in, but the important part is putting the Mr. Ms. or Mrs. infront of it. In the customers table of the SQL database I have created a field called "customer_title. It has three values for the three different titles. How would I be able to get that value and turn it in to a variable that could be used in code like this: // if (ACCOUNT_TITLE == 'true') { if ($title == 'm') { $email_order .= sprintf(EMAIL_TITLE_MR, $order->customer['lastname']); } elseif ($title == 'w') { $email_order .= sprintf(EMAIL_TITLE_MRS, $order->customer['lastname']); } elseif ($title == 's') { $email_order .= sprintf(EMAIL_TITLE_MS, $order->customer['lastname']); } /* } */ else { $email_order .= sprintf(EMAIL_GREET_NONE, $order->customer['firstname']); } I am guessing that I have to edit something in the order.php class, but then again, maybe not. My Installed Contributions: 1. Ultimate SEO URLs V 2-2.2d-X 2. Quantity Box on Product Info Page 3. httpbl4osc Version 1.1.0 4. QTpro for osc 2.3 5. Header Tags SEO V 3.0 (For 2.3) 6. DHTML State Selection for 2.3.1 And Good To Know: I use a 960gs fluid style sheet. I do have a honey pot on my website. Store Version: 2.3 “Pain is temporary. Quitting lasts forever." - Lance Armstrong Link to comment Share on other sites More sharing options...
germ Posted August 10, 2011 Share Posted August 10, 2011 In this case you do need to query the DB for this info. Quite honestly MYSQL isn't my "thing". :blush: I've programmed in about a dozen different computer languages but never even saw any MYSQL until I was introduced to osCommerce. That being said, I just "plagerize" some other query to try to come up with the desired results. You know.... The end justifies the means... :lol: So backup the file. Then try replacing this code: if ($title == 'm') { $email_order .= sprintf(EMAIL_TITLE_MR, $order->customer['lastname']); } elseif ($title == 'w') { $email_order .= sprintf(EMAIL_TITLE_MRS, $order->customer['lastname']); } elseif ($title == 's') { $email_order .= sprintf(EMAIL_TITLE_MS, $order->customer['lastname']); } /* } */ else { $email_order .= sprintf(EMAIL_GREET_NONE, $order->customer['firstname']); With this code: $title_query = tep_db_query("select customer_title from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customer_id . "'"); $title = tep_db_fetch_array($title_query); switch ( strtolower( $title['customer_title'] ) ) { case 'm': $email_order .= sprintf(EMAIL_TITLE_MR, $order->customer['lastname']); break; case 'w': $email_order .= sprintf(EMAIL_TITLE_MRS, $order->customer['lastname']); break; case 's': $email_order .= sprintf(EMAIL_TITLE_MS, $order->customer['lastname']); break; default: $email_order .= sprintf(EMAIL_GREET_NONE, $order->customer['firstname']); } I've got my "plagerized" query to (hopefully) get the "customer_title" from the DB. And I modified all your "if then... else" code and used a "switch". Much cleaner code and easier to follow (IMHO). :) If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
demastermind Posted August 11, 2011 Author Share Posted August 11, 2011 In this case you do need to query the DB for this info. $title_query = tep_db_query("select customer_title from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customer_id . "'"); $title = tep_db_fetch_array($title_query); switch ( strtolower( $title['customer_title'] ) ) { case 'm': $email_order .= sprintf(EMAIL_TITLE_MR, $order->customer['lastname']); break; case 'w': $email_order .= sprintf(EMAIL_TITLE_MRS, $order->customer['lastname']); break; case 's': $email_order .= sprintf(EMAIL_TITLE_MS, $order->customer['lastname']); break; default: $email_order .= sprintf(EMAIL_GREET_NONE, $order->customer['firstname']); } I've got my "plagerized" query to (hopefully) get the "customer_title" from the DB. And I modified all your "if then... else" code and used a "switch". Much cleaner code and easier to follow (IMHO). :) Perfect! <-- Thats how that code you made works. I took out the old, put in the new, and volia, it works. It now puts the customers " Dear 'title' 'last name', " into the email. Thanks again. - Luc My Installed Contributions: 1. Ultimate SEO URLs V 2-2.2d-X 2. Quantity Box on Product Info Page 3. httpbl4osc Version 1.1.0 4. QTpro for osc 2.3 5. Header Tags SEO V 3.0 (For 2.3) 6. DHTML State Selection for 2.3.1 And Good To Know: I use a 960gs fluid style sheet. I do have a honey pot on my website. Store Version: 2.3 “Pain is temporary. Quitting lasts forever." - Lance Armstrong Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.