[EC-CUBE]お問い合わせメールを管理画面から返信できるようにする

先に作成した管理画面でのお問合わせ機能だけだと閲覧のみなので、管理画面からメールを返信できるようにカスタマイズする.

※これが大変だったんだった。  サイトどおりにやってもうまくいかない。ホント。


  • データベースの編集 お問合わせ管理画面からメールを扱えるようにするため、EC-CUBE上で送信されているメールの情報を格納しているテーブルを編集します。

dtb_mail_history

デフォルトでは「order_id」が「NOT_NULL」すなわち、お買い物データがないものは、エラーとなってしまいますので、この制限をはずします。 また、送信先のメールアドレスを保存するために、「email」カラムを「text」型で追加します。

mtb_mail_template

管理画面から、

システム設定>マスタデータ管理>mtb_mail_template

と進んで、

ID:5
値:お問合わせ返信

を追加する。

mtb_mail_tpl_path

も同様に、

ID:5
値:mail_tenplates/contact_re_mail.tpl

を追加。

  • ファイルを作る order系のファイルを複製して以下のファイルを作る。 下記ファイル以外にも編集しなきゃいけないクラスがあったりする。
/html/admin/customer/mail.php 
/html/admin/customer/mail_confirm.php 
/html/admin/customer/mail_view.php 
/data/Smarty/templates/default/admin/customer/mail.tpl 
/data/Smarty/templates/default/admin/customer/mail_confirm.tpl 
/data/Smarty/templates/default/admin/customer/mail_view.tpl 
/data/Smarty/templates/default/mail_template/contact_re_mail.tpl 
/data/class/pages/admin/customer/LC_Page_Admin_Contact_Mail.php 
/data/class/pages/admin/customer/LC_Page_Admin_Contact_MailView.php

クラスの編集 /data/class/helper/SC_Helper_Mail.php

以下のメソッドを追加

  1. /***
  2.   * 2009.04.27 追加
  3.   * @author i-enter y-nakajima
  4.   * 返信メール送信メソッド
  5.   * @param $contact_id, $template_id, $subject = "", $header = "", $footer = "", $send = true
  6.   **/
  7. function sfSendContactMail($contact_id, $template_id, $subject = "", $header = "", $footer = "", $send_flg = true) {
  8. $objPage = new LC_Page();
  9. $objSiteInfo = new SC_SiteInfo();
  10. $arrInfo = $objSiteInfo->data;
  11. $objPage->arrInfo = $arrInfo;
  12.  
  13. $objQuery = new SC_Query();
  14.  
  15. if($subject == "" && $header == "" && $footer == ""){
  16.  
  17. // メールテンプレート情報の取得
  18. $where = "template_id = ?";
  19. $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array('1'));
  20. $objPage->tpl_header = $arrRet[0]['header'];
  21. $objPage->tpl_footer = $arrRet[0]['footer'];
  22. $tmp_subject = $arrRet[0]['subject'];
  23.  
  24. } else {
  25. $objPage->tpl_header = $header;
  26. $objPage->tpl_footer = $footer;
  27. $tmp_subject = $subject;
  28. }
  29.  
  30. // 問い合わせ情報の取得
  31. $where = "contact_id = ?";
  32. $arrRet = $objQuery->select("*", "dtb_contact", $where, array($contact_id));
  33.  
  34. $objPage->arrContact = $arrRet[0];
  35.  
  36. $objMailView = new SC_SiteView();
  37. // メール本文の取得
  38. $objMailView->assignobj($objPage);
  39. $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]);
  40.  
  41. // メール送信処理
  42. $objSendMail = new SC_SendMail_Ex();
  43. $bcc = $arrInfo['email01'];
  44. $from = $arrInfo['email03'];
  45. $error = $arrInfo['email04'];
  46.  
  47. $tosubject = $this->sfMakeSubject($objQuery, $objMailView, $objPage, $tmp_subject);
  48.  
  49. $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
  50. $objSendMail->setTo($arrRet[0]['email'] , $arrRet[0]['name'] . ' ' . $arrRet[0]['name_f'] . ' 様');
  51.  
  52. // 送信フラグ:trueの場合はTXTメール送信を実行する
  53. if($send_flg){
  54. if($objSendMail->sendMail()){
  55. $this->sfSaveMailHistory2($arrRet[0]['email'], $template_id, $tosubject, $body);
  56. }
  57. }
  58.  
  59. return $objSendMail;
  60. }
  61.  
  62. /***
  63.   * 2009.04.27 追加
  64.   * @author i-enter y-nakajima
  65.   * メール配信履歴への登録
  66.   * @param $email, $template_id, $subject, $body
  67.   **/
  68. function sfSaveMailHistory2($email, $template_id, $subject, $body) {
  69. $sqlval['subject'] = $subject;
  70. $sqlval['email'] = $email;
  71. $sqlval['template_id'] = $template_id;
  72. $sqlval['send_date'] = "Now()";
  73.  
  74. if(!isset($_SESSION['member_id'])) $_SESSION['member_id'] = "";
  75. if($_SESSION['member_id'] != "") {
  76. $sqlval['creator_id'] = $_SESSION['member_id'];
  77. } else {
  78. $sqlval['creator_id'] = '0';
  79. }
  80. $sqlval['mail_body'] = $body;
  81.  
  82. $objQuery = new SC_Query();
  83. $objQuery->insert("dtb_mail_history", $sqlval);
  84. }

