经过今天的长期排查 终于找到问题所在。就是paypalwpp.php 文件里面[code]function ec_step2_finish($paypal_ec_payer_info, $new_acct_notify) {
global $db, $order;
// register the payer_info in the session
$_SESSION['paypal_ec_payer_info'] = $paypal_ec_payer_info;
// debug
$this->zcLog('ec_step2_finish - 1', 'START: paypal_ec_payer_info= ' . print_r($_SESSION['paypal_ec_payer_info'], true));
/**
* Building customer zone/address from returned data
*/
// set some defaults, which will be updated later:
$country_id = '223';
$address_format_id = 2;
$state_id = 0;
$acct_exists = false;
// store default address id for later use/reference
$original_default_address_id = $_SESSION['customer_default_address_id'];
// Get the customer's country ID based on name or ISO code
$sql = "SELECT countries_id, address_format_id, countries_iso_code_2, countries_iso_code_3
FROM " . TABLE_COUNTRIES . "
WHERE countries_iso_code_2 = :countryId
OR countries_name = :countryId
LIMIT 1";
$sql1 = $db->bindVars($sql, ':countryId', $paypal_ec_payer_info['ship_country_name'], 'string');
$country1 = $db->Execute($sql1);
$sql2 = $db->bindVars($sql, ':countryId', $paypal_ec_payer_info['ship_country_code'], 'string');
$country2 = $db->Execute($sql2);
// see if we found a record, if yes, then use it instead of default American format
if ($country1->RecordCount() > 0) {
$country_id = $country1->fields['countries_id'];
if (!isset($paypal_ec_payer_info['ship_country_code']) || $paypal_ec_payer_info['ship_country_code'] == '') $paypal_ec_payer_info['ship_country_code'] = $country1->fields['countries_iso_code_2'];
$country_code3 = $country1->fields['countries_iso_code_3'];
$address_format_id = (int)$country1->fields['address_format_id'];
} elseif ($country2->RecordCount() > 0) {
// if didn't find it based on name, check using ISO code (ie: in case of no-shipping-address required/supplied)
$country_id = $country2->fields['countries_id'];
$country_code3 = $country2->fields['countries_iso_code_3'];
$address_format_id = (int)$country2->fields['address_format_id'];
}
// Need to determine zone, based on zone name first, and then zone code if name fails check. Otherwise uses 0.
$sql = "SELECT zone_id
FROM " . TABLE_ZONES . "
WHERE zone_country_id = :zCountry
AND zone_code = :zoneCode
OR zone_name = :zoneCode
LIMIT 1";
$sql = $db->bindVars($sql, ':zCountry', $country_id, 'integer');
$sql = $db->bindVars($sql, ':zoneCode', $paypal_ec_payer_info['ship_state'], 'string');
$states = $db->Execute($sql);
if ($states->RecordCount() > 0) {
$state_id = $states->fields['zone_id'];
}
/**
* Using the supplied data from PayPal, set the data into the order record 全局变量不知道怎么回事无法赋值所以导致信息无法写入数据库
*/
// customer
$order->customer['name'] = $paypal_ec_payer_info['payer_firstname'] . ' ' . $paypal_ec_payer_info['payer_lastname'];
$order->customer['company'] = $paypal_ec_payer_info['payer_business'];
$order->customer['street_address'] = $paypal_ec_payer_info['ship_street_1'];
$order->customer['suburb'] = $paypal_ec_payer_info['ship_street_2'];
$order->customer['city'] = $paypal_ec_payer_info['ship_city'];
$order->customer['postcode'] = $paypal_ec_payer_info['ship_postal_code'];
$order->customer['state'] = $paypal_ec_payer_info['ship_state'];
$order->customer['country'] = array('id' => $country_id, 'title' => $paypal_ec_payer_info['ship_country_name'], 'iso_code_2' => $paypal_ec_payer_info['ship_country_code'], 'iso_code_3' => $country_code3);
$order->customer['country']['id'] = $country_id;
$order->customer['country']['iso_code_2'] = $paypal_ec_payer_info['ship_country_code'];
$order->customer['format_id'] = $address_format_id;
$order->customer['email_address'] = $paypal_ec_payer_info['payer_email'];
$order->customer['telephone'] = $paypal_ec_payer_info['ship_phone'];
$order->customer['zone_id'] = $state_id;
// billing
$order->billing['name'] = $paypal_ec_payer_info['payer_firstname'] . ' ' . $paypal_ec_payer_info['payer_lastname'];
$order->billing['company'] = $paypal_ec_payer_info['payer_business'];
$order->billing['street_address'] = $paypal_ec_payer_info['ship_street_1'];
$order->billing['suburb'] = $paypal_ec_payer_info['ship_street_2'];
$order->billing['city'] = $paypal_ec_payer_info['ship_city'];
$order->billing['postcode'] = $paypal_ec_payer_info['ship_postal_code'];
$order->billing['state'] = $paypal_ec_payer_info['ship_state'];
$order->billing['country'] = array('id' => $country_id, 'title' => $paypal_ec_payer_info['ship_country_name'], 'iso_code_2' => $paypal_ec_payer_info['ship_country_code'], 'iso_code_3' => $country_code3);
$order->billing['country']['id'] = $country_id;
$order->billing['country']['iso_code_2'] = $paypal_ec_payer_info['ship_country_code'];
$order->billing['format_id'] = $address_format_id;
$order->billing['zone_id'] = $state_id;
// delivery 难道是没有进入这里查查看
if ($_SESSION['paypal_ec_payer_info']['ship_address_status'] != 'None') {
$order->delivery['name'] = $paypal_ec_payer_info['payer_firstname'] . ' ' . $paypal_ec_payer_info['payer_lastname'];
$order->delivery['company'] = $paypal_ec_payer_info['payer_business'];
$order->delivery['street_address']= $paypal_ec_payer_info['ship_street_1'];
$order->delivery['suburb'] = $paypal_ec_payer_info['ship_street_2'];
$order->delivery['city'] = $paypal_ec_payer_info['ship_city'];
$order->delivery['postcode'] = $paypal_ec_payer_info['ship_postal_code'];
$order->delivery['state'] = $paypal_ec_payer_info['ship_state'];
$order->delivery['country'] = array('id' => $country_id, 'title' => $paypal_ec_payer_info['ship_country_name'], 'iso_code_2' => $paypal_ec_payer_info['ship_country_code'], 'iso_code_3' => $country_code3);
$order->delivery['country_id'] = $country_id;
$order->delivery['format_id'] = $address_format_id;
$order->delivery['zone_id'] = $state_id;
}
// debug
$this->zcLog('ec_step2_finish - 2',
'country_id = ’ . $country_id . ’ ’ . $paypal_ec_payer_info[‘ship_country_name’] . ’ ’ . $paypal_ec_payer_info[‘ship_country_code’] ."\naddress_format_id = " . $address_format_id . "\nstate_id = " . $state_id . ’ (original state tested: ’ . $paypal_ec_payer_info[‘ship_state’] . ‘)’ . "\ncountry1->fields[‘countries_id’] = " . $country1->fields[‘countries_id’] . "\ncountry2->fields[‘countries_id’] = " . $country2->fields[‘countries_id’] . “\n” . '$order = ’ . print_r($order, true));
// check to see whether PayPal should still be offered to this customer, based on the zone of their address:
$this->update_status();
if (!$this->enabled) {
$this->terminateEC(MODULE_PAYMENT_PAYPALWPP_TEXT_INVALID_ZONE_ERROR, true, FILENAME_SHOPPING_CART);
}
// see if the user is logged in
if (!empty($_SESSION['customer_first_name']) && !empty($_SESSION['customer_id'])) {
// They're logged in, so forward them straight to checkout stages, depending on address needs etc
$order->customer['id'] = $_SESSION['customer_id'];
// set the session value for express checkout temp
$_SESSION['paypal_ec_temp'] = false;
// if no address required for shipping, leave shipping portion alone
if ($_SESSION['paypal_ec_payer_info']['ship_address_status'] != 'None' && $_SESSION['paypal_ec_payer_info']['ship_street_1'] != '') {
// set the session info for the sendto
$_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
// This is the address matching section
// try to match it first
// note: this is by no means 100%$order->delivery因为这个没有值导致错误return flase 继续查询
$address_book_id = $this->findMatchingAddressBookEntry($_SESSION['customer_id'], $order->delivery);
// no match, so add the record
if (!$address_book_id) {
$address_book_id = $this->addAddressBookEntry($_SESSION['customer_id'], $order->delivery, false);
}
// set the address for use
$_SESSION['sendto'] = $address_book_id;
}
// set the users billto information (default address)
if (!isset($_SESSION['billto'])) {
$_SESSION['billto'] = $_SESSION['customer_default_address_id'];
}
// debug
$this->zcLog('ec_step2_finish - 3', 'Exiting ec_step2_finish logged-in mode.' . "\n" . 'Selected address: ' . $address_book_id . "\nOriginal was: " . $original_default_address_id);
// select a shipping method, based on cheapest available option
if (MODULE_PAYMENT_PAYPALWPP_AUTOSELECT_CHEAPEST_SHIPPING == 'Yes') $this->setShippingMethod();
// send the user on
if ($_SESSION['paypal_ec_markflow'] == 1) {
$this->terminateEC('', false, FILENAME_CHECKOUT_PROCESS);
} else {
$this->terminateEC('', false, FILENAME_CHECKOUT_CONFIRMATION);
}
} else {
// They're not logged in. Create an account if necessary, and then log them in.
// First, see if they're an existing customer, and log them in automatically
// If Paypal didn't supply us an email address, something went wrong以下发生了很多事情比如买家送货地址写入 会员信息写入等等
if (trim($paypal_ec_payer_info['payer_email']) == '') $this->terminateEC(MODULE_PAYMENT_PAYPALWPP_INVALID_RESPONSE, true);
// attempt to obtain the user information using the payer_email from the info returned from PayPal, via email address
$sql = "SELECT customers_id, customers_firstname, customers_lastname, customers_paypal_payerid, customers_paypal_ec
FROM " . TABLE_CUSTOMERS . "
WHERE customers_email_address = :emailAddress ";
$sql = $db->bindVars($sql, ':emailAddress', $paypal_ec_payer_info['payer_email'], 'string');
$check_customer = $db->Execute($sql);
// debug
$this->zcLog('ec_step2_finish - 4', 'Not logged in. Looking for account.' . "\n" . $sql . "\n" . print_r($check_customer, true));
if (!$check_customer->EOF) {
$acct_exists = true;
// see if this was only a temp account -- if so, remove it
if ($check_customer->fields['customers_paypal_ec'] == '1') {
// Delete the existing temporary account
$this->ec_delete_user($check_customer->fields['customers_id']);
$acct_exists = false;
// debug
$this->zcLog('ec_step2_finish - 5', 'Found temporary account - deleting it.');
}
}
// Create an account, if the account does not existza问题就在这里 当返回的时候判断是否已经存在该用户有不进入 没有则创建用户信息等等
if (!$acct_exists) {
// debug
$this->zcLog('ec_step2_finish - 6', 'No ZC account found for this customer. Creating new account.' . "\n" . '$this->new_acct_notify =' . $this->new_acct_notify);
// Generate a random 8-char password
$password = zen_create_random_value(8);
$sql_data_array = array();
// set the customer information in the array for the table insertion
$sql_data_array = array(
'customers_firstname' => $paypal_ec_payer_info['payer_firstname'],
'customers_lastname' => $paypal_ec_payer_info['payer_lastname'],
'customers_email_address' => $paypal_ec_payer_info['payer_email'],
'customers_telephone' => $paypal_ec_payer_info['ship_phone'],
'customers_fax' => '',
'customers_gender' => $paypal_ec_payer_info['payer_gender'],
'customers_newsletter' => '0',
'customers_password' => zen_encrypt_password($password),
'customers_paypal_payerid' => $_SESSION['paypal_ec_payer_id']);
// insert the data
$result = zen_db_perform(TABLE_CUSTOMERS, $sql_data_array);
// grab the customer_id (last insert id)
$customer_id = $db->Insert_ID();
// set the Guest customer ID -- for PWA purposes
$_SESSION['customer_guest_id'] = $customer_id;
// set the customer address information in the array for the table insertion
$sql_data_array = array(
'customers_id' => $customer_id,
'entry_gender' => $paypal_ec_payer_info['payer_gender'],
'entry_firstname' => $paypal_ec_payer_info['payer_firstname'],
'entry_lastname' => $paypal_ec_payer_info['payer_lastname'],
'entry_street_address' => $paypal_ec_payer_info['ship_street_1'],
'entry_suburb' => $paypal_ec_payer_info['ship_street_2'],
'entry_city' => $paypal_ec_payer_info['ship_city'],
'entry_zone_id' => $state_id,
'entry_postcode' => $paypal_ec_payer_info['ship_postal_code'],
'entry_country_id' => $country_id);
if ($state_id > 0) {
$sql_data_array['entry_zone_id'] = $state_id;
$sql_data_array['entry_state'] = '';
} else {
$sql_data_array['entry_zone_id'] = 0;
$sql_data_array['entry_state'] = $paypal_ec_payer_info['ship_state'];
}
// insert the data发现是这里没有获取到买家的送货地址继续
zen_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);
// grab the address_id (last insert id)
$address_id = $db->Insert_ID();
// set the address id lookup for the customer
$sql = "UPDATE " . TABLE_CUSTOMERS . "
SET customers_default_address_id = :addrID
WHERE customers_id = :custID";
$sql = $db->bindVars($sql, ':addrID', $address_id, 'integer');
$sql = $db->bindVars($sql, ':custID', $customer_id, 'integer');
$db->Execute($sql);
// insert the new customer_id into the customers info table for consistency
$sql = "INSERT INTO " . TABLE_CUSTOMERS_INFO . "
(customers_info_id, customers_info_number_of_logons, customers_info_date_account_created)
VALUES (:custID, 0, now())";
$sql = $db->bindVars($sql, ':custID', $customer_id, 'integer');
$db->Execute($sql);
// send Welcome Email if appropriate
if ($this->new_acct_notify == 'Yes') {
// require the language file
global $language_page_directory, $template_dir;
if (!isset($language_page_directory)) $language_page_directory = DIR_WS_LANGUAGES . $_SESSION['language'] . '/';
if (file_exists($language_page_directory . $template_dir . '/create_account.php')) {
$template_dir_select = $template_dir . '/';
} else {
$template_dir_select = '';
}
require($language_page_directory . $template_dir_select . '/create_account.php');
// set the mail text
$email_text = sprintf(EMAIL_GREET_NONE, $paypal_ec_payer_info['payer_firstname']) . EMAIL_WELCOME . EMAIL_TEXT;
$email_text .= "\n\n" . EMAIL_EC_ACCOUNT_INFORMATION . "\nUsername: " . $paypal_ec_payer_info['payer_email'] . "\nPassword: " . $password . "\n\n";
$email_text .= EMAIL_CONTACT;
// send the mail
zen_mail($paypal_ec_payer_info['payer_firstname'] . " " . $paypal_ec_payer_info['payer_lastname'], $paypal_ec_payer_info['payer_email'], EMAIL_SUBJECT, $email_text, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, array('EMAIL_MESSAGE_HTML'=>nl2br($email_text)), 'welcome');
// set the express checkout temp -- false means the account is no longer "only" for EC ... it'll be permanent
$_SESSION['paypal_ec_temp'] = false;
} else {
// Make it a temporary account that'll be deleted once they've checked out
$sql = "UPDATE " . TABLE_CUSTOMERS . "
SET customers_paypal_ec = 1
WHERE customers_id = :custID ";
$sql = $db->bindVars($sql, ':custID', $customer_id, 'integer');
$db->Execute($sql);
// set the boolean ec temp value since we created account strictly for EC purposes
$_SESSION['paypal_ec_temp'] = true;
}
// hook notifier class vis a vis account-creation
$this->notify('NOTIFY_LOGIN_SUCCESS_VIA_CREATE_ACCOUNT');
} else {
// set the boolean ec temp value for the account to false, since we didn't have to create one
$_SESSION['paypal_ec_temp'] = false;
}
// log the user in with the email sent back from paypal response
$this->user_login($_SESSION['paypal_ec_payer_info']['payer_email'], false);
// debug
$this->zcLog('ec_step2_finish - 7', 'Auto-Logged customer in. (' . $_SESSION['paypal_ec_payer_info']['payer_email'] . ') (' . $_SESSION['customer_id'] . ')' . "\n" . '$_SESSION[paypal_ec_temp]=' . $_SESSION['paypal_ec_temp']);
// This is the address matching section
// try to match it first
// note: this is by no means 100%这里是当网站已有这个用户的时候的操作比如写入买家送货地址等等
$address_book_id = $this->findMatchingAddressBookEntry($_SESSION['customer_id'], $order->delivery);
// no match add the record
if (!$address_book_id) {
$address_book_id = $this->addAddressBookEntry($_SESSION['customer_id'], $order->delivery, false);
if (!$address_book_id) {
$address_book_id = $_SESSION['customer_default_address_id'];
}
}
// set the sendto to the address
$_SESSION['sendto'] = $address_book_id;
// set billto in the session
$_SESSION['billto'] = $_SESSION['customer_default_address_id'];
// select a shipping method, based on cheapest available option
if (MODULE_PAYMENT_PAYPALWPP_AUTOSELECT_CHEAPEST_SHIPPING == 'Yes') $this->setShippingMethod();
// debug
$this->zcLog('ec_step2_finish - 8', 'Exiting via terminateEC (from originally-not-logged-in mode).' . "\n" . 'Selected address: ' . $address_book_id . "\nOriginal was: " . $original_default_address_id . "\nprepared data: " . print_r($order->delivery, true));
// send the user on
if ($_SESSION['paypal_ec_markflow'] == 1) {
$this->terminateEC('', false, FILENAME_CHECKOUT_PROCESS);
} else {
$this->terminateEC('', false, FILENAME_CHECKOUT_CONFIRMATION);
}
}
}
/**
-
Determine the appropriate shipping method if applicable
-
By default, selects the lowest-cost quote
*/
function setShippingMethod() {
global $total_count, $total_weight;
// ensure that cart contents is calculated properly for weight and value
if (!isset($total_weight)) $total_weight = $_SESSION[‘cart’]->show_weight();
if (!isset($total_count)) $total_count = $_SESSION[‘cart’]->count_contents();
// set the shipping method if one is not already set
// defaults to the cheapest shipping method
if ( !$_SESSION[‘shipping’] || ( $_SESSION[‘shipping’] && ($_SESSION[‘shipping’] == false) && (zen_count_shipping_modules() > 1) ) ) {
require_once(DIR_WS_CLASSES . ‘http_client.php’);
require_once(DIR_WS_CLASSES . ‘shipping.php’);
$shipping_Obj = new shipping;// generate the quotes
$shipping_Obj->quote();// set the cheapest one
$_SESSION[‘shipping’] = $shipping_Obj->cheapest();
}
}
$order->customer $order->delivery $order->billing[/code]这几个变量数组无法赋值原因 $order 是全局变量 为什么他无法赋值呢