EC-CUBE2.12:携帯でおすすめ商品をランダムに1つ表示

「おすすめ商品ランダム」というブロックを作成する。
管理画面のブロック配置で、「おすすめ商品」をはずし、「おすすめ商品ランダム」を置く。

▼ここでのカスタマイズファイルをすべてダウンロードできます。
必要な箇所だけコピーしてご利用ください。
他のカスタマイズも含まれている場合がありますので、ファイルの上書きは絶対におやめください。
こちらから(facebookユーザーのみ)


(1)ブロックの作成
 ■html/frontparts/bloc/recommend_random.php

<?php

// {{{ requires
require_once realpath(dirname(__FILE__)) . '/../../require.php';
require_once CLASS_EX_REALDIR . 'page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Recommend_random_Ex.php';

// }}}
// {{{ generate page

$objPage = new LC_Page_FrontParts_BLoc_Recommend_random_Ex();
$objPage->blocItems = $params['items'];
register_shutdown_function(array($objPage, "destroy"));
$objPage->init();
$objPage->process();
?>

 ■data/class_extends/page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Recommend_random_Ex.php

<?php

// {{{ requires
require_once CLASS_REALDIR . 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Recommend_random.php';

class LC_Page_FrontParts_Bloc_Recommend_random_Ex extends LC_Page_FrontParts_Bloc_Recommend_random {

// }}}
// {{{ functions

/**
* 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_Recommend_random.php

<?php

// {{{ requires
require_once CLASS_REALDIR . 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php';

class LC_Page_FrontParts_Bloc_Recommend_random extends LC_Page_FrontParts_Bloc {

// }}}
// {{{ functions

/**
* Page を初期化する.
*
* @return void
*/
function init() {
parent::init();
}

/**
* Page のプロセス.
*
* @return void
*/
function process() {
$this->action();
$this->sendResponse();
}

/**
* Page のアクション.
*
* @return void
*/
function action() {

// 基本情報を渡す
$objSiteInfo = SC_Helper_DB_Ex::sfGetBasisData();
$this->arrInfo = $objSiteInfo->data;

// 使用しているデータベースサーバー名を取得
$objDB = SC_DB_DBFactory_Ex::getInstance();
$arrSystemInfo = $objDB->sfGetDBVersion();

if(isset($arrSystemInfo)){
$this->arrSystemInfo = $arrSystemInfo;
}

//データ取得
$objQuery =SC_Query_Ex::getSingletonInstance();
$this->arrRet = array();

//おすすめ商品を取得
$string = $arrSystemInfo;
if (preg_match("/MySQL/", $string)) {
$arrRet = $objQuery->select("*", "dtb_products inner join dtb_best_products on dtb_products.product_id=dtb_best_products.product_id", "dtb_products.del_flg = 0 order by rand() limit 0, 1");
}else{
$arrRet = $objQuery->select("*", "dtb_products inner join dtb_best_products on dtb_products.product_id=dtb_best_products.product_id", "dtb_products.del_flg = 0 order by random() limit 1");
}

//データベースからデータの取得ができたか
if(isset($arrRet)){
$this->arrRet = $arrRet;
}

}

/**
* デストラクタ.
*
* @return void
*/
function destroy() {
parent::destroy();
}

}
?>

 ■data/Smarty/templates/mobile/frontparts/bloc/recommend_random.tpl

<!--{if count($arrRet) > 0}-->
<!-- ▼おすすめ商品ランダム表示 -->
<center><img src="<!--{$TPL_URLPATH}-->img/til_recommend.jpg" alt=""></center><br>
<!--{section name=cnt loop=$arrRet}-->
<center><a href="<!--{$smarty.const.P_DETAIL_URLPATH}--><!--{$arrRet[cnt].product_id|u}-->.html"><img src="<!--{$smarty.const.IMAGE_SAVE_URLPATH}--><!--{$arrRet[cnt].main_list_image|h}-->"></a></center><br>
<center><a href="<!--{$smarty.const.P_DETAIL_URLPATH}--><!--{$arrRet[cnt].product_id|u}-->.html"><!--{$arrRet[cnt].name|h}--></a></center><br>
<!--{/section}-->
<!--{/if}-->
<!-- ▲おすすめ商品ランダム表示 -->

(2)データベースにブロックを登録
テーブル:dtb_bloc

INSERT INTO dtb_bloc (device_type_id, bloc_id, bloc_name, tpl_path, filename, create_date, update_date, php_path, deletable_flg) VALUES (1, 6, 'おすすめ商品ランダム', 'recommend_random.tpl', 'recommend_random', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'frontparts/bloc/recommend_random.php', 0);

(3)■html/user_data/packages/mobile/imgフォルダにtil_recommend.jpgを追加

(4)管理画面「デザイン管理>モバイル>レイアウト設定」「TOPページ」配置で、「おすすめ商品」をはずし、「おすすめ商品ランダム」を置く。