前回にも「新商品ブロックを作ろう」を書きましたが、
「特定のカテゴリーの新商品やお勧め商品を表示できるように設定できないか」
というお問い合わせがありましたので、カテゴリー指定バージョンを書きます。
基本的には前回の通りにブロックを作りましょう。
違うのは、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, name";
-
$from = " vw_products_allclass ";
-
$where = " substring(product_flag,1,1) = ‘1′";
-
$where .= " and del_flg = 0 ";
-
$where .= " and category_id = カテゴリIDを指定";
-
$order = " rank";
-
-
$this->order=$objQuery->setorder($order);
-
$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, 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";
と、DISTINCTをかまし、IN句で複数カテゴリを指定しましょう。
おすすめ商品も基本的には同じ。