EC-CUBE EC-CUBEのカスタマイズ・制作会社 強いネットショップ構築します|EC-Orange

EC-Orange とは

EC-CUBE カスタマイズ

EC-CUBEインストール

EC-CUBE 環境構築ノウハウ

EC-CUBE 基本構成理解

ソースコード読解

EC-CUBE カスタマイズ:初歩

EC-CUBE カスタマイズ:基礎

EC-CUBE カスタマイズ:応用

EC-CUBE 機能拡張ノウハウ

EC-CUBE カスタマイズ    ログイン後見た商品をマイページに表示

    EC-CUBE カスタマイズ  >  EC-CUBE カスタマイズ:応用  >  商品閲覧履歴機能

カスタマイズ:応用/商品閲覧履歴機能

ログイン後に見た商品履歴を、マイページに表示させる機能です。
Amazonのように、一度見た商品を提示してくれるので、
商品を探しなおす必要がありません。

機能自体はほぼ完成された形でソースコードの中に存在しているのですが、機能を無効にした形にしています。
比較的簡単に有効にはできるのですが、サーバが重くなりますので、環境に応じてご利用ください。

    システム開発でお悩みの方は、ネットショップ構築パッケージ EC-Orange にお問い合わせください


クラスファイルの編集

  • data/class/pages/products/LC_Page_Products_Detail.php

127行目付近のコメントアウトを解除し、メソッドの呼び出し方を修正します。

$table = "dtb_customer_reading";
$where = "customer_id = ? ";
$arrval[] = $objCustomer->getValue('customer_id');
//顧客の閲覧商品数
$rpcnt = $objQuery->count($table, $where, $arrval);

//閲覧数が設定数以下
if ($rpcnt < CUSTOMER_READING_MAX){
    //閲覧履歴に新規追加
    $this->lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
    //メソッドの呼び出し方を修正
} else {
    //閲覧履歴の中で一番古いものを削除して新規追加
    $oldsql = "SELECT MIN(update_date) FROM ".$table." WHERE customer_id = ?";
    $old = $objQuery->getone($oldsql, array($objCustomer->getValue("customer_id")));
    $where = "customer_id = ? AND update_date = ? ";
    $arrval = array($objCustomer->getValue("customer_id"), $old);
    //削除
    $objQuery->delete($table, $where, $arrval);
    //追加
    $this->lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
    //メソッドの呼び出し方を修正
}

  • data/class/pages/mypage/Reding.php

