[EC-CUBE 2.13]Myページにログアウトメニューを追加する

  • 公開日:2015/1/27
この記事は最終更新日から8年以上が経過しています。

Myページのナビ部分(上部のメニュー部分)に「ログアウト」を追加する方法です。
(なんでデフォルトで無いんだろう?)

eccube_logout01

ログアウトの動作を追記する

パラメータmodeがlogoutの場合にログイン情報を破棄してログインページにリダイレクトするコードを追記します。

data/class/pages/mypage/LC_Page_Mypage.php

// 支払い方法の取得
$this->arrPayment = SC_Helper_Payment_Ex::getIDValueList();
// 1ページあたりの件数
$this->dispNumber = SEARCH_PMAX;

if ($_GET['mode'] == 'logout') {
    $objCustomer->EndSession();
    header('Location: index.php');
}

2015.04.28 追記
data/class_extends/page_extends/mypage/LC_Page_Mypage_Ex.php
に上記を含むaction()を丸ごとコピーして、そっちをカスタマイズする方が良いようです。

ログアウトのリンクを追加する

Myページのメニューに「ログアウト」リンクを追加します。

data/Smarty/templates/default/mypage/navi.tpl
スマホにも必要ならそのテンプレートにも追加します。

<!--{* 会員状態 *}-->
<!--{if $tpl_login}-->
    <li><a href=&quot;./<!--{$smarty.const.DIR_INDEX_PATH}-->&quot; class=&quot;<!--{if $tpl_mypageno == 'index'}--> selected<!--{/if}-->&quot;>
        購入履歴一覧</a></li>
    <!--{if $smarty.const.OPTION_FAVORITE_PRODUCT == 1}-->
        <li><a href=&quot;favorite.php&quot; class=&quot;<!--{if $tpl_mypageno == 'favorite'}--> selected<!--{/if}-->&quot;>
            お気に入り一覧</a></li>
    <!--{/if}-->
    <li><a href=&quot;change.php&quot; class=&quot;<!--{if $tpl_mypageno == 'change'}--> selected<!--{/if}-->&quot;>
        会員登録内容変更</a></li>
    <li><a href=&quot;delivery.php&quot; class=&quot;<!--{if $tpl_mypageno == 'delivery'}--> selected<!--{/if}-->&quot;>
        お届け先追加・変更</a></li>
    <li><a href=&quot;refusal.php&quot; class=&quot;<!--{if $tpl_mypageno == 'refusal'}--> selected<!--{/if}-->&quot;>
        退会手続き</a></li>
    <li><a href=&quot;index.php?mode=logout&quot; class=&quot;<!--{if $tpl_mypageno == 'refusal'}--> selected<!--{/if}-->&quot;>
        ログアウト</a></li>

<!--{* 退会状態 *}-->
<!--{else}-->
    <li><a href=&quot;<!--{$smarty.const.TOP_URL}-->&quot; class=&quot;<!--{if $tpl_mypageno == 'index'}--> selected<!--{/if}-->&quot;>
        購入履歴一覧</a></li>
    <!--{if $smarty.const.OPTION_FAVORITE_PRODUCT == 1}-->
        <li><a href=&quot;<!--{$smarty.const.TOP_URL}-->&quot; class=&quot;<!--{if $tpl_mypageno == 'favorite'}--> selected<!--{/if}-->&quot;>
            お気に入り一覧</a></li>
    <!--{/if}-->
    <li><a href=&quot;<!--{$smarty.const.TOP_URL}-->&quot; class=&quot;<!--{if $tpl_mypageno == 'change'}--> selected<!--{/if}-->&quot;>
        会員登録内容変更</a></li>
    <li><a href=&quot;<!--{$smarty.const.TOP_URL}-->&quot; class=&quot;<!--{if $tpl_mypageno == 'delivery'}--> selected<!--{/if}-->&quot;>
        お届け先追加・変更</a></li>
    <li><a href=&quot;<!--{$smarty.const.TOP_URL}-->&quot; class=&quot;<!--{if $tpl_mypageno == 'refusal'}--> selected<!--{/if}-->&quot;>
        退会手続き</a></li>
    <li><a href=&quot;<!--{$smarty.const.TOP_URL}-->&quot; class=&quot;<!--{if $tpl_mypageno == 'refusal'}--> selected<!--{/if}-->&quot;>
        ログアウト</a></li>
<!--{/if}-->

これでログアウトが追加できました。