Link to home
Start Free TrialLog in
Avatar of Melody Scott
Melody ScottFlag for United States of America

asked on

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

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
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

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()
Avatar of Melody Scott

ASKER

Ok, will do- back to you tomorrow, thanks!
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
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.
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!
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.
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']);
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
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That was my fault, I had missed a line- it works now, thanks so much!
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.)