[EC-CUBE]人気ランキングを表示する

「[EC-CUBE]人気ランキングを表示する」の編集履歴(バックアップ)一覧はこちら

[EC-CUBE]人気ランキングを表示する」(2009/05/11 (月) 10:30:26) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

**売れ筋商品をランキング形式で表示させる。 こんな感じで。 &ref(ranking.jpg) では、さっそくカスタマイズ。 /html/frontparts/bloc/rankig.php インクルードしているファイルの名前を変更する #highlight(linenumber,php){{ <?php require_once(CLASS_EX_PATH . "page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Ranking_Ex.php"); $objPage = new LC_Page_FrontParts_Bloc_Ranking_Ex(); register_shutdown_function(array($objPage, "destroy")); $objPage->init(); $objPage->process(); ?> }} /data/class_extends/page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Ranking_Ex.php これまたインクルード先を変える。 #highlight(linenumber,php){{ <?php require_once(CLASS_PATH . "pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Ranking_Ex.php"); /** * ランキング のページクラス(拡張). * * LC_Page_FrontParts_Bloc_Ranking をカスタマイズする場合はこのクラスを編集する. */ class LC_Page_FrontParts_Bloc_Ranking_Ex extends LC_Page_FrontParts_Bloc_Ranking { /** * Page を初期化する. * * @return void */ function init() { parent::init(); } /** * Page のプロセス. * * @return void */ function process() { parent::process(); } /** * デストラクタ. * * @return void */ function destroy() { parent::destroy(); } } ?> }} /data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Ranking.php これはBest5をコピーしてロジックを編集する。 #highlight(linenumber,php){{ <?php require_once(CLASS_PATH . "pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php"); /** * ランキング のページクラス. */ class LC_Page_FrontParts_Bloc_Ranking extends LC_Page_FrontParts_Bloc { /** * Page を初期化する. * * @return void */ function init() { parent::init(); $bloc_file = 'ranking.tpl'; $this->setTplMainpage($bloc_file); } /** * Page のプロセス. * * @return void */ function process() { if (defined("MOBILE_SITE") && MOBILE_SITE) { $objView = new SC_MobileView(); } else { $objView = new SC_SiteView(); } $objSiteInfo = $objView->objSiteInfo; // 基本情報を渡す $objSiteInfo = new SC_SiteInfo(); $this->arrInfo = $objSiteInfo->data; // ランキング表示 2009.05.08追加 $this->arrRanking = $this->lfGetRanking(); $objView->assignobj($this); objView->display($this->tpl_mainpage); //おすすめ商品表示 //$this->arrBestProducts = $this->lfGetRanking(); //$objView->assignobj($this); //objView->display($this->tpl_mainpage); } /** * モバイルページを初期化する. * * @return void */ function mobileInit() { $this->tpl_mainpage = MOBILE_TEMPLATE_DIR . "frontparts/" . BLOC_DIR . 'ranking.tpl'; } /** * Page のプロセス(モバイル). * * @return void */ function mobileProcess() { $this->process(); } /** * デストラクタ. * * @return void */ function destroy() { parent::destroy(); } // ランキング検索 function lfGetRanking(){ $objQuery = new SC_Query(); $col = "T1.product_id, T1.product_name as name, T3.main_list_image, COUNT(*) as order_count"; $from = "dtb_order_detail AS T1 INNER JOIN dtb_order AS T2 ON T1.order_id = T2.order_id INNER JOIN dtb_products AS T3 ON T1.product_id = T3.product_id"; $objQuery->setgroupby("T1.product_id, T1.product_name, T3.main_list_image"); $objQuery->setorder("order_count DESC"); $objQuery->setlimit(5); return $objQuery->select($col, $from); } } ?> }} ブロックを追加する。 管理画面>デザイン管理>ブロック編集 ブロック名 ランキング ファイル名 ranking ※ランキング用の画像は別途用意する必要あり。 #highlight(linenumber,php){{ <!--{if count($arrRanking) > 0}--> <h2> <img src="<!--{$TPL_DIR}-->img/side/title_ranking.jpg" width="166" height="35" alt="ランキング" /> </h2> <div id="rankingarea"> <ul> <!--{foreach from=$arrRanking key=myId item=i}--> <li> <a href="<!--{$smarty.const.DETAIL_P_HTML}--><!--{$i.product_id}-->"> <img src="<!--{$smarty.const.IMAGE_SAVE_URL|sfTrimURL}-->/<!--{$i.main_list_image}-->" width="130px" alt="<!--{$i.name}-->"> <!--{assign var=rank value=$myId+1}--> <span><!--{$rank}-->位:<!--{$i.name}--></span> </a> </li> <!--{/foreach}--> </ul> </div> <!--{/if}--> }} CSS編集 ランキング用のCSSを追加 /html/user_data/packages/default/css/main.css #highlight(linenumber,php){{ /* ランキング @2009.05.08追加 ----------------------------------------------- */ div#rankingarea { width: 144px; padding: 0 10px 10px 10px; border: solid 1px #ccc; } div#rankingarea img { padding: 0px; margin: 2px auto; vertical-align: bottom; display: block; } div#rankingarea ul li { margin-top: 6px; } div#rankingarea ul li span { clear: both; } div#rankingarea ul li a { font-weight:bold; color: red; text-decoration: none; display: block; } div#rankingarea ul li a:hover { color: red; background-color: #DDDDDD; } }} DBに値を追加する。 dtb_blocテーブルに先ほど追加した「ランキング」ブロックのデータが反映されているので、 そこのphp_pathを以下の値で更新する。 frontparts/bloc/ranking.php
**売れ筋商品をランキング形式で表示させる。 売上の1~5位をランキング形式で表示。 こんな感じで。 &ref(ranking.jpg) では、さっそくカスタマイズ。 /html/frontparts/bloc/rankig.php インクルードしているファイルの名前を変更する #highlight(linenumber,php){{ <?php require_once(CLASS_EX_PATH . "page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Ranking_Ex.php"); $objPage = new LC_Page_FrontParts_Bloc_Ranking_Ex(); register_shutdown_function(array($objPage, "destroy")); $objPage->init(); $objPage->process(); ?> }} /data/class_extends/page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Ranking_Ex.php これまたインクルード先を変える。 #highlight(linenumber,php){{ <?php require_once(CLASS_PATH . "pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Ranking_Ex.php"); /** * ランキング のページクラス(拡張). * * LC_Page_FrontParts_Bloc_Ranking をカスタマイズする場合はこのクラスを編集する. */ class LC_Page_FrontParts_Bloc_Ranking_Ex extends LC_Page_FrontParts_Bloc_Ranking { /** * Page を初期化する. * * @return void */ function init() { parent::init(); } /** * Page のプロセス. * * @return void */ function process() { parent::process(); } /** * デストラクタ. * * @return void */ function destroy() { parent::destroy(); } } ?> }} /data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Ranking.php これはBest5をコピーしてロジックを編集する。 #highlight(linenumber,php){{ <?php require_once(CLASS_PATH . "pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php"); /** * ランキング のページクラス. */ class LC_Page_FrontParts_Bloc_Ranking extends LC_Page_FrontParts_Bloc { /** * Page を初期化する. * * @return void */ function init() { parent::init(); $bloc_file = 'ranking.tpl'; $this->setTplMainpage($bloc_file); } /** * Page のプロセス. * * @return void */ function process() { if (defined("MOBILE_SITE") && MOBILE_SITE) { $objView = new SC_MobileView(); } else { $objView = new SC_SiteView(); } $objSiteInfo = $objView->objSiteInfo; // 基本情報を渡す $objSiteInfo = new SC_SiteInfo(); $this->arrInfo = $objSiteInfo->data; // ランキング表示 2009.05.08追加 $this->arrRanking = $this->lfGetRanking(); $objView->assignobj($this); objView->display($this->tpl_mainpage); //おすすめ商品表示 //$this->arrBestProducts = $this->lfGetRanking(); //$objView->assignobj($this); //objView->display($this->tpl_mainpage); } /** * モバイルページを初期化する. * * @return void */ function mobileInit() { $this->tpl_mainpage = MOBILE_TEMPLATE_DIR . "frontparts/" . BLOC_DIR . 'ranking.tpl'; } /** * Page のプロセス(モバイル). * * @return void */ function mobileProcess() { $this->process(); } /** * デストラクタ. * * @return void */ function destroy() { parent::destroy(); } // ランキング検索 function lfGetRanking(){ $objQuery = new SC_Query(); $col = "T1.product_id, T1.product_name as name, T3.main_list_image, COUNT(*) as order_count"; $from = "dtb_order_detail AS T1 INNER JOIN dtb_order AS T2 ON T1.order_id = T2.order_id INNER JOIN dtb_products AS T3 ON T1.product_id = T3.product_id"; $objQuery->setgroupby("T1.product_id, T1.product_name, T3.main_list_image"); $objQuery->setorder("order_count DESC"); $objQuery->setlimit(5); return $objQuery->select($col, $from); } } ?> }} ブロックを追加する。 管理画面>デザイン管理>ブロック編集 ブロック名 ランキング ファイル名 ranking ※ランキング用の画像は別途用意する必要あり。 #highlight(linenumber,php){{ <!--{if count($arrRanking) > 0}--> <h2> <img src="<!--{$TPL_DIR}-->img/side/title_ranking.jpg" width="166" height="35" alt="ランキング" /> </h2> <div id="rankingarea"> <ul> <!--{foreach from=$arrRanking key=myId item=i}--> <li> <a href="<!--{$smarty.const.DETAIL_P_HTML}--><!--{$i.product_id}-->"> <img src="<!--{$smarty.const.IMAGE_SAVE_URL|sfTrimURL}-->/<!--{$i.main_list_image}-->" width="130px" alt="<!--{$i.name}-->"> <!--{assign var=rank value=$myId+1}--> <span><!--{$rank}-->位:<!--{$i.name}--></span> </a> </li> <!--{/foreach}--> </ul> </div> <!--{/if}--> }} CSS編集 ランキング用のCSSを追加 /html/user_data/packages/default/css/main.css #highlight(linenumber,php){{ /* ランキング @2009.05.08追加 ----------------------------------------------- */ div#rankingarea { width: 144px; padding: 0 10px 10px 10px; border: solid 1px #ccc; } div#rankingarea img { padding: 0px; margin: 2px auto; vertical-align: bottom; display: block; } div#rankingarea ul li { margin-top: 6px; } div#rankingarea ul li span { clear: both; } div#rankingarea ul li a { font-weight:bold; color: red; text-decoration: none; display: block; } div#rankingarea ul li a:hover { color: red; background-color: #DDDDDD; } }} DBに値を追加する。 dtb_blocテーブルに先ほど追加した「ランキング」ブロックのデータが反映されているので、 そこのphp_pathを以下の値で更新する。 frontparts/bloc/ranking.php

表示オプション

横に並べて表示:
変化行の前後のみ表示:
ツールボックス

下から選んでください:

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