[EC-CUBE]ログイン後に見た商品の履歴を表示する

ログイン後に「商品詳細」まで見た商品の履歴をブロック内に表示する。
クッキーに保持する。
履歴は1か月保持。
4件まで表示可能。
Cookieを削除されたらそれまで。。。

閲覧履歴情報を取得する


/data/class/pages/products/LC_Page_Products_Detail.php
に以下を追加。
function proccess()内に以下を追加。
  1. function process() {
  2. $objView = new SC_SiteView();
  3. $objCustomer = new SC_Customer();
  4. $objQuery = new SC_Query();
  5. $objDb = new SC_Helper_DB_Ex();
  6.  
  7. // レイアウトデザインを取得
  8. $helper = new SC_Helper_PageLayout_Ex();
  9. $helper->sfGetPageLayout($this, false, "products/detail.php");
  10.  
  11. // パラメータ管理クラス
  12. $this->objFormParam = new SC_FormParam();
  13. // パラメータ情報の初期化
  14. $this->lfInitParam();
  15. // POST値の取得
  16. $this->objFormParam->setParam($_POST);
  17.  
  18. // ファイル管理クラス
  19. $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
  20. // ファイル情報の初期化
  21. $this->lfInitFile();
  22.  
  23.     // ここ追加から追加。
  24. // 2009.05.01 商品詳細閲覧履歴処理 追加
  25. $this->Get_ItemHistory();
  26. // 追加ここまで。
  27.  

ファイルの最後にfunctionを追加。
  1. /**
  2.   * 商品詳細閲覧履歴情報取得、表示データ取得
  3.   * 2009.05.01 追加
  4.   * @author y-nakajima
  5.   */
  6. function Get_ItemHistory(){
  7. $cnt = 0;
  8. // ページを再読み込み後に表示
  9. if(isset($_COOKIE['product'])){
  10. foreach($_COOKIE['product'] as $name => $value){
  11. $objQuery = new SC_Query();
  12. // DBから一覧表示用商品情報取得
  13. $arrRet = $objQuery->select("*", "vw_products_allclass AS alldtl", "product_id=".$value);
  14. $this->arrItemHistory[$cnt] = $arrRet[0];
  15. $cnt = $cnt+1;
  16. }
  17. }
  18.  
  19. // Cookieに重複しているデータがないか判定
  20. $duplicateFlg = true;
  21. foreach($_COOKIE['product'] as $name => $value){
  22. if($value == $_GET['product_id']){
  23. $duplicateFlg = false;
  24. }
  25.  
  26. }
  27.  
  28. // 重複していない場合、Cookieに保存
  29. if($duplicateFlg){
  30. // 4件以下だったら
  31. if($cnt < 4){
  32. $cnt = $cnt + 1;
  33. setcookie("product[" . $cnt ."]", $_GET['product_id'], time()+60*60*24*30);
  34. } else {
  35. $reNum = 1;
  36. foreach($_COOKIE['product'] as $name => $value){
  37. if($reNum > 1){
  38. $setNum = $reNum - 1;
  39. setcookie("product[" . $setNum . "]", $value, time()+60*60*24*30);
  40. }
  41. $reNum = $reNum + 1;
  42. }
  43. setcookie("product[4]", $_GET['product_id'], time()+60*60*24*30);
  44. }
  45. }
  46. }
  47.  
  48.  


商品詳細ページのテンプレートに表示場所を追加する。


/data/Smqrty/templates/default/detail.tpl
とりあえず、ファイルの最後の</div><!--▲CONTENTS-->の前に追加してみました。

  1. <!--▼閲覧履歴ここから 2009.05.01-->
  2. <!--{if $arrItemHistory}-->
  3. <div id="whoboughtarea">
  4. <h2><img src="<!--{$TPL_DIR}-->img/products/title_product_history.jpg" width="580" height="30" alt="閲覧履歴" /></h2>
  5. <div class="whoboughtblock">
  6.  
  7. <!--{section name=cnt loop=$arrItemHistory}-->
  8. <!--{if ($smarty.section.cnt.index % 2) == 0}-->
  9. <!--{if $arrItemHistory[cnt].product_id}-->
  10. <!-- 左列 -->
  11. <div class="whoboughtleft">
  12. <!--{if $arrItemHistory[cnt].main_list_image != ""}-->
  13. <!--{assign var=image_path value="`$arrItemHistory[cnt].main_list_image`"}-->
  14. <!--{else}-->
  15. <!--{assign var=image_path value="`$smarty.const.NO_IMAGE_DIR`"}-->
  16. <!--{/if}-->
  17.  
  18. <a href="<!--{$smarty.const.DETAIL_P_HTML}--><!--{$arrItemHistory[cnt].product_id}-->">
  19. <img src="<!--{$smarty.const.SITE_URL}-->resize_image.php?image=<!--{$image_path|sfRmDupSlash}-->&width=65&height=65" alt="<!--{$arrItemHistory[cnt].name|escape}-->" />
  20. </a>
  21.  
  22. <!--{assign var=price02_min value=`$arrItemHistory[cnt].price02_min`}-->
  23. <!--{assign var=price02_max value=`$arrItemHistory[cnt].price02_max`}-->
  24. <h3><a href="<!--{$smarty.const.DETAIL_P_HTML}--><!--{$arrItemHistory[cnt].product_id}-->"><!--{$arrItemHistory[cnt].name|escape}--></a></h3>
  25.  
  26. <p>価格<span class="mini">(税込)</span><span class="price">
  27. <!--{if $price02_min == $price02_max}-->
  28. <!--{$price02_min|sfPreTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}-->
  29. <!--{else}-->
  30. <!--{$price02_min|sfPreTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}--><!--{$price02_max|sfPreTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}-->
  31. <!--{/if}--></span></p>
  32. <p class="mini"><!--{$arrItemHistory[cnt].comment|escape|nl2br}--></p>
  33. </div>
  34. <!-- 左列 -->
  35.  
  36. <!--{/if}-->
  37.  
  38. <!--{if ($smarty.section.cnt.index % 2) != 0}-->
  39. <!--{* assign var=nextCnt value=$smarty.section.cnt.index+1 *}-->
  40. <!--{if $arrItemHistory[cnt].product_id}-->
  41. <!-- 右列 -->
  42. <div class="whoboughtright">
  43. <a href="<!--{$smarty.const.DETAIL_P_HTML}--><!--{$arrItemHistory[cnt].product_id}-->">
  44. <!--{if $arrItemHistory[cnt].main_list_image != ""}-->
  45. <!--{assign var=image_path value="`$arrItemHistory[cnt].main_list_image`"}-->
  46. <!--{else}-->
  47. <!--{assign var=image_path value="`$smarty.const.NO_IMAGE_DIR`"}-->
  48. <!--{/if}-->
  49. <img src="<!--{$smarty.const.SITE_URL}-->resize_image.php?image=<!--{$image_path|sfRmDupSlash}-->&width=65&height=65" alt="<!--{$arrItemHistory[cnt].name|escape}-->" />
  50. </a>
  51. <!--{assign var=price02_min value=`$arrItemHistory[cnt].price02_min`}-->
  52. <!--{assign var=price02_max value=`$arrItemHistory[cnt].price02_max`}-->
  53. <h3><a href="<!--{$smarty.const.DETAIL_P_HTML}--><!--{$arrItemHistory[cnt].product_id}-->"><!--{$arrItemHistory[cnt].name|escape}--></a></h3>
  54.  
  55. <p>価格<span class="mini">(税込)</span><span class="price">
  56.  
  57. <!--{if $price02_min == $price02_max}-->
  58. <!--{$price02_min|sfPreTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}-->
  59. <!--{else}-->
  60. <!--{$price02_min|sfPreTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}--><!--{$price02_max|sfPreTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}-->
  61. <!--{/if}--></span></p>
  62. <p class="mini"><!--{$arrItemHistory[cnt].comment|escape|nl2br}--></p>
  63. </div>
  64. <!-- 右列 -->
  65. <!--{/if}-->
  66. <!--{/if}-->
  67.  
  68.  
  69. </div>
  70. <!--{/if}-->
  71. <!--{/section}-->
  72.  
  73. </div>
  74. <!--{/if}-->
  75.  
  76. <!--▲閲覧履歴ここまで 2009.05.01-->
  77.  
  78. </div>
  79. <!--▲CONTENTS-->
  80.  
  81.  

カスタマイズ結果


こーんな感じになりました。
商品詳細まで見た商品しか表示されないので。あしからず。

最終更新:2009年05月01日 17:18
ツールボックス

下から選んでください:

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