?
Solved

Need to add telephone and email to php page on Zen cart

Posted on 2008-10-21
13
Medium Priority
?
491 Views
Last Modified: 2013-12-13
Hi,

 If you go to this cart and place an order (it's not live yet, you can log in as a customer using email address melody@magickitchen.com and password tests), you will see on this page:

http://diabeticmealprograms.com/cart/index.php?main_page=checkout_shipping

and this one:

http://diabeticmealprograms.com/cart/index.php?main_page=checkout_payment

that there are billing and shipping addresses. My client would like me to add in the customer's phone number and email address. (which we have in the same database.)

I'm pretty sure that I do that on:

 /cart/includes/templates/template_default/templates/tpl_checkout_shipping_address_default.php

and

/cart/includes/templates/template_default/templates/tpl_checkout_payment_address_default.php

But I really don't know how. I am attaching those two files here, with the exttensions changed to txt. I hope I have the right files, and that someone can help! Thanks in advance!
tpl-checkout-shipping-address-de.txt
tpl-checkout-payment-address-def.txt
0
Comment
Question by:mel200
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22772731
The address is written here:

<address class="back"><?php echo zen_address_label($_SESSION['customer_id'], $_SESSION['billto'], true, ' ', '<br />'); ?></address>

and

<address class="back"><?php echo zen_address_label($_SESSION['customer_id'], $_SESSION['sendto'], true, ' ', '<br />'); ?></address>

You need to find the definition of the function zen_address_label()
0
 

Author Comment

by:mel200
ID: 22781264
Ok, will do- back to you tomorrow, thanks!
0
 

Author Comment

by:mel200
ID: 22787412
Hi- I think this is it, at about line 119 in this attached file, functions_customers.php. Does that look like what we need? Thanks!
functions-customers.txt
0
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22787811
Yes, this seems to be it.

This is a rather complex handling of address labels, it is made this way to be able to handle all forms of addresses, international. First, there is a selection of format based on country. A lookup in TABLE_COUNTRIES finds the address_format_id for the country of the address in question. The address_format_id is used to lookup in TABLE_ADDRESS_FORMAT to find the format to use in a column called 'format'.

To implement email and phone here, we must do two things: make the two new fields available in the $address->fields array passed from zen_address_label() to zen_address_format(), and change the format in the correct row in TABLE_ADDRESS_FORMAT to include the new fields.

You said you had the email and phone in the same database. In what table are they, and what are the columns called? The addesses are in table TABLE_ADDRESS_BOOK, if email/phone is in a different table, we need to know how to join the two tables. Is the column 'customers_id' in both tables?

TABLE_ADDRESS_BOOK, TABLE_ADDRESS_FORMAT and TABLE_COUNTRIES probably has slightly different names in your database, these are the names of the PHP constants used to store the real names.
0
 

Author Comment

by:mel200
ID: 22788254
Ah, I see! You're absolutely right. zen_address_book contains the addresses, but zen_customers contains the phone numbers and email addresses. Both tables have customers_id.

In zen_address_book, the column names are address_book_id, customers_id, entry_gender, entry_company, entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_state, entry_country_id, entry_zone_id

In zen_customers, the column names are:
customers_id, customers_gender, customers_firstname, customers_lastname, customers_dob, customers_email_address, customers_nick, customers_default_address_id, customers_telephone, customers_fax, customers_password, customers_newsletter, customers_group_pricing              customers_email_format, customers_authorization, customers_referral, customers_paypal_payerid, customers_paypal_ec       

Where do we go from here? I really appreciate this; I recognize that doing this second hand is incredibly difficult!  I should tell you that I will be in and out all day today, and will check this question every few hours. Then I am away until Tuesday. Thanks again!
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22789713
You need to modify functions_customers.php.

First, we modify the SQL statement. Because 'customer_id' is the only common column name in the two tables, we can use a NATURAL JOIN, automatically joining on the common column. In function zen_address_label(), change the query, like this:

    $address_query = "select entry_firstname as firstname, entry_lastname as lastname,
                             entry_company as company, entry_street_address as street_address,
                             entry_suburb as suburb, entry_city as city, entry_postcode as postcode,
                             entry_state as state, entry_zone_id as zone_id,
                             entry_country_id as country_id,
                             customers_email_address as email,
                             customers_telephone as telephone
                      from " . TABLE_ADDRESS_BOOK . "
                      as AB natural join " . TABLE_CUSTOMERS . "
                      where AB.customers_id = '" . (int)$customers_id . "'
                      and address_book_id = '" . (int)$address_id . "'";

Then we need to make the new columns 'email' and 'telephone' available in the zen_address_format() function. Immediately after this line (line 53):

    $state = zen_output_string_protected($address['state']);

...insert these lines:

    if (isset($address['email']) && zen_not_null($address['email']))
      $email = zen_output_string_protected($address['email']);
    if (isset($address['telephone']) && zen_not_null($address['telephone']))
      $email = zen_output_string_protected($address['telephone']);

After saving your changes you should immediately check that everything works ok.

If all is fine, you can put the $email and $telephone into the format column in the TABLE_ADDRESS_FORMAT. To find the correct row(s), you first need to find the address_format_id for the relevant countries in TABLE_COUNTRIES. I don't know if you need to consider multiple countries, but I suppose many countries will share the same address_format_id, hopefully there are not too many that needs to be changed.

The 'format' column will contain a template, where you can see PHP variables like $steet, $zip, $city and so on. Some are special: $CR means a new line (carriage return), $HR means a <hr> (horizontal ruler). Update this row and insert your $email and $telephone variables. Post the content of the format column if you need help.
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22789888
There was a bug in the telephone assignment above, it should be like this:

    if (isset($address['telephone']) && zen_not_null($address['telephone']))
      $telephone = zen_output_string_protected($address['telephone']);
0
 

Author Comment

by:mel200
ID: 22790280
wow, you're good!  I am bowing down to you. We are only selling in the United States, so this should be relatively simple, but let me run it by you.

Ok, the table zen_address_format is as attached. What I understand is that I would do an SQL query such as:

UPDATE zen_address_format
SET ADDRESS_FORMAT ='$firstname $lastname$cr$streets$cr$city, $postcode$cr$statecomma$country,$telephone,$email'
WHERE ADDRESS_FORMAT_ID='1'

and do the same for each row?


SQL-result---phpMyAdmin-2.1...pdf
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22790485
Yes, or you can edit it direcctly in phpMyAdmin. You only need to edit the one with the same address_format_id as the country record for USA.
0
 

Author Comment

by:mel200
ID: 22790822
Ok, thanks again. I  changed each address_format cell, adding $cr$telephone$cr$email

Now in my cart, I do see the telephone number, but not the email address.
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 2000 total points
ID: 22791083
That was odd.

I spotted a weakness in the new code, but I don't think it explains the missing email. We should fix it anyways. Change these four lines:

    if (isset($address['email']) && zen_not_null($address['email']))
      $email = zen_output_string_protected($address['email']);
    if (isset($address['telephone']) && zen_not_null($address['telephone']))
      $telephone = zen_output_string_protected($address['telephone']);

...into this:

    $email = (isset($address['email']) && zen_not_null($address['email'])) ?
      zen_output_string_protected($address['email']) : '';
    $telephone = (isset($address['telephone']) && zen_not_null($address['telephone'])) ?
      zen_output_string_protected($address['telephone']) : '';

That way the $email and $telephone variables are defined even if they have no value in the database.

Check the sql again, it should contain "customers_email_address as email," and check that the customer record actually has an email in this column (using phpMyAdmin).

If the email still won't show up, the only source for the problem I can think of right now is the function zen_output_string_protected(). It is used on all values read from the database before they are output. Can you find the definition of this function?
0
 

Author Comment

by:mel200
ID: 22791248
That was my fault, I had missed a line- it works now, thanks so much!
0
 

Author Closing Comment

by:mel200
ID: 31508569
If you are reading this, read through all the answers- this expert really IS!! (with apologies, I know you're all experts, but this person was a huge help.)
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question