Source for file SC_Helper_DB.php
Documentation is available at SC_Helper_DB.php
* This file is part of EC-CUBE
* Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* @author LOCKON CO.,LTD.
* @version $Id:SC_Helper_DB.php 15532 2007-08-31 14:39:46Z nanasess $
* @param string $dsn データソース名
* @return string データベースのバージョン
$dbFactory = SC_DB_DBFactory_Ex::getInstance();
return $dbFactory->sfGetDBVersion($dsn);
* @param string $table_name チェック対象のテーブル名
* @param string $dsn データソース名
* @return テーブルが存在する場合 true
$dbFactory = SC_DB_DBFactory_Ex::getInstance();
$dsn = $dbFactory->getDSN($dsn);
$objQuery = new SC_Query($dsn, true, true);
if(!$objQuery->isError()) {
list ($db_type) = split(":", $dsn);
$sql = $dbFactory->getTableExistsSql();
$arrRet = $objQuery->getAll($sql, array($table_name));
* チェック対象のテーブルに, 該当のカラムが存在するかチェックする.
* 引数 $add が true の場合, 該当のカラムが存在しない場合は, カラムの生成を行う.
* カラムの生成も行う場合は, $col_type も必須となる.
* @param string $table_name テーブル名
* @param string $column_name カラム名
* @param string $col_type カラムのデータ型
* @param string $dsn データソース名
* @param bool $add カラムの作成も行う場合 true
* @return bool カラムが存在する場合とカラムの生成に成功した場合 true,
* 引数 $add == false でカラムが存在しない場合 false
function sfColumnExists($table_name, $col_name, $col_type = "", $dsn = "", $add = false) {
$dbFactory = SC_DB_DBFactory_Ex::getInstance();
$dsn = $dbFactory->getDSN($dsn);
$objQuery = new SC_Query($dsn, true, true);
if(!$objQuery->isError()) {
list ($db_type) = split(":", $dsn);
$arrRet = $dbFactory->sfGetColumnList($table_name);
$objQuery->query("ALTER TABLE $table_name ADD $col_name $col_type ");
* チェック対象のテーブルに, 該当のインデックスが存在するかチェックする.
* 引数 $add が true の場合, 該当のインデックスが存在しない場合は, インデックスの生成を行う.
* インデックスの生成も行う場合で, DB_TYPE が mysql の場合は, $length も必須となる.
* @param string $table_name テーブル名
* @param string $column_name カラム名
* @param string $index_name インデックス名
* @param integer|string$length インデックスを作成するデータ長
* @param string $dsn データソース名
* @param bool $add インデックスの生成もする場合 true
* @return bool インデックスが存在する場合とインデックスの生成に成功した場合 true,
* 引数 $add == false でインデックスが存在しない場合 false
function sfIndexExists($table_name, $col_name, $index_name, $length = "", $dsn = "", $add = false) {
$dbFactory = SC_DB_DBFactory_Ex::getInstance();
$dsn = $dbFactory->getDSN($dsn);
$objQuery = new SC_Query($dsn, true, true);
$arrRet = $dbFactory->getTableIndex($index_name, $table_name);
$dbFactory->createTableIndex($index_name, $table_name, $col_name, $length());
* @param string $table_name テーブル名
* @param string $where データを検索する WHERE 句
* @param string $dsn データソース名
* @param string $sql データの追加を行う場合の SQL文
* @param bool $add データの追加も行う場合 true
* @return bool データが存在する場合 true, データの追加に成功した場合 true,
* $add == false で, データが存在しない場合 false
function sfDataExists($table_name, $where, $arrval, $dsn = "", $sql = "", $add = false) {
$dbFactory = SC_DB_DBFactory_Ex::getInstance();
$dsn = $dbFactory->getDSN($dsn);
$objQuery = new SC_Query($dsn, true, true);
$count = $objQuery->count($table_name, $where, $arrval);
* @return array 店舗基本情報の配列
$arrRet = $objQuery->select('*', 'dtb_baseinfo');
if (isset ($arrRet[0])) return $arrRet[0];
/* 選択中のアイテムのルートカテゴリIDを取得する */
if (!isset ($_GET['product_id'])) $_GET['product_id'] = "";
if (!isset ($_GET['category_id'])) $_GET['category_id'] = "";
if(!empty($_GET['product_id']) || !empty($_GET['category_id'])) {
$category_id = $this->sfGetCategoryId($_GET['product_id'], $_GET['category_id']);
$arrRet = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id);
$root_id = isset ($arrRet[0]) ? $arrRet[0] : "";
* @param array $arrID 規格ID
list ($product_id, $classcategory_id1, $classcategory_id2) = $arrID;
if($classcategory_id1 == "") {
$classcategory_id1 = '0';
if($classcategory_id2 == "") {
$classcategory_id2 = '0';
$col = "product_id, deliv_fee, name, product_code, main_list_image, main_image, price01, price02, point_rate, product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited, sale_limit, sale_unlimited";
$table = "vw_product_class AS prdcls";
$where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ? AND status = 1";
$objQuery->setOrder("rank1 DESC, rank2 DESC");
$arrRet = $objQuery->select($col, $table, $where, array($product_id, $classcategory_id1, $classcategory_id2));
$objQuery->setOrder("fix, rank DESC");
$arrRet = $objQuery->select("payment_id, payment_method, rule", "dtb_payment", $where);
* @param LC_Page $objPage ページクラスのインスタンス
* @param SC_CartSession $objCartSess カートセッションのインスタンス
* @param array $arrInfo 商品情報の配列
* @return LC_Page 集計処理後のページクラスインスタンス
function sfTotalCart(&$objPage, $objCartSess, $arrInfo) {
$arrClassCatName = $this->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
$objPage->tpl_total_pretax = 0; // 費用合計(税込み)
$objPage->tpl_total_tax = 0; // 消費税合計
if (USE_POINT === true) {
$objPage->tpl_total_point = 0; // ポイント合計
$arrCart = $objCartSess->getCartList();
for ($i = 0; $i < $max; $i++ ) {
if (count($arrData) > 0) {
if ($arrData['stock_unlimited'] != '1' && $arrData['sale_unlimited'] != '1') {
$limit = min($arrData['sale_limit'], $arrData['stock']);
} elseif ($arrData['sale_unlimited'] != '1') {
$limit = $arrData['sale_limit'];
// 購入制限なしの場合は、SALE_LIMIT_MAXが最大購入個数
// 但し、SALE_LIMIT_MAXは、有効な整数値でないと機能しない
if ($arrData['stock_unlimited'] != '1') {
// 在庫制限がある場合は、SALE_LIMIT_MAXと在庫数の小さい方が購入可能最大数
if (SALE_LIMIT_MAX > 0) {
$limit = min(SALE_LIMIT_MAX, $arrData['stock']);
$limit = $arrData['stock'];
if (SALE_LIMIT_MAX > 0) {
if($limit != "" && $limit < $arrCart[$i]['quantity']) {
$objCartSess->setProductValue($arrCart[$i]['id'], 'quantity', $limit);
$objPage->tpl_message = "※「" . $arrData['name'] . "」は販売制限しております、一度にこれ以上の購入はできません。";
$quantity = $arrCart[$i]['quantity'];
$objPage->arrProductsClass[$cnt] = $arrData;
$objPage->arrProductsClass[$cnt]['quantity'] = $quantity;
$objPage->arrProductsClass[$cnt]['cart_no'] = $arrCart[$i]['cart_no'];
$objPage->arrProductsClass[$cnt]['class_name1'] =
isset ($arrClassName[$arrData['class_id1']])
? $arrClassName[$arrData['class_id1']] : "";
$objPage->arrProductsClass[$cnt]['class_name2'] =
isset ($arrClassName[$arrData['class_id2']])
? $arrClassName[$arrData['class_id2']] : "";
$objPage->arrProductsClass[$cnt]['classcategory_name1'] =
$arrClassCatName[$arrData['classcategory_id1']];
$objPage->arrProductsClass[$cnt]['classcategory_name2'] =
$arrClassCatName[$arrData['classcategory_id2']];
$main_image_path = IMAGE_SAVE_DIR . basename($objPage->arrProductsClass[$cnt]["main_image"]);
list ($image_width, $image_height) = getimagesize($main_image_path);
$objPage->arrProductsClass[$cnt]["tpl_image_width"] = $image_width + 60;
$objPage->arrProductsClass[$cnt]["tpl_image_height"] = $image_height + 80;
if ($arrData['price02'] != "") {
$objCartSess->setProductValue($arrCart[$i]['id'], 'price', $arrData['price02']);
$objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price02'];
$objCartSess->setProductValue($arrCart[$i]['id'], 'price', $arrData['price01']);
$objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price01'];
if (USE_POINT === true) {
$objCartSess->setProductValue($arrCart[$i]['id'], 'point_rate', $arrData['point_rate']);
$objPage->arrProductsClass[$cnt]['total_pretax'] = $objCartSess->getProductTotal($arrInfo, $arrCart[$i]['id']);
$objPage->tpl_total_deliv_fee+= ($arrData['deliv_fee'] * $arrCart[$i]['quantity']);
} else { // DBに商品が見つからない場合はカート商品の削除
$objPage->tpl_message .= "※申し訳ございませんが、ご購入の直前で売り切れた商品があります。該当商品をカートから削除いたしました。\n";
$objCartSess->delProductKey('id', $arrCart[$i]['id']);
$objPage->tpl_total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
$objPage->tpl_total_tax = $objCartSess->getAllProductsTax($arrInfo);
if (USE_POINT === true) {
$objPage->tpl_total_point = $objCartSess->getAllProductsPoint();
* @param string $uniqid ユニークID
* @param array $sqlval SQLの値の配列
$where = "order_temp_id = ?";
$cnt = $objQuery->count("dtb_order_temp", $where, array($uniqid));
// 初回書き込み時に会員の登録済み情報を取り込む
$sqlval['create_date'] = "now()";
$objQuery->insert("dtb_order_temp", $sqlval);
$objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid));
* @param string $uniqid ユニークID
* @param array $sqlval SQL の値の配列
* @return array 会員情報を含んだ SQL の値の配列
if ($objCustomer->isLoginSuccess(true)) {
$sqlval['order_temp_id'] = $uniqid;
$sqlval['update_date'] = 'Now()';
$sqlval['customer_id'] = $objCustomer->getValue('customer_id');
$sqlval['order_name01'] = $objCustomer->getValue('name01');
$sqlval['order_name02'] = $objCustomer->getValue('name02');
$sqlval['order_kana01'] = $objCustomer->getValue('kana01');
$sqlval['order_kana02'] = $objCustomer->getValue('kana02');
$sqlval['order_sex'] = $objCustomer->getValue('sex');
$sqlval['order_zip01'] = $objCustomer->getValue('zip01');
$sqlval['order_zip02'] = $objCustomer->getValue('zip02');
$sqlval['order_pref'] = $objCustomer->getValue('pref');
$sqlval['order_addr01'] = $objCustomer->getValue('addr01');
$sqlval['order_addr02'] = $objCustomer->getValue('addr02');
$sqlval['order_tel01'] = $objCustomer->getValue('tel01');
$sqlval['order_tel02'] = $objCustomer->getValue('tel02');
$sqlval['order_tel03'] = $objCustomer->getValue('tel03');
$email_mobile = $objCustomer->getValue('email_mobile');
if (empty($email_mobile)) {
$sqlval['order_email'] = $objCustomer->getValue('email');
$sqlval['order_email'] = $email_mobile;
$sqlval['order_email'] = $objCustomer->getValue('email');
$sqlval['order_job'] = $objCustomer->getValue('job');
$sqlval['order_birth'] = $objCustomer->getValue('birth');
* @param array $array パラメータの配列
* @param array $arrRegistColumn 登録するカラムの配列
foreach ($arrRegistColumn as $data) {
if ($data["column"] != "password") {
if($array[ $data['column'] ] != "") {
$arrRegist[ $data["column"] ] = $array[ $data["column"] ];
$arrRegist[ $data['column'] ] = NULL;
if (strlen($array["year"]) > 0 && strlen($array["month"]) > 0 && strlen($array["day"]) > 0) {
$arrRegist["birth"] = $array["year"] . "/". $array["month"] . "/". $array["day"] . " 00:00:00";
$arrRegist["birth"] = NULL;
//-- パスワードの更新がある場合は暗号化。(更新がない場合はUPDATE文を構成しない)
if ($array["password"] != DEFAULT_PASSWORD) $arrRegist["password"] = sha1($array["password"] . ":" . AUTH_MAGIC);
$arrRegist["update_date"] = "NOW()";
$objQuery->update("dtb_customer", $arrRegist, "customer_id = ? ", array($array['customer_id']));
* 注文番号、利用ポイント、加算ポイントから最終ポイントを取得する.
* @param integer $order_id 注文番号
* @param integer $use_point 利用ポイント
* @param integer $add_point 加算ポイント
* @return array 最終ポイントの配列
$arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id));
$customer_id = $arrRet[0]['customer_id'];
if($customer_id != "" && $customer_id >= 1) {
if (USE_POINT === true) {
$arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
$point = $arrRet[0]['point'];
$total_point = $arrRet[0]['point'] - $use_point + $add_point;
return array($point, $total_point);
* 顧客番号、利用ポイント、加算ポイントから最終ポイントを取得する.
* @param integer $customer_id 顧客番号
* @param integer $use_point 利用ポイント
* @param integer $add_point 加算ポイント
* @return array 最終ポイントの配列
if (USE_POINT === true) {
$arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
$point = $arrRet[0]['point'];
$total_point = $arrRet[0]['point'] - $use_point + $add_point;
return array($point, $total_point);
* @param integer $parent_category_id 親カテゴリID
* @param bool $count_check 登録商品数のチェックを行う場合 true
* @return array カテゴリツリーの配列
function sfGetCatTree($parent_category_id, $count_check = false) {
$col .= " cat.category_id,";
$col .= " cat.category_name,";
$col .= " cat.parent_category_id,";
$col .= " cat.creator_id,";
$col .= " cat.create_date,";
$col .= " cat.update_date,";
$col .= " cat.del_flg, ";
$col .= " ttl.product_count";
$from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id";
$where = "del_flg = 0 AND product_count > 0";
$objQuery->setOption("ORDER BY rank DESC");
$arrRet = $objQuery->select($col, $from, $where);
$arrParentID = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id);
foreach($arrRet as $key => $array) {
foreach($arrParentID as $val) {
if($array['category_id'] == $val) {
$arrRet[$key]['display'] = 1;
* @param integer $product_id 商品ID
* @param bool $count_check 登録商品数のチェックを行う場合 true
* @return array カテゴリツリーの配列
$col .= " cat.category_id,";
$col .= " cat.category_name,";
$col .= " cat.parent_category_id,";
$col .= " cat.creator_id,";
$col .= " cat.create_date,";
$col .= " cat.update_date,";
$col .= " cat.del_flg, ";
$col .= " ttl.product_count";
$from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id";
$where = "del_flg = 0 AND product_count > 0";
$objQuery->setOption("ORDER BY rank DESC");
$arrRet = $objQuery->select($col, $from, $where);
foreach ($arrCategory_id as $pkey => $parent_category_id) {
$arrParentID = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id);
foreach($arrParentID as $pid) {
foreach($arrRet as $key => $array) {
if($array['category_id'] == $pid) {
$arrCatTree[$pkey][] = $arrRet[$key];
* @param integer $category_id カテゴリID
* @return string 親カテゴリーを連結した文字列
$arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
foreach($arrCatID as $key => $val){
$sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
$CatName = $objQuery->getOne($sql,$arrVal);
$ConbName .= $CatName . ' | ';
* 指定したカテゴリーIDの大カテゴリーを取得する.
* @param integer $category_id カテゴリID
* @return array 指定したカテゴリーIDの大カテゴリー
$arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
$arrRet['id'] = $arrCatID[0];
$sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
$arrVal = array($arrRet['id']);
$arrRet['name'] = $objQuery->getOne($sql,$arrVal);
* $products_check:true商品登録済みのものだけ取得する
* @param string $addwhere 追加する WHERE 句
* @param bool $products_check 商品の存在するカテゴリのみ取得する場合 true
* @param string $head カテゴリ名のプレフィックス文字列
* @return array カテゴリツリーの配列
function sfGetCategoryList($addwhere = "", $products_check = false, $head = CATEGORY_HEAD) {
$where.= " AND $addwhere";
$objQuery->setOption("ORDER BY rank DESC");
$col = "T1.category_id, category_name, level";
$from = "dtb_category AS T1 LEFT JOIN dtb_category_total_count AS T2 ON T1.category_id = T2.category_id";
$where .= " AND product_count > 0";
$col = "category_id, category_name, level";
$arrRet = $objQuery->select($col, $from, $where);
for($cnt = 0; $cnt < $max; $cnt++ ) {
$id = $arrRet[$cnt]['category_id'];
$name = $arrRet[$cnt]['category_name'];
$arrList[$id] = str_repeat($head, $arrRet[$cnt]['level']) . $name;
* @param bool $parent_zero 親カテゴリの Value=0 の場合 true
* @return array カテゴリツリーの配列
$col = "category_id, parent_category_id, category_name, level";
$objQuery->setOption("ORDER BY rank DESC");
$arrRet = $objQuery->select($col, "dtb_category", $where);
for($cnt = 0; $cnt < $max; $cnt++ ) {
if($arrRet[$cnt]['level'] == LEVEL_MAX) {
$arrValue[$cnt] = $arrRet[$cnt]['category_id'];
$arrValue[$cnt] = $arrRet[$cnt]['category_id'];
$parent_category_id = $arrRet[$cnt]['parent_category_id'];
for($cat_cnt = $arrRet[$cnt]['level']; $cat_cnt > 1; $cat_cnt-- ) {
foreach ($arrRet as $arrCat) {
if ($arrCat['category_id'] == $parent_category_id) {
$arrOutput[$cnt] = CATEGORY_HEAD
. $arrCat['category_name'] . $arrOutput[$cnt];
$parent_category_id = $arrCat['parent_category_id'];
$arrOutput[$cnt].= CATEGORY_HEAD . $arrRet[$cnt]['category_name'];
return array($arrValue, $arrOutput);
* @param integer $product_id プロダクトID
* @param integer $category_id カテゴリID
* @return array 選択中の商品のカテゴリIDの配列
$category_id = (int) $category_id;
$product_id = (int) $product_id;
if(SC_Utils_Ex::sfIsInt($category_id) && $this->sfIsRecord("dtb_category","category_id", $category_id)) {
} else if (SC_Utils_Ex::sfIsInt($product_id) && $this->sfIsRecord("dtb_products","product_id", $product_id, $status)) {
$where = "product_id = ?";
$category_id = $objQuery->getCol("dtb_product_categories", "category_id", "product_id = ?", array($product_id));
* @param integer $category_id カテゴリID
* @param integer $product_id プロダクトID
$sqlval = array("category_id" => $category_id,
"product_id" => $product_id);
$arrCat = $objQuery->select("product_id, category_id, rank",
"dtb_product_categories",
foreach ($arrCat as $val) {
if ($val["product_id"] == $product_id) {
$max = ($max < $val["rank"]) ? $val["rank"] : $max;
$sqlval["rank"] = $max + 1;
$objQuery->insert("dtb_product_categories", $sqlval);
* @param integer $category_id カテゴリID
* @param integer $product_id プロダクトID
$sqlval = array("category_id" => $category_id,
"product_id" => $product_id);
$arrCat = $objQuery->select("product_id, category_id, rank",
"dtb_product_categories",
foreach ($arrCat as $val) {
if ($val["product_id"] == $product_id) {
$min = ($min < $val["rank"]) ? $val["rank"] : $min;
$objQuery->insert("dtb_product_categories", $sqlval);
* @param integer $category_id カテゴリID
* @param integer $product_id プロダクトID
$sqlval = array("category_id" => $category_id,
"product_id" => $product_id);
$objQuery->delete("dtb_product_categories",
"category_id = ? AND product_id = ?", $sqlval);
* @param array $arrCategory_id 登録するカテゴリIDの配列
* @param integer $product_id プロダクトID
$arrCurrentCat = $objQuery->select("product_id, category_id, rank",
"dtb_product_categories",
foreach ($arrCurrentCat as $val) {
if (!in_array($val["category_id"], $arrCategory_id)) {
foreach ($arrCategory_id as $category_id) {
* @param SC_Query $objQuery SC_Query インスタンス
$objQuery->query("DELETE FROM dtb_category_count");
$objQuery->query("DELETE FROM dtb_category_total_count");
$sql = " INSERT INTO dtb_category_count(category_id, product_count, create_date) ";
$sql .= " SELECT T1.category_id, count(T2.category_id), now() ";
$sql .= " FROM dtb_category AS T1 LEFT JOIN dtb_product_categories AS T2";
$sql .= " ON T1.category_id = T2.category_id ";
$sql .= " LEFT JOIN dtb_products AS T3";
$sql .= " ON T2.product_id = T3.product_id";
$sql .= " WHERE T3.del_flg = 0 AND T3.status = 1 ";
$sql .= " GROUP BY T1.category_id, T2.category_id ";
$arrCat = $objQuery->getAll("SELECT * FROM dtb_category");
foreach($arrCat as $key => $val){
$arrRet = $this->sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $val['category_id']);
$line = SC_Utils_Ex::sfGetCommaList($arrRet);
$sql = " INSERT INTO dtb_category_total_count(category_id, product_count, create_date) ";
$sql .= " SELECT ?, SUM(product_count), now() FROM dtb_category_count ";
$sql .= " WHERE category_id IN (" . $line . ")";
$objQuery->query($sql, array($val['category_id']));
* @param string $table テーブル名
* @param string $pid_name 親ID名
* @param string $id_name ID名
* @param string $table テーブル名
* @param string $pid_name 親ID名
* @param string $id_name ID名
* @param integer $id ID番号
$col = $pid_name . "," . $id_name;
$arrData = $objQuery->select($col, $table);
while(count($arrRet) > 0) {
* @param array $arrData 親カテゴリの配列
* @param string $pid_name 親ID名
* @param string $id_name ID名
* @param array $arrPID 親IDの配列
for($i = 0; $i < $max; $i++ ) {
foreach($arrPID as $val) {
if($arrData[$i][$pid_name] == $val) {
$arrChildren[] = $arrData[$i][$id_name];
* @param SC_Query $objQuery SC_Query インスタンス
* @param string $table テーブル名
* @param string $pid_name 親ID名
* @param string $id_name ID名
function sfGetParents($objQuery, $table, $pid_name, $id_name, $id) {
* @param string $table テーブル名
* @param string $pid_name 親ID名
* @param string $id_name ID名
$col = $pid_name . "," . $id_name;
$arrData = $objQuery->select($col, $table);
* カテゴリから商品を検索する場合のWHERE文と値を返す.
* @param integer $category_id カテゴリID
* @return array 商品を検索する場合の配列
$arrRet = $this->sfGetChildsID("dtb_category", "parent_category_id", "category_id", $category_id);
foreach ($arrRet as $val) {
$tmp_where.= " category_id IN ( ?";
return array($tmp_where, $arrval);
* @param integer $order_temp_id 受注一時ID
* @return array 受注一時情報の配列
$where = "order_temp_id = ?";
$arrRet = $objQuery->select("*", "dtb_order_temp", $where, array($order_temp_id));
* @param string $table テーブル名
* @param string $keyname プライマリーキーのカラム名
* @param string $valname データ内容のカラム名
* @return array SELECT ボックス用リストの配列
$col = "$keyname, $valname";
$objQuery->setWhere("del_flg = 0");
$objQuery->setOrder("rank DESC");
$arrList = $objQuery->select($col, $table);
$count = count($arrList);
for($cnt = 0; $cnt < $count; $cnt++ ) {
$key = $arrList[$cnt][$keyname];
$val = $arrList[$cnt][$valname];
* @param string $table テーブル名
* @param string $colname カラム名
* @param string|integer$id テーブルのキー
* @param string $andwhere SQL の AND 条件である WHERE 句
function sfRankUp($table, $colname, $id, $andwhere = "") {
$where.= " AND $andwhere";
$rank = $objQuery->get($table, "rank", $where, array($id));
$maxrank = $objQuery->max($table, "rank", $andwhere);
$where.= " AND $andwhere";
$up_id = $objQuery->get($table, $colname, $where, array($uprank));
$sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?";
$sqlup.= " AND $andwhere";
$objQuery->exec($sqlup, array($rank + 1, $id));
$objQuery->exec($sqlup, array($rank, $up_id));
* @param string $table テーブル名
* @param string $colname カラム名
* @param string|integer$id テーブルのキー
* @param string $andwhere SQL の AND 条件である WHERE 句
function sfRankDown($table, $colname, $id, $andwhere = "") {
$where.= " AND $andwhere";
$rank = $objQuery->get($table, "rank", $where, array($id));
// ランクが1(最小値)よりも大きい場合に実行する。
$where.= " AND $andwhere";
$down_id = $objQuery->get($table, $colname, $where, array($downrank));
$sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?";
$sqlup.= " AND $andwhere";
$objQuery->exec($sqlup, array($rank - 1, $id));
$objQuery->exec($sqlup, array($rank, $down_id));
* @param string $tableName テーブル名
* @param string $keyIdColumn キーを保持するカラム名
* @param string|integer$keyId キーの値
* @param integer $pos 指定順位
* @param string $where SQL の AND 条件である WHERE 句
function sfMoveRank($tableName, $keyIdColumn, $keyId, $pos, $where = "") {
$getWhere = "$keyIdColumn = ? AND " . $where;
$getWhere = "$keyIdColumn = ?";
$rank = $objQuery->get($tableName, "rank", $getWhere, array($keyId));
$max = $objQuery->max($tableName, "rank", $where);
$position = $max - $pos + 1;
//入れ替え先の順位が入れ換え元の順位より大きい場合
if( $position > $rank ) $term = "rank - 1";
//入れ替え先の順位が入れ換え元の順位より小さい場合
if( $position < $rank ) $term = "rank + 1";
// XXX 入れ替え先の順位が入れ替え元の順位と同じ場合
if (!isset ($term)) $term = "rank";
// 指定した順位の商品から移動させる商品までのrankを1つずらす
$sql = "UPDATE $tableName SET rank = $term WHERE rank BETWEEN ? AND ?";
if( $position > $rank ) $objQuery->exec( $sql, array($rank, $position));
if( $position < $rank ) $objQuery->exec( $sql, array($position, $rank));
$sql = "UPDATE $tableName SET rank = ? WHERE $keyIdColumn = ? ";
$objQuery->exec( $sql, array( $position, $keyId ) );
* レコードごと削除する場合は、$deleteをtrueにする
* @param string $table テーブル名
* @param string $colname カラム名
* @param string|integer$id テーブルのキー
* @param string $andwhere SQL の AND 条件である WHERE 句
* @param bool $delete レコードごと削除する場合 true,
$where.= " AND $andwhere";
$rank = $objQuery->get($table, "rank", $where, array($id));
$sqlup = "UPDATE $table SET rank = 0, del_flg = 1 ";
$sqlup.= "WHERE $colname = ?";
$objQuery->exec($sqlup, array($id));
$objQuery->delete($table, "$colname = ?", array($id));
// 追加レコードのランクより上のレコードを一つずらす。
$where.= " AND $andwhere";
$sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";
$objQuery->exec($sqlup, array($rank));
* @param SC_Query $objQuery SC_Query インスタンス
* @param string $table テーブル名
* @param string $id_name ID名
* @param string $col_name カラム名
* @param array $arrId IDの配列
* @return array 特定のカラムの配列
function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId ) {
for($cnt = 0; $cnt < $len; $cnt++ ) {
$where.= " OR $id_name = ?";
$objQuery->setOrder("level");
$arrRet = $objQuery->select($col, $table, $where, $arrId);
* @param SC_Query $objQuery SC_Query インスタンス
* @param string $table テーブル名
* @param string $id_name ID名
* @param string $cat_name カテゴリ名
* @param integer $old_catid 旧カテゴリID
* @param integer $new_catid 新カテゴリID
function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) {
if ($old_catid == $new_catid) {
$rank = $objQuery->get($table, "rank", $where, array($id));
// 削除レコードのランクより上のレコードを一つ下にずらす。
$where = "rank > ? AND $cat_name = ?";
$sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";
$objQuery->exec($sqlup, array($rank, $old_catid));
$max_rank = $objQuery->max($table, "rank", "$cat_name = ?", array($new_catid)) + 1;
$sqlup = "UPDATE $table SET rank = ? WHERE $where";
$objQuery->exec($sqlup, array($max_rank, $id));
* @param integer $payment_id 支払い方法ID
$where = "del_flg = 0 AND payment_id = ?";
$arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id));
$deliv_id = $arrRet[0]['deliv_id'];
$objQuery->setOrder("time_id");
$arrRet= $objQuery->select("time_id, deliv_time", "dtb_delivtime", $where, array($deliv_id));
* @param integer $pref 都道府県ID
* @param integer $payment_id 支払い方法ID
* @return string 指定の都道府県, 支払い方法の配送料金
$pref = $arrData['deliv_pref'];
$payment_id = isset ($arrData['payment_id']) ? $arrData['payment_id'] : "";
// 支払い方法が指定されている場合は、対応した配送業者を取得する
$where = "del_flg = 0 AND payment_id = ?";
$arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id));
$deliv_id = $arrRet[0]['deliv_id'];
// 支払い方法が指定されていない場合は、先頭の配送業者を取得する
$objQuery->setOrder("rank DESC");
$objQuery->setLimitOffset(1);
$arrRet = $objQuery->select("deliv_id", "dtb_deliv", $where);
$deliv_id = $arrRet[0]['deliv_id'];
// 都道府県が指定されていない場合は、東京都の番号を指定しておく
$where = "deliv_id = ? AND pref = ?";
$arrRet= $objQuery->select("fee", "dtb_delivfee", $where, array($deliv_id, $pref));
return $arrRet[0]['fee'];
* @param array $arrData 各種情報
* @param LC_Page $objPage LC_Page インスタンス
* @param SC_CartSession $objCartSess SC_CartSession インスタンス
* @param array $arrInfo 店舗情報の配列
* @param SC_Customer $objCustomer SC_Customer インスタンス
function sfTotalConfirm($arrData, &$objPage, &$objCartSess, $arrInfo, $objCustomer = "") {
if (!isset ($arrData['deliv_pref'])) $arrData['deliv_pref'] = "";
if (!isset ($arrData['payment_id'])) $arrData['payment_id'] = "";
if (!isset ($arrData['charge'])) $arrData['charge'] = "";
if (!isset ($arrData['use_point'])) $arrData['use_point'] = "";
$total_quantity = $objCartSess->getTotalQuantity(true);
$arrData['tax'] = $objPage->tpl_total_tax;
$arrData['subtotal'] = $objPage->tpl_total_pretax;
$arrData['deliv_fee'] = 0;
if (OPTION_PRODUCT_DELIV_FEE == 1) {
$arrData['deliv_fee']+= $objCartSess->getAllProductsDelivFee();
if (OPTION_DELIV_FEE == 1) {
if(DELIV_FREE_AMOUNT > 0) {
if($total_quantity >= DELIV_FREE_AMOUNT) {
$arrData['deliv_fee'] = 0;
if($arrInfo['free_rule'] > 0) {
if($arrData['subtotal'] >= $arrInfo['free_rule']) {
$arrData['deliv_fee'] = 0;
$arrData['total'] = $objPage->tpl_total_pretax; // 商品合計
$arrData['total']+= $arrData['deliv_fee']; // 送料
$arrData['total']+= $arrData['charge']; // 手数料
$arrData['payment_total'] = $arrData['total'] - ($arrData['use_point'] * POINT_VALUE);
if (USE_POINT === false) {
$arrData['add_point'] = 0;
$arrData['add_point'] = SC_Utils::sfGetAddPoint($objPage->tpl_total_point, $arrData['use_point'], $arrInfo);
if($objCustomer->isBirthMonth()) {
$arrData['birth_point'] = BIRTH_MONTH_POINT;
$arrData['add_point'] += $arrData['birth_point'];
if($arrData['add_point'] < 0) {
$arrData['add_point'] = 0;
* @param string $table テーブル名
* @param string $col カラム名
* @param array $arrval 要素の配列
* @param array $addwhere SQL の AND 条件である WHERE 句
* @return bool レコードが存在する場合 true
function sfIsRecord($table, $col, $arrval, $addwhere = "") {
$arrCol = split("[, ]", $col);
$where.= " AND $addwhere";
foreach($arrCol as $val) {
$where.= " AND $val = ?";
$ret = $objQuery->get($table, $col, $where, $arrval);
Documentation generated on Fri, 24 Feb 2012 14:00:13 +0900 by Seasoft
|