[Svn-src-all:1267] [version-2_5-dev 20156] LC_Page_Mypage_DeliveryAddr リファクタリング
kimoto
admin @ mail.ec-cube.net
2011年 2月 12日 (土) 19:01:02 JST
Subversion committed to /home/svn/open 20156
http://svn.ec-cube.net/open_trac/changeset/20156
┌────────────────────────────┐
│更新者 : kimoto │
│更新日時: 2011-02-12 19:01:02 +0900 (土, 12 2月 2011)│
└────────────────────────────┘
Log:
--------------------------------------------------------
LC_Page_Mypage_DeliveryAddr リファクタリング
* そもそも別配送先の登録は別クラスですべきではないか
* 購入遷移での配送先の登録もMypageのページクラスでするべきではない
Changed: [U:修正,A:追加,D:削除]
--------------------------------------------------------
U branches/version-2_5-dev/data/class/helper/SC_Helper_Customer.php
U branches/version-2_5-dev/data/class/pages/mypage/LC_Page_AbstractMypage.php
U branches/version-2_5-dev/data/class/pages/mypage/LC_Page_Mypage_DeliveryAddr.php
変更: branches/version-2_5-dev/data/class/helper/SC_Helper_Customer.php
===================================================================
--- branches/version-2_5-dev/data/class/helper/SC_Helper_Customer.php 2011-02-12 05:44:10 UTC (rev 20155)
+++ branches/version-2_5-dev/data/class/helper/SC_Helper_Customer.php 2011-02-12 10:01:02 UTC (rev 20156)
@@ -296,6 +296,7 @@
*/
function sfCustomerEntryParam (&$objFormParam) {
SC_Helper_Customer_Ex::sfCustomerCommonParam($objFormParam);
+ SC_Helper_Customer_Ex::sfCustomerRegisterParam($objFormParam);
}
/**
@@ -307,6 +308,7 @@
*/
function sfCustomerMypageParam (&$objFormParam) {
SC_Helper_Customer_Ex::sfCustomerCommonParam($objFormParam);
+ SC_Helper_Customer_Ex::sfCustomerRegisterParam($objFormParam);
if (SC_Display::detectDevice() !== DEVICE_TYPE_MOBILE){
$objFormParam->addParam('携帯メールアドレス', "email_mobile", MTEXT_LEN, "a", array("NO_SPTAB", "EMAIL_CHECK", "SPTAB_CHECK" ,"EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
$objFormParam->addParam('携帯メールアドレス(確認)', "email_mobile02", MTEXT_LEN, "a", array("NO_SPTAB", "EMAIL_CHECK","SPTAB_CHECK" , "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"), "", false);
@@ -314,29 +316,47 @@
}
/**
- * 会員フォーム共通
+ * お届け先フォーム初期化
*
* @param mixed $objFormParam
* @access public
* @return void
*/
+ function sfCustomerOtherDelivParam (&$objFormParam) {
+ SC_Helper_Customer_Ex::sfCustomerCommonParam($objFormParam);
+ $objFormParam->addParam("", 'other_deliv_id');
+ }
+
+ /**
+ * 会員共通
+ *
+ * @param mixed $objFormParam
+ * @access public
+ * @return void
+ */
function sfCustomerCommonParam (&$objFormParam) {
-
$objFormParam->addParam("お名前(姓)", 'name01', STEXT_LEN, "aKV", array("EXIST_CHECK", "NO_SPTAB", "SPTAB_CHECK" ,"MAX_LENGTH_CHECK"));
$objFormParam->addParam("お名前(名)", 'name02', STEXT_LEN, "aKV", array("EXIST_CHECK", "NO_SPTAB", "SPTAB_CHECK" , "MAX_LENGTH_CHECK"));
$objFormParam->addParam("お名前(フリガナ・姓)", 'kana01', STEXT_LEN, "CKV", array("EXIST_CHECK", "NO_SPTAB", "SPTAB_CHECK" ,"MAX_LENGTH_CHECK", "KANA_CHECK"));
$objFormParam->addParam("お名前(フリガナ・名)", 'kana02', STEXT_LEN, "CKV", array("EXIST_CHECK", "NO_SPTAB", "SPTAB_CHECK" ,"MAX_LENGTH_CHECK", "KANA_CHECK"));
- $objFormParam->addParam("パスワード", 'password', STEXT_LEN, "a", array("EXIST_CHECK", "SPTAB_CHECK" ,"ALNUM_CHECK"));
- $objFormParam->addParam("パスワード確認用の質問", "reminder", STEXT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK"));
- $objFormParam->addParam("パスワード確認用の質問の答え", "reminder_answer", STEXT_LEN, "aKV", array("EXIST_CHECK","SPTAB_CHECK" , "MAX_LENGTH_CHECK"));
$objFormParam->addParam("郵便番号1", "zip01", ZIP01_LEN, "n", array("EXIST_CHECK", "SPTAB_CHECK" ,"NUM_CHECK", "NUM_COUNT_CHECK"));
$objFormParam->addParam("郵便番号2", "zip02", ZIP02_LEN, "n", array("EXIST_CHECK", "SPTAB_CHECK" ,"NUM_CHECK", "NUM_COUNT_CHECK"));
$objFormParam->addParam("都道府県", 'pref', INT_LEN, "n", array("EXIST_CHECK","NUM_CHECK"));
$objFormParam->addParam("住所1", "addr01", MTEXT_LEN, "aKV", array("EXIST_CHECK","SPTAB_CHECK" ,"MAX_LENGTH_CHECK"));
$objFormParam->addParam("住所2", "addr02", MTEXT_LEN, "aKV", array("EXIST_CHECK","SPTAB_CHECK" ,"MAX_LENGTH_CHECK"));
- $objFormParam->addParam("お電話番号1", 'tel01', TEL_ITEM_LEN, "n", array("EXIST_CHECK","SPTAB_CHECK" ));
- $objFormParam->addParam("お電話番号2", 'tel02', TEL_ITEM_LEN, "n", array("EXIST_CHECK","SPTAB_CHECK" ));
- $objFormParam->addParam("お電話番号3", 'tel03', TEL_ITEM_LEN, "n", array("EXIST_CHECK","SPTAB_CHECK" ));
+ $objFormParam->addParam("お電話番号1", 'tel01', TEL_ITEM_LEN, "n", array("EXIST_CHECK","SPTAB_CHECK"));
+ $objFormParam->addParam("お電話番号2", 'tel02', TEL_ITEM_LEN, "n", array("EXIST_CHECK","SPTAB_CHECK"));
+ $objFormParam->addParam("お電話番号3", 'tel03', TEL_ITEM_LEN, "n", array("EXIST_CHECK","SPTAB_CHECK"));
+ }
+
+ /*
+ * 会員登録共通
+ *
+ */
+ function sfCustomerRegisterParam (&$objFormParam) {
+ $objFormParam->addParam("パスワード", 'password', STEXT_LEN, "a", array("EXIST_CHECK", "SPTAB_CHECK" ,"ALNUM_CHECK"));
+ $objFormParam->addParam("パスワード確認用の質問", "reminder", STEXT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK"));
+ $objFormParam->addParam("パスワード確認用の質問の答え", "reminder_answer", STEXT_LEN, "aKV", array("EXIST_CHECK","SPTAB_CHECK" , "MAX_LENGTH_CHECK"));
$objFormParam->addParam("性別", "sex", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK"));
$objFormParam->addParam("職業", "job", INT_LEN, "n", array("NUM_CHECK"));
$objFormParam->addParam("年", "year", INT_LEN, "n", array("MAX_LENGTH_CHECK"), "", false);
@@ -356,6 +376,11 @@
}
}
+ function sfCustomerOtherDelivErrorCheck(&$objFormParam) {
+ $objErr = SC_Helper_Customer_Ex::sfCustomerCommonErrorCheck(&$objFormParam);
+ return $objErr->arrErr;
+ }
+
/**
* 会員登録エラーチェック
*
@@ -364,7 +389,9 @@
* @return array エラーの配列
*/
function sfCustomerEntryErrorCheck(&$objFormParam) {
- $objErr->arrErr = SC_Helper_Customer_Ex::sfCustomerCommonErrorCheck(&$objFormParam);
+ $objErr = SC_Helper_Customer_Ex::sfCustomerCommonErrorCheck(&$objFormParam);
+ $objErr = SC_Helper_Customer_Ex::sfCustomerRegisterErrorCheck(&$objErr);
+
return $objErr->arrErr;
}
@@ -380,7 +407,8 @@
$objFormParam->toLower('email_mobile');
$objFormParam->toLower('email_mobile02');
- $objErr->arrErr = SC_Helper_Customer_Ex::sfCustomerCommonErrorCheck($objFormParam);
+ $objErr = SC_Helper_Customer_Ex::sfCustomerCommonErrorCheck($objFormParam);
+ $objErr = SC_Helper_Customer_Ex::sfCustomerRegisterErrorCheck(&$objErr);
if (isset($objErr->arrErr['password']) && $objFormParam->getValue('password') == DEFAULT_PASSWORD) {
unset($objErr->arrErr['password']);
@@ -411,6 +439,14 @@
$objErr->doFunc(array("お電話番号", "tel01", "tel02", "tel03"),array("TEL_CHECK"));
$objErr->doFunc(array("郵便番号", "zip01", "zip02"), array("ALL_EXIST_CHECK"));
+
+ return $objErr;
+ }
+
+ /*
+ * 会員登録編集共通
+ */
+ function sfCustomerRegisterErrorCheck(&$objErr) {
$objErr->doFunc(array("生年月日", "year", "month", "day"), array("CHECK_BIRTHDAY"));
if (SC_Display::detectDevice() !== DEVICE_TYPE_MOBILE){
@@ -422,6 +458,7 @@
// 現会員の判定 → 現会員もしくは仮登録中は、メアド一意が前提になってるので同じメアドで登録不可
$objErr->doFunc(array("メールアドレス", "email"), array("CHECK_REGIST_CUSTOMER_EMAIL"));
- return $objErr->arrErr;
+ return $objErr;
}
+
}
変更: branches/version-2_5-dev/data/class/pages/mypage/LC_Page_AbstractMypage.php
===================================================================
--- branches/version-2_5-dev/data/class/pages/mypage/LC_Page_AbstractMypage.php 2011-02-12 05:44:10 UTC (rev 20155)
+++ branches/version-2_5-dev/data/class/pages/mypage/LC_Page_AbstractMypage.php 2011-02-12 10:01:02 UTC (rev 20156)
@@ -60,7 +60,7 @@
$objCustomer = new SC_Customer();
// ログインしていない場合は必ずログインページを表示する
- if(!$objCustomer->isLoginSuccess(true)) {
+ if($objCustomer->isLoginSuccess(true) === false) {
// クッキー管理クラス
$objCookie = new SC_Cookie(COOKIE_EXPIRE);
// クッキー判定(メールアドレスをクッキーに保存しているか)
変更: branches/version-2_5-dev/data/class/pages/mypage/LC_Page_Mypage_DeliveryAddr.php
===================================================================
--- branches/version-2_5-dev/data/class/pages/mypage/LC_Page_Mypage_DeliveryAddr.php 2011-02-12 05:44:10 UTC (rev 20155)
+++ branches/version-2_5-dev/data/class/pages/mypage/LC_Page_Mypage_DeliveryAddr.php 2011-02-12 10:01:02 UTC (rev 20156)
@@ -43,9 +43,9 @@
*/
function init() {
parent::init();
- $this->tpl_title = "お届け先の追加・変更";
- $masterData = new SC_DB_MasterData_Ex();
- $this->arrPref= $masterData->getMasterData('mtb_pref');
+ $this->tpl_title = "お届け先の追加・変更";
+ $masterData = new SC_DB_MasterData_Ex();
+ $this->arrPref = $masterData->getMasterData('mtb_pref');
$this->httpCacheControl('nocache');
}
@@ -66,73 +66,46 @@
* @return void
*/
function action() {
- $objQuery = new SC_Query();
+ $objQuery = new SC_Query();
$objCustomer = new SC_Customer();
- $ParentPage = MYPAGE_DELIVADDR_URLPATH;
+ $ParentPage = MYPAGE_DELIVADDR_URLPATH;
// GETでページを指定されている場合には指定ページに戻す
if (isset($_GET['page'])) {
- $ParentPage = htmlspecialchars($_GET['page'],ENT_QUOTES);
- }else if(isset($_POST['ParentPage'])) {
- $ParentPage = htmlspecialchars($_POST['ParentPage'],ENT_QUOTES);
+ $ParentPage = htmlspecialchars($_GET['page'], ENT_QUOTES);
+ } else if (isset($_POST['ParentPage'])) {
+ $ParentPage = htmlspecialchars($_POST['ParentPage'], ENT_QUOTES);
}
$this->ParentPage = $ParentPage;
/*
* ログイン判定 及び 退会判定
* 未ログインでも, 複数配送設定ページからのアクセスの場合は表示する
+ *
+ * TODO 購入遷移とMyPageで別クラスにすべき
*/
if (!$objCustomer->isLoginSuccess(true) && $ParentPage != MULTIPLE_URLPATH){
$this->tpl_onload = "fnUpdateParent('". $this->getLocation($_POST['ParentPage']) ."'); window.close();";
}
+ // $_GET['other_deliv_id'] のあるなしで追加か編集か判定しているらしい
if (!isset($_GET['other_deliv_id'])) $_GET['other_deliv_id'] = "";
+ $_SESSION['other_deliv_id'] = $_GET['other_deliv_id'];
- //TODO 要リファクタリング(MODE if利用)
- if ($this->getMode() == null){
- $_SESSION['other_deliv_id'] = $_GET['other_deliv_id'];
- }
+ // パラメータ管理クラス,パラメータ情報の初期化
+ $objFormParam = new SC_FormParam();
+ SC_Helper_Customer_Ex::sfCustomerOtherDelivParam($objFormParam);
+ $objFormParam->setParam($_POST);
+ $this->arrForm = $objFormParam->getHashArray();
- if ($_GET['other_deliv_id'] != ""){
- //不正アクセス判定
- $flag = $objQuery->count("dtb_other_deliv", "customer_id=? AND other_deliv_id=?", array($objCustomer->getValue("customer_id"), $_SESSION['other_deliv_id']));
- if (!$objCustomer->isLoginSuccess(true) || $flag == 0){
- SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
- }
- }
-
- //別のお届け先DB登録用カラム配列
- $arrRegistColumn = array(
- array("column" => "name01", "convert" => "aKV"),
- array("column" => "name02", "convert" => "aKV"),
- array("column" => "kana01", "convert" => "CKV"),
- array("column" => "kana02", "convert" => "CKV"),
- array("column" => "zip01", "convert" => "n"),
- array("column" => "zip02", "convert" => "n"),
- array("column" => "pref", "convert" => "n"),
- array("column" => "addr01", "convert" => "aKV"),
- array("column" => "addr02", "convert" => "aKV"),
- array("column" => "tel01", "convert" => "n"),
- array("column" => "tel02", "convert" => "n"),
- array("column" => "tel03", "convert" => "n"),
- );
-
-
- if ($_GET['other_deliv_id'] != ""){
- //別のお届け先情報取得
- $arrOtherDeliv = $objQuery->select("*", "dtb_other_deliv", "other_deliv_id=? ", array($_SESSION['other_deliv_id']));
- $this->arrForm = $arrOtherDeliv[0];
- }
-
switch ($this->getMode()) {
+ // 入力は必ずedit
case 'edit':
- $_POST = $this->lfConvertParam($_POST,$arrRegistColumn);
- $this->arrErr = $this->lfErrorCheck($_POST);
- if ($this->arrErr){
- foreach ($_POST as $key => $val){
- if ($val != "") $this->arrForm[$key] = $val;
- }
- } else {
+ $this->arrErr = SC_Helper_Customer_Ex::sfCustomerOtherDelivErrorCheck($objFormParam);
+ // 入力エラーなし
+ if(empty($this->arrErr)) {
+
+ // TODO ここでやるべきではない
$validUrl = array(MYPAGE_DELIVADDR_URLPATH,
DELIV_URLPATH,
MULTIPLE_URLPATH);
@@ -143,20 +116,42 @@
}
if ($objCustomer->isLoginSuccess(true)) {
- $this->lfRegistData($_POST, $arrRegistColumn, $objCustomer);
+ $this->lfRegistData($objFormParam, $objCustomer->getValue("customer_id"));
} else {
- $this->lfRegistDataNonMember($_POST, $arrRegistColumn);
+ $this->lfRegistDataNonMember($objFormParam);
}
- if(Net_UserAgent_Mobile::isMobile() === true) {
+ if(SC_Display::detectDevice() === DEVICE_TYPE_MOBILE) {
// モバイルの場合、元のページに遷移
SC_Response_Ex::sendRedirect($this->getLocation($_POST['ParentPage']));
exit;
}
}
break;
+ case 'multiple':
+ // 複数配送先用?
+ break;
+ default :
+
+ if ($_GET['other_deliv_id'] != ""){
+ //不正アクセス判定
+ $flag = $objQuery->count("dtb_other_deliv",
+ "customer_id = ? AND other_deliv_id = ?",
+ array($objCustomer->getValue("customer_id"),
+ $_SESSION['other_deliv_id']));
+
+ if (!$objCustomer->isLoginSuccess(true) || $flag == 0){
+ SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
+ }
+
+ //別のお届け先情報取得
+ $arrOtherDeliv = $objQuery->select("*", "dtb_other_deliv", "other_deliv_id = ? ", array($_SESSION['other_deliv_id']));
+ $this->arrForm = $arrOtherDeliv[0];
+ }
+ break;
}
- if(Net_UserAgent_Mobile::isMobile() === true) {
+
+ if (SC_Display::detectDevice() === DEVICE_TYPE_MOBILE) {
$this->tpl_mainpage = 'mypage/delivery_addr.tpl';
} else {
$this->setTemplate('mypage/delivery_addr.tpl');
@@ -172,65 +167,44 @@
parent::destroy();
}
- /* エラーチェック */
- function lfErrorCheck() {
- $objErr = new SC_CheckError();
- $objErr->doFunc(array("お名前(姓)", 'name01', STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
- $objErr->doFunc(array("お名前(名)", 'name02', STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK", "MAX_LENGTH_CHECK"));
- $objErr->doFunc(array("お名前(フリガナ・姓)", 'kana01', STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK", "MAX_LENGTH_CHECK", "KANA_CHECK"));
- $objErr->doFunc(array("お名前(フリガナ・名)", 'kana02', STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK", "MAX_LENGTH_CHECK", "KANA_CHECK"));
- $objErr->doFunc(array("郵便番号1", "zip01", ZIP01_LEN ) ,array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
- $objErr->doFunc(array("郵便番号2", "zip02", ZIP02_LEN ) ,array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
- $objErr->doFunc(array("郵便番号", "zip01", "zip02"), array("ALL_EXIST_CHECK"));
- $objErr->doFunc(array("都道府県", 'pref'), array("SELECT_CHECK","NUM_CHECK"));
- $objErr->doFunc(array("住所(1)", "addr01", MTEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
- $objErr->doFunc(array("住所(2)", "addr02", MTEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
- $objErr->doFunc(array("電話番号1", 'tel01'), array("EXIST_CHECK","NUM_CHECK"));
- $objErr->doFunc(array("電話番号2", 'tel02'), array("EXIST_CHECK","NUM_CHECK"));
- $objErr->doFunc(array("電話番号3", 'tel03'), array("EXIST_CHECK","NUM_CHECK"));
- $objErr->doFunc(array("電話番号", "tel01", "tel02", "tel03") ,array("TEL_CHECK"));
- return $objErr->arrErr;
-
- }
-
/* 登録実行 */
- function lfRegistData($array, $arrRegistColumn, &$objCustomer) {
- $objQuery = new SC_Query();
- foreach ($arrRegistColumn as $data) {
- $arrRegist[ $data["column"] ] = $array[ $data["column"] ];
- }
+ function lfRegistData($objFormParam, $customer_id) {
+ $objQuery =& SC_Query::getSingletonInstance();
- $arrRegist['customer_id'] = $objCustomer->getvalue('customer_id');
+ $arrRet = $objFormParam->getHashArray();
+ $sqlval = $objFormParam->getDbArray();
+ $sqlval['customer_id'] = $customer_id;
+
// 追加
- if (strlen($_POST['other_deliv_id'] == 0)) {
+ if (strlen($arrRet['other_deliv_id'] == 0)) {
// 別のお届け先登録数の取得
- $deliv_count = $objQuery->count("dtb_other_deliv", "customer_id=?", array($objCustomer->getValue('customer_id')));
+ $deliv_count = $objQuery->count("dtb_other_deliv", "customer_id = ?", array($customer_id));
// 別のお届け先最大登録数に達している場合、エラー
if ($deliv_count >= DELIV_ADDR_MAX) {
SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, "", false, '別のお届け先最大登録数に達しています。');
}
// 実行
- $arrRegist['other_deliv_id'] = $objQuery->nextVal('dtb_other_deliv_other_deliv_id');
- $objQuery->insert("dtb_other_deliv", $arrRegist);
+ $sqlval['other_deliv_id'] = $objQuery->nextVal('dtb_other_deliv_other_deliv_id');
+ $objQuery->insert("dtb_other_deliv", $sqlval);
// 変更
} else {
- $deliv_count = $objQuery->count("dtb_other_deliv","customer_id=? and other_deliv_id = ?" ,array($objCustomer->getValue('customer_id'), $_POST['other_deliv_id']));
+ $deliv_count = $objQuery->count("dtb_other_deliv","customer_id = ? AND other_deliv_id = ?" ,array($customer_id, $arrRet['other_deliv_id']));
if ($deliv_count != 1) {
SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, "", false, '一致する別のお届け先がありません。');
}
// 実行
- $objQuery->update("dtb_other_deliv", $arrRegist,
- "other_deliv_id = "
- . SC_Utils_Ex::sfQuoteSmart($array["other_deliv_id"]));
+ $objQuery->update("dtb_other_deliv", $sqlval, "other_deliv_id = ?", array($arrRet['other_deliv_id']));
}
}
- function lfRegistDataNonMember($array, $arrRegistColumn) {
+ function lfRegistDataNonMember($objFormParam) {
+ $arrRegistColumn = $objFormParam->getDbArray();
+
foreach ($arrRegistColumn as $data) {
$arrRegist['shipping_' . $data["column"] ] = $array[ $data["column"] ];
}
@@ -240,30 +214,5 @@
$_SESSION['shipping'][] = $arrRegist;
}
}
-
- //---- 取得文字列の変換
- function lfConvertParam($array, $arrRegistColumn) {
- /*
- * 文字列の変換
- * K : 「半角(ハンカク)片仮名」を「全角片仮名」に変換
- * C : 「全角ひら仮名」を「全角かた仮名」に変換
- * V : 濁点付きの文字を一文字に変換。"K","H"と共に使用します
- * n : 「全角」数字を「半角(ハンカク)」に変換
- * a : 全角英数字を半角英数字に変換する
- */
- // カラム名とコンバート情報
- foreach ($arrRegistColumn as $data) {
- $arrConvList[ $data["column"] ] = $data["convert"];
- }
-
- // 文字変換
- foreach ($arrConvList as $key => $val) {
- // POSTされてきた値のみ変換する。
- if(strlen(($array[$key])) > 0) {
- $array[$key] = mb_convert_kana($array[$key] ,$val);
- }
- }
- return $array;
- }
}
?>
Svn-src-all メーリングリストの案内