12月 17

jquery.suggestを利用して、商品検索ブロックの入力フォームに入力補完機能を追加してみよう。

jquery.suggestのサンプル

ファイルをダウンロードする

まずはVulgarisOverIPサイトからファイルをダウンロード。

ファイルを格納

jquery.suggest.js → /user_data/packages/default/js/
jquery.suggest.css → /user_data/packages/default/css/
へ放り込む。

商品名検索用php作成

EC-CUBEをインストールしたルートディレクトリにjquery_suggestというディレクトリを作成。
そこに以下の内容でname_search.phpというファイルを作成。

<?php
require_once("../require.php");

// 検索結果の取得
$objQuery = new SC_Query();
$col = " name ";
$from = " dtb_products ";
$where = "status = 1 and del_flg = 0";
$arrval = array();

$q = strtolower($_REQUEST["q"]);
if (!$q) return;
$arrProducts = $objQuery->select($col, $from, $where, $arrval);
foreach ($arrProducts as $value) {
	$items[] = $value['name'];
}

foreach ($items as $value) {
	if (strpos(strtolower($value), $q) !== false) {
		echo "$value\n";
	}
}
?>

商品検索ブロック修正

/data/Smarty/templates/default/bloc/search_products.tpl 内の次の1行、

<p><input type="text" name="name" class="box142" maxlength="50" value="<!--{$smarty.get.name|escape}-->" /></p>

を以下に修正(id=”suggest_name”を追加しただけ)

<p><input type="text" name="name" id="suggest_name" class="box142" maxlength="50" value="<!--{$smarty.get.name|escape}-->" /></p>

テンプレートに追加

/data/Smarty/templates/default/site_flame.tpl へ以下を追加。

<link rel="stylesheet" href="<!--{$TPL_DIR}-->css/jquery.suggest.css" type="text/css" media="all" />
<script type="text/javascript" src="<!--{$TPL_DIR}-->js/jquery.js"></script>
<script type="text/javascript" src="<!--{$TPL_DIR}-->js/jquery.suggest.js"></script>
<script type="text/javascript">
jQuery(function() {
jQuery("#suggest_name").suggest("<!--{$smarty.const.URL_DIR}-->jquery_suggest/name_search.php",{});
});
</script>

さぁ、レッツトライ!

うまく動かない場合はご一報を。(全く同じ環境で試してないので…)

written by sixbird \\ tags: ,

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句で複数カテゴリを指定しましょう。

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

written by sixbird \\ tags: , , ,

8月 13

最近はECサイトに人の存在感を与え、そして安心感を与えるためにブログも運営することが多くなった。

そこで、ECサイトにそのブログのRSS情報を非常に簡単に表示する方法。
ただしPHP5が条件。
なぜなら、simplexml_load_fileを使用するから。

EC-CUBEを利用、新規ブロックを作成した場合の方法。

/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Rss.php

function process() {

$memore_rss =simplexml_load_file('http://memo.6-bird.net/feed/');
$this->memore_rss = $memore_rss;

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

/user_data/packages/memore/bloc/rss.tpl

    {foreach from=$memore_rss->channel->item item="datum" key="key" name="memore_rss"}
  1.  
  2. {/foreach}

これで、ブログの記事タイトルにリンクがはられ、ズラーッと表示される。

written by sixbird \\ tags: ,