data/class/pages/mypage/LC_Page_Mypage.php をもとにして作成します。

  1. <?php
  2. require_once(CLASS_PATH . "pages/LC_Page.php");
  3.  
  4. class LC_Page_MyPage_Reading extends LC_Page {
  5.  
  6.     /** ページナンバー */
  7.     var $tpl_pageno;
  8.  
  9.     /**
  10.      * Page を初期化する.
  11.      *
  12.      * @return void
  13.      */
  14.     function init() {
  15.         parent::init();
  16.         $this->tpl_mainpage = TEMPLATE_DIR .'mypage/reading.tpl';
  17.         $this->tpl_title = 'MYページ/閲覧履歴一覧';
  18.         $this->tpl_navi = TEMPLATE_DIR . 'mypage/navi.tpl';
  19.         $this->tpl_column_num = 1;
  20.         $this->tpl_mainno = 'mypage';
  21.         $this->tpl_mypageno = 'reading';
  22.         $this->allowClientCache();
  23.     }
  24.  
  25.     /**
  26.      * Page のプロセス.
  27.      *
  28.      * @return void
  29.      */
  30.     function process() {
  31.  
  32.         $objView = new SC_SiteView();
  33.         $objQuery = new SC_Query();
  34.         $objCustomer = new SC_Customer();
  35.  
  36.         // レイアウトデザインを取得
  37.         $objLayout = new SC_Helper_PageLayout_Ex();
  38.         $objLayout->sfGetPageLayout($this, false, "mypage/index.php");
  39.  
  40.         // ログインチェック
  41.         if(!$objCustomer->isLoginSuccess()) {
  42.             SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
  43.         }else {
  44.             //マイページトップ顧客情報表示用
  45.             $this->CustomerName1 = $objCustomer->getvalue('name01');
  46.             $this->CustomerName2 = $objCustomer->getvalue('name02');
  47.             $this->CustomerPoint = $objCustomer->getvalue('point');
  48.         }
  49.  
  50.         //ページ送り用
  51.         if (isset($_POST['pageno'])) {
  52.             $this->tpl_pageno = htmlspecialchars($_POST['pageno'], ENT_QUOTES, CHAR_CODE);
  53.         }
  54.  
  55.         $col = "T1.*,T2.*";
  56.         $from = "dtb_customer_reading AS T1 INNER JOIN vw_products_allclass AS T2 ON T1.reading_product_id = T2.product_id";
  57.         $where = "T2.status = 1 AND T1.customer_id=?";
  58.         $arrval = array($objCustomer->getvalue('customer_id'));
  59.         $order = "T1.update_date DESC";
  60.  
  61.         $linemax = $objQuery->count($from, $where, $arrval);
  62.         $this->tpl_linemax = $linemax;
  63.  
  64.         // ページ送りの取得
  65.         $objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, SEARCH_PMAX, "fnNaviPage", NAVI_PMAX);
  66.         $this->tpl_strnavi = $objNavi->strnavi;        // 表示文字列
  67.         $startno = $objNavi->start_row;
  68.  
  69.         // 取得範囲の指定(開始行番号、行数のセット)
  70.         $objQuery->setlimitoffset(SEARCH_PMAX, $startno);
  71.         // 表示順序
  72.         $objQuery->setorder($order);
  73.  
  74.         //閲覧履歴の取得
  75.         $this->arrForm = $objQuery->select($col, $from, $where, $arrval);
  76.  
  77.         // 支払い方法の取得
  78.         $objDb = new SC_Helper_DB_Ex();
  79.         $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
  80.  
  81.         $objView->assignobj($this);                //$objpage内の全てのテンプレート変数をsmartyに格納
  82.         $objView->display(SITE_FRAME);                //パスとテンプレート変数の呼び出し、実行
  83.     }
  84.  
  85.     /**
  86.      * モバイルページを初期化する.
  87.      *
  88.      * @return void
  89.      */
  90.     function mobileInit() {
  91.         $this->tpl_mainpage = 'mypage/index.tpl';
  92.         $this->tpl_title = 'MYページ/購入履歴一覧';
  93.         $this->allowClientCache();
  94.     }
  95.  
  96.     /**
  97.      * Page のプロセス(モバイル).
  98.      *
  99.      * @return void
  100.      */
  101.     function mobileProcess() {
  102.         $objView = new SC_MobileView();
  103.         $objQuery = new SC_Query();
  104.         $objCustomer = new SC_Customer();
  105.         // クッキー管理クラス
  106.         $objCookie = new SC_Cookie(COOKIE_EXPIRE);
  107.         // パラメータ管理クラス
  108.         $objFormParam = new SC_FormParam();
  109.         // パラメータ情報の初期化
  110.         $this->lfInitParam($objFormParam);
  111.         // POST値の取得
  112.         $objFormParam->setParam($_POST);
  113.  
  114.         // 携帯端末IDが一致する会員が存在するかどうかをチェックする。
  115.         $this->tpl_valid_phone_id = $objCustomer->checkMobilePhoneId();
  116.  
  117.         if (!isset($_POST['mode'])) $_POST['mode'] = "";
  118.  
  119.         // ログイン処理
  120.         if($_POST['mode'] == 'login') {
  121.             $objFormParam->toLower('login_email');
  122.             $arrErr = $objFormParam->checkError();
  123.             $arrForm =  $objFormParam->getHashArray();
  124.  
  125.             // クッキー保存判定
  126.             if ($arrForm['login_memory'] == "1" && $arrForm['login_email'] != "") {
  127.                 $objCookie->setCookie('login_email', $_POST['login_email']);
  128.             } else {
  129.                 $objCookie->setCookie('login_email', '');
  130.             }
  131.  
  132.             if (count($arrErr) == 0){
  133.                 if($objCustomer->getCustomerDataFromMobilePhoneIdPass($arrForm['login_pass']) ||
  134.                    $objCustomer->getCustomerDataFromEmailPass($arrForm['login_pass'], $arrForm['login_email'], true)) {
  135.                     // ログインが成功した場合は携帯端末IDを保存する。
  136.                     $objCustomer->updateMobilePhoneId();
  137.  
  138.                     /*
  139.                      * email がモバイルドメインでは無く,
  140.                      * 携帯メールアドレスが登録されていない場合
  141.                      */
  142.                     $objMobile = new SC_Helper_Mobile_Ex();
  143.                     if (!$objMobile->gfIsMobileMailAddress($objCustomer->getValue('email'))) {
  144.                         if (!$objCustomer->hasValue('email_mobile')) {
  145.                             $this->sendRedirect($this->getLocation("../entry/email_mobile.php"), true);
  146.                             exit;
  147.                         }
  148.                     }
  149.                 } else {
  150.                     $objQuery = new SC_Query;
  151.                     $where = "(email = ? OR email_mobile = ?) AND status = 1 AND del_flg = 0";
  152.                     $ret = $objQuery->count("dtb_customer", $where, array($arrForm['login_email'], $arrForm['login_email']));
  153.  
  154.                     if($ret > 0) {
  155.                         SC_Utils_Ex::sfDispSiteError(TEMP_LOGIN_ERROR, "", false, "", true);
  156.                     } else {
  157.                         SC_Utils_Ex::sfDispSiteError(SITE_LOGIN_ERROR, "", false, "", true);
  158.                     }
  159.                 }
  160.             }
  161.         }
  162.  
  163.         /*
  164.          * ログインチェック
  165.          * 携帯メールの登録を必須にする場合は isLoginSuccess(false) にする
  166.          */
  167.         if(!$objCustomer->isLoginSuccess(true)) {
  168.             $this->tpl_mainpage = 'mypage/login.tpl';
  169.             $objView->assignArray($objFormParam->getHashArray());
  170.             if (empty($arrErr)) $arrErr = array();
  171.             $objView->assignArray(array("arrErr" => $arrErr));
  172.         }else {
  173.             //マイページトップ顧客情報表示用
  174.             $this->CustomerName1 = $objCustomer->getvalue('name01');
  175.             $this->CustomerName2 = $objCustomer->getvalue('name02');
  176.         }
  177.  
  178.         $objView->assignobj($this);                //$objpage内の全てのテンプレート変数をsmartyに格納
  179.         $objView->display(SITE_FRAME);                //パスとテンプレート変数の呼び出し、実行
  180.  
  181.     }
  182.  
  183.     /**
  184.      * デストラクタ.
  185.      *
  186.      * @return void
  187.      */
  188.     function destroy() {
  189.         parent::destroy();
  190.     }
  191.  
  192.     //エラーチェック
  193.  
  194.     function lfErrorCheck() {
  195.         $objErr = new SC_CheckError();
  196.         $objErr->doFunc(array("メールアドレス", "login_email", MTEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","EMAIL_CHECK","MAX_LENGTH_CHECK"));
  197.         $objErr->dofunc(array("パスワード", "login_password", PASSWORD_LEN2), array("EXIST_CHECK","ALNUM_CHECK"));
  198.         return $objErr->arrErr;
  199.     }
  200.  
  201.     /* パラメータ情報の初期化 */
  202.     function lfInitParam(&$objFormParam) {
  203.  
  204.         $objFormParam->addParam("記憶する", "login_memory", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
  205.         $objFormParam->addParam("メールアドレス", "login_email", MTEXT_LEN, "a", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
  206.         $objFormParam->addParam("パスワード", "login_pass", STEXT_LEN, "a", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
  207.     }
  208.  
  209. }
  210. ?>

呼び出し側ファイルの作成

  • html/mypage/reading.php

html/mypage/index.phpを修正して、新規に作成します。

  1. <?php
  2. require_once("../require.php");
  3. require_once(CLASS_PATH . "pages/mypage/LC_Page_Mypage_Reading.php");
  4.  
  5. $objPage = new LC_Page_Mypage_Reading();
  6. register_shutdown_function(array($objPage, "destroy"));
  7. $objPage->init();
  8. $objPage->process();
  9. ?>

テンプレートの編集

  • data/Smarty/templates/default/mypage/navi.tpl

以下を追加します。

<!--{if $tpl_mypageno == 'reading'}-->
  
<li><a href="./reading.php"><img src="<!--{$TPL_DIR}-->img/mypage/navi07_on.jpg" width="170" height="30" alt="閲覧履歴一覧" border="0" name="m_navi07" /></a></li>
<!--{else}-->
  
<li><a href="./reading.php" onmouseover="chgImg('<!--{$TPL_DIR}-->img/mypage/navi07_on.jpg','m_navi07');" onmouseout="chgImg('<!--{$TPL_DIR}-->img/mypage/navi07.jpg','m_navi07');"><img src="<!--{$TPL_DIR}-->img/mypage/navi07.jpg" width="170" height="30" alt="閲覧履歴一覧" border="0" name="m_navi07" /></a></li>
<!--{/if}-->

  • data/Smarty/templates/default/mypage/reading.tpl

中身は古いテンプレートになっていますので、以下の内容に全体を置き換えます。

  1. <!--▼CONTENTS-->
  2. <div id="mypagecolumn">
  3.     <h2 class="title"><img src="<!--{$TPL_DIR}-->img/mypage/title.jpg" width="700" height="40" alt="MYページ" /></h2>
  4.     <!--{if $tpl_navi != ""}-->
  5.         <!--{include file=$tpl_navi}-->
  6.     <!--{else}-->
  7.         <!--{include file=`$smarty.const.TEMPLATE_DIR`mypage/navi.tpl}-->
  8.     <!--{/if}-->
  9.     <div id="mycontentsarea">
  10.         <!--サブタイトル-->
  11.         <h3><img src="<!--{$TPL_DIR}-->img/mypage/subtitle07.gif" width="515" height="32" alt="閲覧履歴一覧" /></h3>                <!--サブタイトル-->
  12.  
  13.         <!--{if $arrForm}-->
  14.         <p>ワンクリックで閲覧商品のページに行く事ができます。<br />
  15.         <span class="asterisk"></span>最大<!--{$smarty.const.CUSTOMER_READING_MAX}-->件まで表示します。</p>
  16.         <form name="form1" method="post" action="<!--{$smarty.server.PHP_SELF|escape}-->" >
  17.             <input type="hidden" name="product_id" value="" />
  18.             <input type="hidden" name="mode" value="" />
  19.             <input type="hidden" name="pageno" value="<!--{$tpl_pageno}-->" />
  20.  
  21.             <table cellspacing="1" cellpadding="10" summary=" " id="frame">
  22.                 <tr>
  23.                     <th>閲覧日時</th>
  24.                     <th>商品名</th>
  25.                     <th>単価</th>
  26.                 </tr>
  27.                 <!--{section name=cnt loop=$arrForm}-->
  28.                 <tr>
  29.                     <td><!--{$arrForm[cnt].update_date|sfDispDBDate}--></td>
  30.                     <td><a href="<!--{$smarty.const.DETAIL_P_HTML}--><!--{$arrForm[cnt].reading_product_id}-->"><!--{$arrForm[cnt].name|escape}--></a></td>
  31.                     <!--{assign var=price02_min value=$arrForm[cnt].price02_min}-->
  32.                     <!--{assign var=price02_max value=$arrForm[cnt].price02_max}-->
  33.                     <td class="pricetd">
  34.                     <!--{if $price02_min == $price02_max}-->
  35.                     <!--{$price02_min|sfPreTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}-->
  36.                     <!--{else}-->
  37.                     <!--{$price02_min|sfPreTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}--> <br/><br/><!--{$price02_max|sfPreTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}-->
  38.                     <!--{/if}-->
  39.                     円</td>
  40.                 </tr>
  41.                 <!--{/section}-->
  42.             </table>
  43.  
  44.             <div>
  45.                 <!--▼ページナビ-->
  46.                 <!--{$tpl_strnavi}-->
  47.                 <!--▲ページナビ-->
  48.             </div>
  49.         </form>
  50.         <!--{else}-->
  51.         <p>閲覧履歴はありません。</p>
  52.         <!--{/if}-->
  53.     </div>
  54. </div>
  55. <!--▲CONTENTS-->

スクリーンショット