10 月 30

前回にも「新商品ブロックを作ろう」を書きましたが、
「特定のカテゴリーの新商品やお勧め商品を表示できるように設定できないか」
というお問い合わせがありましたので、カテゴリー指定バージョンを書きます。

基本的には前回の通りにブロックを作りましょう。
違うのは、LC_Page_FrontParts_Bloc_New.phpのロジックです。
以下がそのロジックです。

  1. function process() {
  2.  
  3. // 基本情報を渡す
  4. $objSiteInfo = new SC_SiteInfo();
  5. $this->arrInfo = $objSiteInfo->data;
  6.  
  7. $objQuery = new SC_Query();
  8.  
  9. $col    = " product_id, price02_min, price02_max, main_image, name";
  10. $from   = " vw_products_allclass ";
  11. $where  = " substring(product_flag,1,1) = ‘1′";
  12. $where .= " and del_flg = 0 ";
  13. $where .= " and category_id = カテゴリIDを指定";
  14. $order  = " rank";
  15.  
  16. $this->order=$objQuery->setorder($order);
  17. $arrNewProducts = $objQuery->select($col, $from, $where);
  18.  
  19. $this->arrNewProducts = $arrNewProducts;
  20.  
  21. $objSubView = new SC_SiteView();
  22. $objSubView->assignobj($this);
  23. $objSubView->display($this->tpl_mainpage);
  24. }

上記の「カテゴリIDを指定」の箇所に表示させたいカテゴリを指定。

もし、複数カテゴリを指定したい場合は、

  1. $col    = " DISTINCT product_id, price02_min, price02_max, main_image, name";
  2. $from   = " vw_products_allclass ";
  3. $where  = " substring(product_flag,1,1) = ‘1′";
  4. $where .= " and del_flg = 0 ";
  5. $where .= " and category_id IN (カンマ区切りでカテゴリIDを指定)";
  6. $order  = " rank";

と、DISTINCTをかまし、IN句で複数カテゴリを指定しましょう。

おすすめ商品も基本的には同じ。

written by sixbird \\ tags: , , ,

5 月 05

新商品のみを表示するブロックを作ろう。

このブロックは、EC-CUBEの開発コミュニティであがっていたスレッド「新入荷商品をブロックに表示したい」を参考にさせて頂きました。参考というよりも、ほとんど丸々頂いている(duckeiさんに心より感謝)

まず、新規ブロックの作り方から。

  1. 管理画面より、「デザイン管理」→「ブロック編集」にて、
    ブロック名(新商品)、ファイル名(new)を追加。
    その下の大きなテキストボックスには、best5.tplの中身をコピペ。
  2. DBのdtb_blocに新商品ブロックのデータが追加されているので、
    php_path:frontparts/bloc/new.php
    とし更新。
  3. /data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Best5.php
    /data/class_extends/page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Best5_Ex.php
    /frontparts/bloc/best5.php
    上記3ファイルをそれぞれコピーし、Best5(best5)をNew(new)にファイル名を変更。
  4. LC_Page_FrontParts_Bloc_New.php
    LC_Page_FrontParts_Bloc_New_Ex.php
    new.php
    の中身の”Best5″(best5)を”New”(new)に置換。

とりあえずこれでブロック完成。(たぶん)
コピーしただけなので、まだ中身はおすすめ商品のまま。

次、LC_Page_FrontParts_Bloc_New.phpを以下のように修正。

function process() {

// 基本情報を渡す
$objSiteInfo = new SC_SiteInfo();
$this->arrInfo = $objSiteInfo->data;

$objQuery = new SC_Query();

//検索したい商品のステータスを設定
//NEW→1, 残りわずか→2, ポイント2倍→3, オススメ→4, 限定品→5
$productNew = 1;

//検索する商品のステータスをランダムに決定し、表示させたい場合は以下のコメントを外してください。
//$id_count = $objQuery->count(mtb_status);
//$productNew = rand(1,$id_count);

$this->statusName =$objQuery->get(”mtb_status_image”, “name”, “id={$productNew}”);

//表示する商品の件数
$listCount = 99;

$ret = “”;
$arrTmp[$productNew] = “1″;

for($i = 1; $i <= $productNew; $i++) {
if($arrTmp[$i] == “1″) {
$ret.= “1″;
} else {
$ret.= “_”;
}
}

if($ret != “”) {
$ret.= “%”;
}

$col = “DISTINCT price02_min, product_id, price02_max, main_image, product_flag, name”;
$from = “vw_products_allclass AS T1″;
$where = “product_flag LIKE ‘{$ret}’”;
//商品の表示はproduct_id逆順
$order = “product_id DESC”;
$this->order=$objQuery->setorder($order);

$arrNewList = $objQuery->select($col, $from, $where);

//商品の表示をランダムに抽出する場合は以下のコメントを外してください。
//srand((double)microtime()*1000000); //乱数生成器を初期化
//shuffle($arrNewList);

$this->arrNewProducts = $arrNewList;

$objSubView = new SC_SiteView();
$objSubView->assignobj($this);
$objSubView->display($this->tpl_mainpage);
}

元々、新商品以外のステータスにも対応させているため、純粋なる新商品検索処理ではない。
なので、パラメータを変更するだけで、使い回しができる。

テンプレートは/user_data/packages/default/bloc/new.tplに生成されている。
ソースのarrBestProductsをarrNewListに置換。
これで、新商品だけを表示することができる。

新商品ブロックを作ろう(カテゴリ指定)もご覧あれ。

written by sixbird \\ tags: ,