/**
  * Page のAction.
  *
  * @return void
  */
 public function action()
 {
     $objCustomer = new SC_Customer_Ex();
     $customer_id = $objCustomer->getValue('customer_id');
     $objAddress = new SC_Helper_Address_Ex();
     $objFormParam = new SC_FormParam_Ex();
     $this->lfInitParam($objFormParam);
     $objFormParam->setParam($_POST);
     $objFormParam->convParam();
     switch ($this->getMode()) {
         // お届け先の削除
         case 'delete':
             if ($objFormParam->checkError()) {
                 SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
                 SC_Response_Ex::actionExit();
             }
             if (!$objAddress->deleteAddress($objFormParam->getValue('other_deliv_id'), $customer_id)) {
                 SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', false, '別のお届け先を削除できませんでした。');
                 SC_Response_Ex::actionExit();
             }
             break;
             // スマートフォン版のもっと見るボタン用
         // スマートフォン版のもっと見るボタン用
         case 'getList':
             $arrData = $objFormParam->getHashArray();
             //別のお届け先情報
             $arrOtherDeliv = $objAddress->getList($customer_id, ($arrData['pageno'] - 1) * SEARCH_PMAX);
             //県名をセット
             $arrOtherDeliv = $this->setPref($arrOtherDeliv, $this->arrPref);
             $arrOtherDeliv['delivCount'] = count($arrOtherDeliv);
             $this->arrOtherDeliv = $arrOtherDeliv;
             echo SC_Utils_Ex::jsonEncode($this->arrOtherDeliv);
             SC_Response_Ex::actionExit();
             break;
             // お届け先の表示
         // お届け先の表示
         default:
             break;
     }
     //別のお届け先情報
     $this->arrOtherDeliv = $objAddress->getList($customer_id);
     //お届け先登録数
     $this->tpl_linemax = count($this->arrOtherDeliv);
     // 1ページあたりの件数
     $this->dispNumber = SEARCH_PMAX;
 }
 /**
  * @param SC_Helper_Address_Ex $objAddress
  * @param SC_FormParam $objFormParam
  */
 public function lfRegistData($objAddress, $objFormParam, $customer_id)
 {
     $arrRet = $objFormParam->getHashArray();
     $sqlval = $objFormParam->getDbArray();
     $sqlval['other_deliv_id'] = $arrRet['other_deliv_id'];
     $sqlval['customer_id'] = $customer_id;
     if (!$objAddress->registAddress($sqlval)) {
         SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', false, '別のお届け先を登録できませんでした。');
         SC_Response_Ex::actionExit();
     }
 }
 /**
  * Page のAction.
  *
  * @return void
  */
 function action()
 {
     $objCustomer = new SC_Customer_Ex();
     $objAddress = new SC_Helper_Address_Ex();
     $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);
         }
     }
     $this->ParentPage = $ParentPage;
     /*
      * ログイン判定 及び 退会判定
      * 未ログインでも, 複数配送設定ページからのアクセスの場合は表示する
      *
      * TODO 購入遷移とMyPageで別クラスにすべき
      */
     if (!$objCustomer->isLoginSuccess(true) && $ParentPage != MULTIPLE_URLPATH) {
         $this->tpl_onload = "fnUpdateParent('" . $this->getLocation($_POST['ParentPage']) . "'); window.close();";
     }
     // other_deliv_id のあるなしで追加か編集か判定しているらしい
     $_SESSION['other_deliv_id'] = $_REQUEST['other_deliv_id'];
     // パラメーター管理クラス,パラメーター情報の初期化
     $objFormParam = new SC_FormParam_Ex();
     $objAddress->setFormParam($objFormParam);
     $objFormParam->setParam($_POST);
     $this->arrForm = $objFormParam->getHashArray();
     switch ($this->getMode()) {
         // 入力は必ずedit
         case 'edit':
             $this->arrErr = $objAddress->errorCheck($objFormParam);
             // 入力エラーなし
             if (empty($this->arrErr)) {
                 // TODO ここでやるべきではない
                 if (in_array($_POST['ParentPage'], $this->validUrl)) {
                     $this->tpl_onload = "fnUpdateParent('" . $this->getLocation($_POST['ParentPage']) . "'); window.close();";
                 } else {
                     SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
                 }
                 if ($objCustomer->isLoginSuccess(true)) {
                     $this->lfRegistData($objAddress, $objFormParam, $objCustomer->getValue('customer_id'));
                 } else {
                     $this->lfRegistDataNonMember($objFormParam);
                 }
                 if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
                     // モバイルの場合、元のページに遷移
                     SC_Response_Ex::sendRedirect($this->getLocation($_POST['ParentPage']));
                     SC_Response_Ex::actionExit();
                 }
             }
             break;
         case 'multiple':
             // 複数配送先用
             break;
         default:
             if ($_GET['other_deliv_id'] != '') {
                 $arrOtherDeliv = $objAddress->getAddress($_SESSION['other_deliv_id']);
                 //不正アクセス判定
                 if (!$objCustomer->isLoginSuccess(true) || !$arrOtherDeliv) {
                     SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
                 }
                 //別のお届け先情報取得
                 $this->arrForm = $arrOtherDeliv;
             }
             break;
     }
     if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
         $this->tpl_mainpage = 'mypage/delivery_addr.tpl';
     } else {
         $this->setTemplate('mypage/delivery_addr.tpl');
     }
 }
 /**
  * お届け先チェックの値に応じて, お届け先情報を保存する.
  *
  * 会員住所がチェックされている場合は, 会員情報からお届け先を取得する.
  * その他のお届け先がチェックされている場合は, その他のお届け先からお届け先を取得する.
  * お届け先チェックの値が不正な場合は false を返す.
  *
  * @param  integer            $other_deliv_id
  * @param  string             $uniqid         受注一時テーブルのユニークID
  * @param  SC_Helper_Purchase $objPurchase    SC_Helper_Purchase インスタンス
  * @param  SC_Customer        $objCustomer    SC_Customer インスタンス
  * @param SC_Helper_Address_Ex $objAddress
  * @return boolean            お届け先チェックの値が妥当な場合 true
  */
 public function registerDeliv($other_deliv_id, $uniqid, &$objPurchase, &$objCustomer, $objAddress)
 {
     $arrValues = array();
     // 会員登録住所がチェックされている場合
     if ($other_deliv_id == 0) {
         $objPurchase->copyFromCustomer($arrValues, $objCustomer, 'shipping');
         // 別のお届け先がチェックされている場合
     } else {
         $arrOtherDeliv = $objAddress->getAddress($other_deliv_id, $objCustomer->getValue('customer_id'));
         if (!$arrOtherDeliv) {
             return false;
         }
         $objPurchase->copyFromOrder($arrValues, $arrOtherDeliv, 'shipping', '');
     }
     $objPurchase->saveShippingTemp($arrValues, $other_deliv_id);
     $objPurchase->saveOrderTemp($uniqid, $arrValues, $objCustomer);
     return true;
 }
 /**
  * 複数配送情報を一時保存する.
  *
  * 会員ログインしている場合は, その他のお届け先から住所情報を取得する.
  *
  * @param  integer            $uniqid       一時受注テーブルのユニークID
  * @param  SC_FormParam       $objFormParam SC_FormParam インスタンス
  * @param  SC_Customer        $objCustomer  SC_Customer インスタンス
  * @param  SC_Helper_Purchase $objPurchase  SC_Helper_Purchase インスタンス
  * @param SC_Helper_Address_Ex $objAddress
  * @return void
  */
 public function saveMultipleShippings($uniqid, &$objFormParam, &$objCustomer, &$objPurchase, &$objAddress)
 {
     $arrParams = $objFormParam->getSwapArray();
     foreach ($arrParams as $arrParam) {
         $other_deliv_id = $arrParam['shipping'];
         if ($objCustomer->isLoginSuccess(true)) {
             if ($other_deliv_id != 0) {
                 $otherDeliv = $objAddress->getAddress($other_deliv_id, $objCustomer->getValue('customer_id'));
                 if (!$otherDeliv) {
                     SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', false, "入力値が不正です。<br />正しい値を入力してください。");
                     SC_Response_Ex::actionExit();
                 }
                 foreach ($otherDeliv as $key => $val) {
                     $arrValues[$other_deliv_id]['shipping_' . $key] = $val;
                 }
             } else {
                 $objPurchase->copyFromCustomer($arrValues[0], $objCustomer, 'shipping');
             }
         } else {
             $arrValues = $objPurchase->getShippingTemp();
         }
         $arrItemTemp[$other_deliv_id][$arrParam['product_class_id']] += $arrParam['quantity'];
     }
     $objPurchase->clearShipmentItemTemp();
     foreach ($arrValues as $shipping_id => $arrVal) {
         $objPurchase->saveShippingTemp($arrVal, $shipping_id);
     }
     foreach ($arrItemTemp as $other_deliv_id => $arrProductClassIds) {
         foreach ($arrProductClassIds as $product_class_id => $quantity) {
             if ($quantity == 0) {
                 continue;
             }
             $objPurchase->setShipmentItemTemp($other_deliv_id, $product_class_id, $quantity);
         }
     }
     //不必要な配送先を削除
     foreach ($_SESSION['shipping'] as $id => $arrShipping) {
         if (!isset($arrShipping['shipment_item'])) {
             $objPurchase->unsetOneShippingTemp($id);
         }
     }
     // $arrValues[0] には, 購入者の情報が格納されている
     $objPurchase->saveOrderTemp($uniqid, $arrValues[0], $objCustomer);
 }
 /**
  * Page のプロセス.
  *
  * @return void
  */
 function action()
 {
     $objSiteSess = new SC_SiteSession_Ex();
     $objCartSess = new SC_CartSession_Ex();
     $objCustomer = new SC_Customer_Ex();
     $objPurchase = new SC_Helper_Purchase_Ex();
     $objFormParam = new SC_FormParam_Ex();
     $objAddress = new SC_Helper_Address_Ex();
     $this->tpl_uniqid = $objSiteSess->getUniqId();
     $objPurchase->verifyChangeCart($this->tpl_uniqid, $objCartSess);
     $this->cartKey = $objCartSess->getKey();
     // ログインチェック
     if (!$objCustomer->isLoginSuccess(true)) {
         SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
     }
     // ダウンロード商品の場合は、支払方法画面に転送
     if ($this->cartKey == PRODUCT_TYPE_DOWNLOAD) {
         $objPurchase->copyFromCustomer($sqlval, $objCustomer, 'shipping');
         $objPurchase->saveShippingTemp($sqlval);
         $objPurchase->saveOrderTemp($this->tpl_uniqid, $sqlval, $objCustomer);
         $objSiteSess->setRegistFlag();
         SC_Response_Ex::sendRedirect('payment.php');
         SC_Response_Ex::actionExit();
     }
     $this->lfInitParam($objFormParam);
     $objFormParam->setParam($_POST);
     $objFormParam->convParam();
     $arrErr = $objFormParam->checkError();
     if (!SC_Utils_Ex::isBlank($arrErr)) {
         SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true);
         SC_Response_Ex::actionExit();
     }
     $arrForm = $objFormParam->getHashArray();
     switch ($this->getMode()) {
         // 削除
         case 'delete':
             $objAddress->deleteAddress($arrForm['other_deliv_id']);
             break;
             // 会員登録住所に送る
         // 会員登録住所に送る
         case 'customer_addr':
             $objPurchase->unsetShippingTemp();
             $shipping_id = $arrForm['deliv_check'] == -1 ? 0 : $arrForm['deliv_check'];
             $success = $this->registerDeliv($shipping_id, $this->tpl_uniqid, $objPurchase, $objCustomer, $objAddress);
             if (!$success) {
                 SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true);
             }
             $objPurchase->setShipmentItemTempForSole($objCartSess, $shipping_id);
             $objSiteSess->setRegistFlag();
             SC_Response_Ex::sendRedirect(SHOPPING_PAYMENT_URLPATH);
             SC_Response_Ex::actionExit();
             break;
             // 前のページに戻る
         // 前のページに戻る
         case 'return':
             // 確認ページへ移動
             SC_Response_Ex::sendRedirect(CART_URLPATH);
             SC_Response_Ex::actionExit();
             break;
             // お届け先複数指定
         // お届け先複数指定
         case 'multiple':
             // 複数配送先指定が無効な場合はエラー
             if (USE_MULTIPLE_SHIPPING === false) {
                 SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true);
                 SC_Response_Ex::actionExit();
             }
             SC_Response_Ex::sendRedirect('multiple.php');
             SC_Response_Ex::actionExit();
             break;
         default:
             // 配送IDの取得
             $shippingData = $objPurchase->getShippingTemp();
             $arrShippingId = array_keys($shippingData);
             if (isset($arrShippingId[0])) {
                 $this->arrForm['deliv_check']['value'] = $arrShippingId[0] == 0 ? -1 : $arrShippingId[0];
             }
             break;
     }
     // 登録済み住所を取得
     $addr = array(array('other_deliv_id' => NULL, 'customer_id' => $objCustomer->getValue('customer_id'), 'name01' => $objCustomer->getValue('name01'), 'name02' => $objCustomer->getValue('name02'), 'kana01' => $objCustomer->getValue('kana01'), 'kana02' => $objCustomer->getValue('kana02'), 'zipcode' => $objCustomer->getValue('zipcode'), 'pref' => $objCustomer->getValue('pref'), 'addr01' => $objCustomer->getValue('addr01'), 'addr02' => $objCustomer->getValue('addr02'), 'tel01' => $objCustomer->getValue('tel01'), 'tel02' => $objCustomer->getValue('tel02'), 'tel03' => $objCustomer->getValue('tel03')));
     $this->arrAddr = array_merge($addr, $objAddress->getList($objCustomer->getValue('customer_id')));
     $this->tpl_addrmax = count($this->arrAddr);
 }