e コマース用の wordpress テーマ プラグインでは、Cookie を設定する 2 つの ajax/php スクリプトがあります (両方とも同じディレクトリにあります) ajax 呼び出しは同じ "cart.js" から設定されます。カートが作成または更新されます。2 つ目は、カートが PayPal に渡される前に、顧客/ユーザーが存在するかどうかを確認するか、または新たに作成し、どちらの場合も、まだログインしていない場合はログインします。そのため、paypal から戻ると、顧客/ユーザー (現在ログイン中) には、注文のステータス (新規および旧)の概要/レビューが表示されます。
私の WAMP 開発スタックでは、これは問題なく動作しますが、ホストされた (Linux) インストールでは、cart_cookie スクリプトは期待どおりに動作しますが、checkout/customer_cookie はスローされます...
[14-May-2013 02:08:50]
PHP Warning: session_start()
[<a href='function.session-start'>function.session-start</a>]:
Cannot send session cache limiter - headers already sent
(output started at /home2/alternam/public_html/demo/wp-content/themes/AM_Wallaby_Kids/checkout.php:2)
in /home2/alternam/public_html/demo/wp-content/plugins/cat-man/catalog-manager.php on line 23
その後、ユーザーはログインせず、カートは変換されません(関連する顧客データで更新されます)。これを最小限に抑える方法を見つけたいと思いますが、プラットフォーム間で 2 つのスクリプトの動作が異なる理由がわからないため、長い投稿について事前にお詫びし、両方を以下にすべて含めて、質問します。誰かが格差の明白な理由を見ることができれば? お待ち頂きまして、ありがとうございます。
PS php 5.2を実行しているWAMPとLAMPの両方のスタック
cart_add.php (WAMP && LAMP の両方で動作)
<?php
ob_start();
require_once(preg_replace("/wp-content.*/","wp-load.php",__FILE__));
ob_end_clean();
$ud_cart = $product_name = $product_url = $reset = "";
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);# Sanitize Post Input
foreach ($_POST as $key => $val)
{ if(!is_array($val)) $$key = html_entity_decode($val,ENT_QUOTES);
else $$key = $val;
}
if($ud_cart)
{ $reset =1;
$amt_cart[0] = $cart_id;
if(@$items) foreach($items as $key => $item )$amt_cart[] = $item;
$amt_cart = serialize($amt_cart);
}
if($reset)
{ // Initiated from the cart (tpl_cart.php on page load) to remove out-of-stock items
// from OLD CARTS -- where items have gone out-of-stock since cart created -- OR
// to simply update/remove cart items upon user request (user clicks Update|Remove)
if($amt_cart)
{ $amt_cart = stripslashes($amt_cart);
setcookie(AMART_CART, $amt_cart, time()+60*60*24*90, COOKIEPATH, COOKIE_DOMAIN);
}
exit;
}
// Create Cart, and add, update, or remove Cart-Items from within the catalog gallery && product detail pages
$add = array("product_id" => $product_id, "product_name" => $product_name, "product_type" => $product_type,"product_url" => $product_url,"qty" => $qty);
$update = "";
if( isset( $_COOKIE[AMART_CART] ) )
{ $amt_cart = stripslashes($_COOKIE[AMART_CART]);
$amt_cart = unserialize($amt_cart);
foreach($amt_cart as $key => $item)
{ if($key == 0 ) $amt_cart_id = $item;
else
{ foreach($item as $attr => $value)
{ if($product_id != $value) continue;
else
{ $update = 1;
if($qty == 0 )
{ unset($amt_cart[$key]);
break;
} else $amt_cart[$key]['qty'] = $qty;
}
}
}
}
if(!$update) $amt_cart[] = $add;
setcookie(AMART_CART, serialize($amt_cart), time()+60*60*24*90, COOKIEPATH, COOKIE_DOMAIN);
}
else
{ unset($_SESSION[STORE_ID]['dest_zip'], $_SESSION[STORE_ID]['dest_ctry']);
$amt_cart[0] = uniqid(AMART_CART);
$amt_cart[] = $add;
setcookie(AMART_CART, serialize($amt_cart), time()+60*60*24*90, COOKIEPATH, COOKIE_DOMAIN);
}
?>
checkout.php (WAMP で動作、LAMP で失敗)
<?php
// TPL CART POSTS VIA AJAX CALL IN cart.js
ob_start();
require_once(preg_replace("/wp-content.*/","wp-load.php",__FILE__));
ob_end_clean();
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
global $current_user, $wpfx;
$buyer_address1 = $buyer_address2 = $buyer_city = $buyer_region = $buyer_postal_code = $buyer_country = $buyer_ctry_code ="";
foreach ($_POST as $key => $val) $$key = $val;
foreach($buyer as $key => $val) $$key = $val;
$user_is_admin = current_user_can('manage_options');
if(!is_user_logged_in() || $user_is_admin )
{ if($userID = email_exists($email))
{ $user_info = $user_info = get_userdata($userID);
$user_login = $user_info->user_login;
$display_name = $user_info->display_name;
$welcome = "Welcome Back $display_name!";
}
if(@$welcome)
{ if(!$user_is_admin )
{ if(!$user_cnfm) die($welcome);
$auth = get_object_vars(wp_authenticate($user_login, $user_pass));
if(array_key_exists('errors',$auth)) die("Password Error");
wp_set_auth_cookie( $userID, true);
wp_set_current_user($userID, $user_login);
}
update_user_meta( $userID, 'customer', 1);
}
else
{ $buyer_name = "$buyer_first $buyer_last";
$ship_to_name = "$first_name $last_name";
if($ship_to_self)
{ foreach ( $ctry_opts as $key=>$value ) if (strcasecmp($country, $value) == 0) $buyer_country = $key;
$buyer_address1 = $address1;
$buyer_address2 = $address2;
$buyer_city = $city;
$buyer_region = $state;
$buyer_postal_code = $zip;
$buyer_ctry_code =strtolower($country);
} else foreach ( $ctry_opts as $key=>$value ) if ($buyer_ctry_code == $value) $buyer_country = $key;
$userdata = $user_cookie = array(
'user_login' => $email,
'user_email'=> $email,
'user_pass'=>$user_pass,
'first_name'=>$buyer_first,
'last_name'=>$buyer_last,
'display_name' =>$buyer_name,
'address1' => $buyer_address1,//null if not ship to self
'address2' => $buyer_address2,//null if not ship to self
'city' => $buyer_city,//google guess if not ship to self
'region' => $buyer_region,//google guess if not ship to self
'postal_code' => $buyer_postal_code,//null if not ship to self
'country' => $buyer_country,//google guess if not ship to self
'ctry_code' => $buyer_ctry_code,//google guess if not ship to self
'customer' => '1'
);
$userID = wp_insert_user( $userdata );
if(!$user_is_admin)
{ wp_set_auth_cookie( $userID, true);
wp_set_current_user($userID, $email);
}
unset($user_cookie['user_login'],$user_cookie['user_pass'],$user_cookie['display_name']);
setcookie('AMART_CUSTOMER', serialize($user_cookie), time()+60*60*24*180, COOKIEPATH, COOKIE_DOMAIN);
}
}
if(is_user_logged_in())
{ if(!$user_is_admin) $userID = $current_user->ID;
$cart_id = $item_name;
$cart = $wpdb->get_row("SELECT * FROM {$wpfx}amt_carts WHERE cart_id = '$cart_id'", ARRAY_A);
if( $cart['host_checkout'] && isset($store_options->paypal_live) && $store_options->paypal_live !=='false')
$host_checkout = true;
$ship_to = serialize( array('first_name' => $first_name,'last_name' => $last_name,'address1' => $address1,'address2' => $address2,'city' => $city, 'state' => $state,'postal_code' => $zip,'country' =>$country));
$attributes = array('ship_to' => $ship_to, 'customer_id'=>$userID, 'checkout_date'=>$now);
$where = array('cart_id' => $cart_id);
$wpdb->update("{$wpfx}amt_carts", $attributes,$where);
}
?>