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 をもとにして作成します。
- require_once(CLASS_PATH . "pages/LC_Page.php");
- class LC_Page_MyPage_Reading extends LC_Page {
- /** ページナンバー */
- var $tpl_pageno;
- /**
- * Page を初期化する.
- *
- * @return void
- */
- function init() {
- parent::init();
- $this->tpl_mainpage = TEMPLATE_DIR .'mypage/reading.tpl';
- $this->tpl_title = 'MYページ/閲覧履歴一覧';
- $this->tpl_navi = TEMPLATE_DIR . 'mypage/navi.tpl';
- $this->tpl_column_num = 1;
- $this->tpl_mainno = 'mypage';
- $this->tpl_mypageno = 'reading';
- $this->allowClientCache();
- }
- /**
- * Page のプロセス.
- *
- * @return void
- */
- function process() {
- $objView = new SC_SiteView();
- $objQuery = new SC_Query();
- $objCustomer = new SC_Customer();
- // レイアウトデザインを取得
- $objLayout = new SC_Helper_PageLayout_Ex();
- $objLayout->sfGetPageLayout($this, false, "mypage/index.php");
- // ログインチェック
- if(!$objCustomer->isLoginSuccess()) {
- SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
- }else {
- //マイページトップ顧客情報表示用
- $this->CustomerName1 = $objCustomer->getvalue('name01');
- $this->CustomerName2 = $objCustomer->getvalue('name02');
- $this->CustomerPoint = $objCustomer->getvalue('point');
- }
- //ページ送り用
- if (isset($_POST['pageno'])) {
- $this->tpl_pageno = htmlspecialchars($_POST['pageno'], ENT_QUOTES, CHAR_CODE);
- }
- $col = "T1.*,T2.*";
- $from = "dtb_customer_reading AS T1 INNER JOIN vw_products_allclass AS T2 ON T1.reading_product_id = T2.product_id";
- $where = "T2.status = 1 AND T1.customer_id=?";
- $arrval = array($objCustomer->getvalue('customer_id'));
- $order = "T1.update_date DESC";
- $linemax = $objQuery->count($from, $where, $arrval);
- $this->tpl_linemax = $linemax;
- // ページ送りの取得
- $objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, SEARCH_PMAX, "fnNaviPage", NAVI_PMAX);
- $this->tpl_strnavi = $objNavi->strnavi; // 表示文字列
- $startno = $objNavi->start_row;
- // 取得範囲の指定(開始行番号、行数のセット)
- $objQuery->setlimitoffset(SEARCH_PMAX, $startno);
- // 表示順序
- $objQuery->setorder($order);
- //閲覧履歴の取得
- $this->arrForm = $objQuery->select($col, $from, $where, $arrval);
- // 支払い方法の取得
- $objDb = new SC_Helper_DB_Ex();
- $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
- $objView->assignobj($this); //$objpage内の全てのテンプレート変数をsmartyに格納
- $objView->display(SITE_FRAME); //パスとテンプレート変数の呼び出し、実行
- }
- /**
- * モバイルページを初期化する.
- *
- * @return void
- */
- function mobileInit() {
- $this->tpl_mainpage = 'mypage/index.tpl';
- $this->tpl_title = 'MYページ/購入履歴一覧';
- $this->allowClientCache();
- }
- /**
- * Page のプロセス(モバイル).
- *
- * @return void
- */
- function mobileProcess() {
- $objView = new SC_MobileView();
- $objQuery = new SC_Query();
- $objCustomer = new SC_Customer();
- // クッキー管理クラス
- $objCookie = new SC_Cookie(COOKIE_EXPIRE);
- // パラメータ管理クラス
- $objFormParam = new SC_FormParam();
- // パラメータ情報の初期化
- $this->lfInitParam($objFormParam);
- // POST値の取得
- $objFormParam->setParam($_POST);
- // 携帯端末IDが一致する会員が存在するかどうかをチェックする。
- $this->tpl_valid_phone_id = $objCustomer->checkMobilePhoneId();
- if (!isset($_POST['mode'])) $_POST['mode'] = "";
- // ログイン処理
- if($_POST['mode'] == 'login') {
- $objFormParam->toLower('login_email');
- $arrErr = $objFormParam->checkError();
- $arrForm = $objFormParam->getHashArray();
- // クッキー保存判定
- if ($arrForm['login_memory'] == "1" && $arrForm['login_email'] != "") {
- $objCookie->setCookie('login_email', $_POST['login_email']);
- } else {
- $objCookie->setCookie('login_email', '');
- }
- if (count($arrErr) == 0){
- if($objCustomer->getCustomerDataFromMobilePhoneIdPass($arrForm['login_pass']) ||
- $objCustomer->getCustomerDataFromEmailPass($arrForm['login_pass'], $arrForm['login_email'], true)) {
- // ログインが成功した場合は携帯端末IDを保存する。
- $objCustomer->updateMobilePhoneId();
- /*
- * email がモバイルドメインでは無く,
- * 携帯メールアドレスが登録されていない場合
- */
- $objMobile = new SC_Helper_Mobile_Ex();
- if (!$objMobile->gfIsMobileMailAddress($objCustomer->getValue('email'))) {
- if (!$objCustomer->hasValue('email_mobile')) {
- $this->sendRedirect($this->getLocation("../entry/email_mobile.php"), true);
- exit;
- }
- }
- } else {
- $objQuery = new SC_Query;
- $where = "(email = ? OR email_mobile = ?) AND status = 1 AND del_flg = 0";
- $ret = $objQuery->count("dtb_customer", $where, array($arrForm['login_email'], $arrForm['login_email']));
- if($ret > 0) {
- SC_Utils_Ex::sfDispSiteError(TEMP_LOGIN_ERROR, "", false, "", true);
- } else {
- SC_Utils_Ex::sfDispSiteError(SITE_LOGIN_ERROR, "", false, "", true);
- }
- }
- }
- }
- /*
- * ログインチェック
- * 携帯メールの登録を必須にする場合は isLoginSuccess(false) にする
- */
- if(!$objCustomer->isLoginSuccess(true)) {
- $this->tpl_mainpage = 'mypage/login.tpl';
- $objView->assignArray($objFormParam->getHashArray());
- if (empty($arrErr)) $arrErr = array();
- $objView->assignArray(array("arrErr" => $arrErr));
- }else {
- //マイページトップ顧客情報表示用
- $this->CustomerName1 = $objCustomer->getvalue('name01');
- $this->CustomerName2 = $objCustomer->getvalue('name02');
- }
- $objView->assignobj($this); //$objpage内の全てのテンプレート変数をsmartyに格納
- $objView->display(SITE_FRAME); //パスとテンプレート変数の呼び出し、実行
- }
- /**
- * デストラクタ.
- *
- * @return void
- */
- function destroy() {
- parent::destroy();
- }
- //エラーチェック
- function lfErrorCheck() {
- $objErr = new SC_CheckError();
- $objErr->doFunc(array("メールアドレス", "login_email", MTEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","EMAIL_CHECK","MAX_LENGTH_CHECK"));
- $objErr->dofunc(array("パスワード", "login_password", PASSWORD_LEN2), array("EXIST_CHECK","ALNUM_CHECK"));
- return $objErr->arrErr;
- }
- /* パラメータ情報の初期化 */
- function lfInitParam(&$objFormParam) {
- $objFormParam->addParam("記憶する", "login_memory", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
- $objFormParam->addParam("メールアドレス", "login_email", MTEXT_LEN, "a", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
- $objFormParam->addParam("パスワード", "login_pass", STEXT_LEN, "a", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
- }
- }
呼び出し側ファイルの作成
- html/mypage/reading.php
html/mypage/index.phpを修正して、新規に作成します。
- require_once("../require.php");
- require_once(CLASS_PATH . "pages/mypage/LC_Page_Mypage_Reading.php");
- $objPage = new LC_Page_Mypage_Reading();
- register_shutdown_function(array($objPage, "destroy"));
- $objPage->init();
- $objPage->process();
テンプレートの編集
- 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}-->
<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
中身は古いテンプレートになっていますので、以下の内容に全体を置き換えます。
- <!--▼CONTENTS-->
- <div id="mypagecolumn">
- <h2 class="title"><img src="<!--{$TPL_DIR}-->img/mypage/title.jpg" width="700" height="40" alt="MYページ" /></h2>
- <!--{if $tpl_navi != ""}-->
- <!--{include file=$tpl_navi}-->
- <!--{else}-->
- <!--{include file=`$smarty.const.TEMPLATE_DIR`mypage/navi.tpl}-->
- <!--{/if}-->
- <div id="mycontentsarea">
- <!--サブタイトル-->
- <h3><img src="<!--{$TPL_DIR}-->img/mypage/subtitle07.gif" width="515" height="32" alt="閲覧履歴一覧" /></h3> <!--サブタイトル-->
- <!--{if $arrForm}-->
- <p>ワンクリックで閲覧商品のページに行く事ができます。<br />
- <span class="asterisk">※</span>最大<!--{$smarty.const.CUSTOMER_READING_MAX}-->件まで表示します。</p>
- <form name="form1" method="post" action="<!--{$smarty.server.PHP_SELF|escape}-->" >
- <input type="hidden" name="product_id" value="" />
- <input type="hidden" name="mode" value="" />
- <input type="hidden" name="pageno" value="<!--{$tpl_pageno}-->" />
- <table cellspacing="1" cellpadding="10" summary=" " id="frame">
- <tr>
- <th>閲覧日時</th>
- <th>商品名</th>
- <th>単価</th>
- </tr>
- <!--{section name=cnt loop=$arrForm}-->
- <tr>
- <td><!--{$arrForm[cnt].update_date|sfDispDBDate}--></td>
- <td><a href="<!--{$smarty.const.DETAIL_P_HTML}--><!--{$arrForm[cnt].reading_product_id}-->"><!--{$arrForm[cnt].name|escape}--></a></td>
- <!--{assign var=price02_min value=$arrForm[cnt].price02_min}-->
- <!--{assign var=price02_max value=$arrForm[cnt].price02_max}-->
- <td class="pricetd">
- <!--{if $price02_min == $price02_max}-->
- <!--{$price02_min|sfPreTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}-->
- <!--{else}-->
- <!--{$price02_min|sfPreTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}--> <br/>〜<br/><!--{$price02_max|sfPreTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}-->
- <!--{/if}-->
- 円</td>
- </tr>
- <!--{/section}-->
- </table>
- <div>
- <!--▼ページナビ-->
- <!--{$tpl_strnavi}-->
- <!--▲ページナビ-->
- </div>
- </form>
- <!--{else}-->
- <p>閲覧履歴はありません。</p>
- <!--{/if}-->
- </div>
- </div>
- <!--▲CONTENTS-->
EC-CUBEのカスタマイズ・制作会社 強いネットショップ構築します|EC-Orange





