Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/c89d37f1a2116878260c to your computer and use it in GitHub Desktop.
Save kurozumi/c89d37f1a2116878260c to your computer and use it in GitHub Desktop.
【EC-CUBE2.13】商品名、カテゴリ、キーワード、価格帯、商品ステータス、規格で絞り込み検索ができる検索フォームページを作成
<?php
require_once '../require.php';
require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
/**
* ユーザーカスタマイズ用のページクラス
*
* 管理画面から自動生成される
*
* @package Page
*/
class LC_Page_User extends LC_Page_Ex {
/**
* Page を初期化する.
*
* @return void
*/
function init()
{
parent::init();
$masterData = new SC_DB_MasterData_Ex();
$this->arrSTATUS = $masterData->getMasterData('mtb_status');
}
/**
* Page のプロセス.
*
* @return void
*/
function process()
{
parent::process();
$this->action();
$this->sendResponse();
}
/**
* Page のアクション.
*
* @return void
*/
function action()
{
// カテゴリID取得
$category_id = $this->lfGetCategoryId();
// 選択中のカテゴリIDを判定する
$this->category_id = $this->lfGetSelectedCategoryId($product_id, $category_id);
// カテゴリ検索用選択リスト
$this->arrCatList = $this->lfGetCategoryList();
// 規格検索用選択リスト
$this->arrClassCat1List = $this->lfGetClassCatList('大きさ');
// 規格検索用選択リスト
$this->arrClassCat2List = $this->lfGetClassCatList('味');
}
/**
* カテゴリIDを取得する.
*
* @return string $category_id カテゴリID
*/
public function lfGetCategoryId()
{
$category_id = '';
if (isset($_GET['category_id']) && $_GET['category_id'] != '' && is_numeric($_GET['category_id'])) {
$category_id = $_GET['category_id'];
}
return $category_id;
}
/**
* 選択中のカテゴリIDを取得する
*
* @param string $product_id
* @param string $category_id
* @return array $arrCategoryId 選択中のカテゴリID
*/
public function lfGetSelectedCategoryId($product_id, $category_id)
{
// 選択中のカテゴリIDを判定する
$objDb = new SC_Helper_DB_Ex();
$arrCategoryId = $objDb->sfGetCategoryId($product_id, $category_id);
return $arrCategoryId;
}
/**
* カテゴリ検索用選択リストを取得する
*
* @return array $arrCategoryList カテゴリ検索用選択リスト
*/
public function lfGetCategoryList()
{
$objDb = new SC_Helper_DB_Ex();
// カテゴリ検索用選択リスト
$arrCategoryList = $objDb->sfGetCategoryList('', true, ' ');
if (is_array($arrCategoryList)) {
// 文字サイズを制限する
foreach ($arrCategoryList as $key => $val) {
$truncate_str = SC_Utils_Ex::sfCutString($val, SEARCH_CATEGORY_LEN, false);
$arrCategoryList[$key] = preg_replace('/ /u', '&nbsp;&nbsp;', $truncate_str);
}
}
return $arrCategoryList;
}
/**
* 有効な規格分類情報の取得
*
* @param string $name
* @return array 規格分類情報
*/
public function lfGetClassCatList($name)
{
$objQuery = & SC_Query_Ex::getSingletonInstance();
$where = 'del_flg <> 1 AND name LIKE ?';
$class_id = $objQuery->get('class_id', 'dtb_class', $where, array($name));
$where = 'del_flg <> 1 AND class_id = ?';
$objQuery->setOrder('rank DESC'); // XXX 降順
$ret = $objQuery->select('name, classcategory_id', 'dtb_classcategory', $where, array($class_id));
$arrClassCatList = array();
if (is_array($ret)) {
foreach ($ret as $val) {
$truncate_str = SC_Utils_Ex::sfCutString($val['name'], SEARCH_CATEGORY_LEN, false);
$arrClassCatList[$val['classcategory_id']] = preg_replace('/ /u', '&nbsp;&nbsp;', $truncate_str);
}
}
return $arrClassCatList;
}
}
$objPage = new LC_Page_User();
$objPage->init();
$objPage->process();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment