|
10月 30
|
前回にも「新商品ブロックを作ろう」を書きましたが、
「特定のカテゴリーの新商品やお勧め商品を表示できるように設定できないか」
というお問い合わせがありましたので、カテゴリー指定バージョンを書きます。
基本的には前回の通りにブロックを作りましょう。
違うのは、LC_Page_FrontParts_Bloc_New.phpのロジックです。
以下がそのロジックです。
function process() {
// 基本情報を渡す
$objSiteInfo = new SC_SiteInfo();
$this->arrInfo = $objSiteInfo->data;
$objQuery = new SC_Query();
$col = " product_id, price02_min, price02_max, main_image, main_list_image, name";
$from = " vw_products_allclass ";
$where = " substring(product_flag,1,1) = '1'";
$where .= " and del_flg = 0 ";
$where .= " and category_id = カテゴリIDを指定";
$order = " rank";
// $order = "random()"; ←ランダムで取得したい場合こちら( MySQLはrand() )
// ソート
$this->order=$objQuery->setorder($order);
// 取得範囲の指定
$page_max = 5; // 取得件数を設定
$startno = 0; // 開始番号を設定(1件目はゼロとなる)
$objQuery->setlimitoffset($page_max, $startno);
$arrNewProducts = $objQuery->select($col, $from, $where);
$this->arrNewProducts = $arrNewProducts;
$objSubView = new SC_SiteView();
$objSubView->assignobj($this);
$objSubView->display($this->tpl_mainpage);
}
上記の「カテゴリIDを指定」の箇所に表示させたいカテゴリを指定。
もし、複数カテゴリを指定したい場合は、
$col = " DISTINCT product_id, price02_min, price02_max, main_image, main_list_image, name"; $from = " vw_products_allclass "; $where = " substring(product_flag,1,1) = '1'"; $where .= " and del_flg = 0 "; $where .= " and category_id IN (カンマ区切りでカテゴリIDを指定)"; $order = " rank"; // $order = "random()"; ←ランダムで取得したい場合こちら( MySQLはrand() )
と、DISTINCTをかまし、IN句で複数カテゴリを指定しましょう。
おすすめ商品も基本的には同じ。
Recent Comment