Solved

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

Posted on 2008-10-21
13
478 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
  • 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now