Latest News: (loading..)

Archived

This topic is now archived and is closed to further replies.

demastermind

How to "call" customers name from database.

9 posts in this topic

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

Share this post


Link to post
Share on other sites

It's already there:

 

First name: $order->customer['firstname']

 

Last Name: $order->customer['lastname']

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

You aren't using the correct variables.

 

For example, your code:

 

$email_order .= $firstname; 

Needs to be:

 

$email_order .= $order->customer['firstname']; 

demastermind likes this

Share this post


Link to post
Share on other sites

$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?

Share this post


Link to post
Share on other sites

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:

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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).

:)

demastermind likes this

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites