EC-CUBE カスタマイズ 売れ筋商品をランキング表示!
カスタマイズ:応用/ランキング表示
売れ筋商品の上位をランキング表示させる機能を追加します。
データベースからの情報の取り出し方で、何を基準にランキングするかのカスタマイズが可能です。
ちなみにEC-Orangeではレコメンド機能にも対応しています。
ECサイトでは、”ついで買い”はとっても重要な購買行動の一つです。
関連性の高いものに結びついた商品は、購買の確率をぐっとあげますし、
読み手にも新しい発見や流行を提供されると、閲覧が楽しいもの
ランキングが載ってだけで、特に女性はチェックしたくなっちゃいます!
たくさんの商品をお客様に見ていただきましょう。
ランキング表示については、EC-CUBE No.1パートナー 最新情報ブログにも記事があります。
「ランキング」、「「ちゃんとやるだけ」大規模ECサイト(その4)」もご参照ください。
EC-CUBEのQ&Aにもランキングの並べ替えについての記事があります。
システム開発でお悩みの方は、ネットショップ構築パッケージ EC-Orange にお問い合わせください
編集するファイル
以下のファイルを新規に作成します。
/data/class_extends/page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Ranking_Ex.php
/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Ranking.php
/data/Smarty/templates/default/bloc/ranking.tpl
※Page_FrontParts_Bloc_Ranking_Ex.phpを作らずに、ranking.phpとLC_Page_FrontParts_Bloc_Ranking.phpを直接繋ぐことも可能ですが、今後さらにカスタマイズが入る場合を考慮して、デフォルトの機能と同じ構成としています。
すべて、構成の近い「best5」のファイルをコピーして、編集していきます。
rankig.phpの編集
このファイルでの処理は特にありませんので、インクルードするファイルのパスを変更しておきます。
- require_once(CLASS_EX_PATH . "page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Best5_Ex.php");
- require_once(CLASS_EX_PATH . "page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Ranking_Ex.php");
- $objPage = new LC_Page_FrontParts_BLoc_Best5_Ex();
- $objPage = new LC_Page_FrontParts_BLoc_Ranking_Ex();
LC_Page_FrontParts_Bloc_Ranking_Ex.phpの編集
このファイルも同様です。インクルードするファイルを変更しておきます。
- require_once(CLASS_PATH . "pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Best5.php");
- require_once(CLASS_PATH . "pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Ranking.php");
- class LC_Page_FrontParts_Bloc_Best5_Ex extends LC_Page_FrontParts_Bloc_Best5 {
- class LC_Page_FrontParts_Bloc_Ranking_Ex extends LC_Page_FrontParts_Bloc_Ranking {
LC_Page_FrontParts_Bloc_Ranking.php
このファイルはロジックを修正していきます。
- class LC_Page_FrontParts_Bloc_Best5 extends LC_Page_FrontParts_Bloc {
- class LC_Page_FrontParts_Bloc_Ranking extends LC_Page_FrontParts_Bloc {
- function init() {
- parent::init();
- $bloc_file = 'best5.tpl';
- $this->setTplMainpage($bloc_file);
- }
- function init() {
- parent::init();
- $bloc_file = 'ranking.tpl';
- $this->setTplMainpage($bloc_file);
- }
- //おすすめ商品表示
- $this->arrBestProducts = $this->lfGetRanking();
- $objView->assignobj($this);
- $objView->display($this->tpl_mainpage);
- //ランキング表示
- $this->arrRanking = $this->lfGetRanking();
- $objView->assignobj($this);
- $objView->display($this->tpl_mainpage);
- //おすすめ商品検索
- function lfGetRanking(){
- $objQuery = new SC_Query();
- $col = "DISTINCT A.*, name, price02_min, price01_min, main_list_image ";
- $from = "dtb_best_products AS A INNER JOIN vw_products_allclass AS allcls using(product_id)";
- $where = "status = 1";
- $order = "rank";
- $objQuery->setorder($order);
- $arrBestProducts = $objQuery->select($col, $from, $where);
- return $arrBestProducts;
- }
- //ランキング検索
- 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.tplの編集
- <!--▼おすすめ情報ここから-->
- ・
- ・
- ・
- <!--{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}-->
ランキング用の画像などは別途作成する必要があります。
main.cssの編集
ランキング部分用のCSSを追加しておきます。
- /* ランキング
- ----------------------------------------------- */
- 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;;
- }
dtb_blocにパスを追加
php_pathカラムに
frontparts/bloc/ranking.php
を追加します。
これで作業は完了です。
管理画面のデザイン管理からブロックを追加してください。
※購入データが存在しないと、何も表示されませんのでご注意ください。
EC-CUBEのカスタマイズ・制作会社 強いネットショップ構築します|EC-Orange





