2012年2月29日カテゴリー:未分類

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

下記ファイルを作成する
 html\frontparts\bloc\recommend_random.php
 class_extends\page_extends\frontparts\bloc\LC_Page_FrontParts_Bloc_Recommend_random_Ex.php
 class\pages\frontparts\bloc\LC_Page_FrontParts_Bloc_Recommend_random.php
▼データベースによってSQL文を使い分けることで、MySQLとPostgreSQLの両方に対応できる。

[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]

 Smarty\templates\mobile\frontparts\bloc\recommend_random.tpl

(2)データベースにブロックを登録
テーブル:dtb_bloc
device_type_id:1
bloc_id:6
bloc_name:おすすめ商品ランダム
tpl_path:recommend_random.tpl
filename:recommend_random
create_date:作成日
update_date:作成日
php_path:frontparts/bloc/recommend_random.php
deletable_flg:0

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

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