次に以下のファイルを編集。

/data/class/pages/admin/customer/LC_Page_Admin_Contact_Mail.php
<?php
require_once(CLASS_PATH . "pages/LC_Page.php");
 
/**
 * お問い合わせメール管理 のページクラス.
 */
class LC_Page_Admin_Contact_Mail extends LC_Page {
 
    /**
     * Page を初期化する.
     *
     * @return void
     */
    function init() {
        parent::init();
        $this->tpl_mainpage = 'customer/mail.tpl';
        $this->tpl_subnavi = 'customer/subnavi.tpl';
        $this->tpl_mainno = 'customer';
        $this->tpl_subno = 'contact';
        $this->tpl_subtitle = 'お問合わせ返信';
 
        $masterData = new SC_DB_MasterData_Ex();
        $this->arrMAILTEMPLATE = $masterData->getMasterData("mtb_mail_template");
 
    }
 
    /**
     * Page のプロセス.
     *
     * @return void
     */
    function process() {
 
        $objView = new SC_AdminView();
        $objSess = new SC_Session();
        SC_Utils_Ex::sfIsSuccess($objSess);
 
        if(SC_Utils_Ex::sfIsInt($_GET['contact_id'])){
        	$this->tpl_contact_id = $_GET['contact_id'];
        }elseif(SC_Utils_Ex::sfIsInt($_POST['contact_id'])){
    		$this->tpl_contact_id = $_POST['contact_id'];
        }
        // パラメータ管理クラス
        $objFormParam = new SC_FormParam();
        // パラメータ情報の初期化
        $this->lfInitParam($objFormParam);
 
        $objMail = new SC_Helper_Mail_Ex();
 
        switch($_POST['mode']) {
        case 'pre_edit':
            break;
        case 'return':
            // POST値の取得
            $objFormParam->setParam($_POST);
            break;
        case 'send':
            // POST値の取得
            $objFormParam->setParam($_POST);
            // 入力値の変換
            $objFormParam->convParam();
            $this->arrErr = $objFormParam->checkError();
            // メールの送信
            if (count($this->arrErr) == 0) {
                // 問合せ返信メール
                $objSendMail = $objMail->sfSendContactMail($this->tpl_contact_id, $_POST['template_id'], $_POST['subject'], $_POST['header'], $_POST['footer']);
            }
 
            $this->sendRedirect($this->getLocation("./contact.php"), true);
            exit;
            break;
        case 'confirm':
            // POST値の取得
            $objFormParam->setParam($_POST);
            // 入力値の変換
            $objFormParam->convParam();
            // 入力値の引き継ぎ
            $this->arrHidden = $objFormParam->getHashArray();
            $this->arrErr = $objFormParam->checkError();
            // メールの送信
            if (count($this->arrErr) == 0) {
                // 問合せ返信メール(送信なし)
                $objSendMail = $objMail->sfSendContactMail($this->tpl_contact_id, $_POST['template_id'], $_POST['subject'], $_POST['header'], $_POST['footer'], false);
                // 確認ページの表示
                $this->tpl_subject = $_POST['subject'];
                $this->tpl_body = mb_convert_encoding( $objSendMail->body, CHAR_CODE, "auto" );
                $this->tpl_to = $objSendMail->arrRecip["To"];
                $this->tpl_mainpage = 'customer/mail_confirm.tpl';
                $this->arrHidden['contact_id'] = $this->tpl_contact_id;
 
                $objView->assignobj($this);
                $objView->display(MAIN_FRAME);
 
                exit;
            }
            break;
        case 'change':
            // POST値の取得
            $objFormParam->setValue('template_id', $_POST['template_id']);
            if(SC_Utils_Ex::sfIsInt($_POST['template_id'])) {
                $objQuery = new SC_Query();
                $where = "template_id = ?";
                $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($_POST['template_id']));
                $objFormParam->setParam($arrRet[0]);
            }
            break;
        }
 
