2012年10月7日カテゴリー:未分類

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

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

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


(1)ブロックの作成
 ■html/frontparts/bloc/recommend_random.php
[php]
blocItems = $params[‘items’];
register_shutdown_function(array($objPage, “destroy”));
$objPage->init();
$objPage->process();
?>
[/php]

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

[/php]

 ■data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Recommend_random.php
[php]
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();
}

}
?>
[/php]

 ■data/Smarty/templates/mobile/frontparts/bloc/recommend_random.tpl
[php]


.html”>.html”>




[/php]

(2)データベースにブロックを登録
テーブル:dtb_bloc
[php]
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);
[/php]

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

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