        $objQuery = new SC_Query();
        $where = "contact_id = ?";
        $arrRet = $objQuery->select("*", "dtb_contact", $where, array($this->tpl_contact_id));
        $col = "send_date, subject, template_id, send_id";
        $where = "email = ?";
        $objQuery->setorder("send_date DESC");
        $this->arrMailHistory = $objQuery->select($col, "dtb_mail_history", $where, array($arrRet[0]['email']));
 
        $this->arrForm = $objFormParam->getFormParamList();
        $objView->assignobj($this);
        $objView->display(MAIN_FRAME);
    }
 
    /**
     * デストラクタ.
     *
     * @return void
     */
    function destroy() {
        parent::destroy();
    }
 
 
    /* パラメータ情報の初期化 */
    function lfInitParam(&$objFormParam) {
 
        $objFormParam->addParam("テンプレート", "template_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
        $objFormParam->addParam("メールタイトル", "subject", STEXT_LEN, "KVa",  array("EXIST_CHECK", "MAX_LENGTH_CHECK", "SPTAB_CHECK"));
        $objFormParam->addParam("ヘッダー", "header", LTEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "SPTAB_CHECK"));
        $objFormParam->addParam("フッター", "footer", LTEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "SPTAB_CHECK"));
    }
}
?>

次はこれをorderのをコピーして編集。 /data/class/pages/admin/customer/LC_Page_Admin_Contact_MailView.php

  1. <?php
  2. require_once(CLASS_PATH . "pages/LC_Page.php");
  3.  
  4. /**
  5.  * お問合わせメール確認 のページクラス.
  6.  */
  7. class LC_Page_Admin_Contact_MailView extends LC_Page {
  8.  
  9. /**
  10.   * Page を初期化する.
  11.   *
  12.   * @return void
  13.   */
  14. function init() {
  15. parent::init();
  16. $this->tpl_mainpage = 'customer/mail_view.tpl';
  17. }
  18.  
  19. /**
  20.   * Page のプロセス.
  21.   *
  22.   * @return void
  23.   */
  24. function process() {
  25. $objView = new SC_AdminView();
  26. $objSess = new SC_Session();
  27.  
  28. // 認証可否の判定
  29. SC_Utils_Ex::sfIsSuccess($objSess);
  30.  
  31. if(SC_Utils_Ex::sfIsInt($_GET['send_id'])) {
  32. $objQuery = new SC_Query();
  33. $col = "subject, mail_body";
  34. $where = "send_id = ?";
  35. $arrRet = $objQuery->select($col, "dtb_mail_history", $where, array($_GET['send_id']));
  36. $this->tpl_subject = $arrRet[0]['subject'];
  37. $this->tpl_body = $arrRet[0]['mail_body'];
  38. }
  39.  
  40. $objView->assignobj($this);
  41. $objView->display($this->tpl_mainpage);
  42. }
  43.  
  44. /**
  45.   * デストラクタ.
  46.   *
  47.   * @return void
  48.   */
  49. function destroy() {
  50. parent::destroy();
  51. }
  52. }
  53. ?>
  • テンプレートの編集

/data/Smarty/templates/default/adin/customer/mail.tpl の以下を変更

Line 28

28. <input type="hidden" name="order_id" value="<!--{$tpl_order_id}-->">

↓↓↓↓

28. <input type="hidden" name="order_id" value="<!--{$tpl_contact_id}-->">

Line142

142. <input type="button" name="back" value="検索結果へ戻る" onclick="fnChangeAction('<!--{$smarty.const.URL_SEARCH_ORDER}-->'); fnModeSubmit('search','',''); return false;" /> 

↓↓↓↓

142. <input type="button" name="back" value="検索結果へ戻る" onclick="fnChangeAction('contact.php'); fnModeSubmit('','',''); return false;" />

/data/Smarty/templates/default/adin/customer/contact_re_mail.tpl を新規作成。

  1. お問合せ内容が挿入されます。
  2. <!--{$tpl_header}-->
  3.  
  4. ----------------------------------------------
  5.  
  6. ■お問合せ日時:<!--{$arrContact.create_date}-->
  7.  
  8. ■お問い合わせ内容
  9. <!--{$arrContact.message}-->
  10.  
  11. ----------------------------------------------
  12.  
  13. <!--{$tpl_footer}-->

カスタマイズ結果はこんな感じです。

最終更新:2009年05月19日 16:13
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。