/** * 商品IDをキーにした, 商品ステータスIDの配列を取得する. * * @param array 商品ID の配列 * @return array 商品IDをキーにした商品ステータスIDの配列 */ function getProductStatus($productIds) { if (empty($productIds)) { return array(); } $objQuery =& SC_Query_Ex::getSingletonInstance(); $cols = 'product_id, product_status_id'; $from = 'dtb_product_status'; $where = 'del_flg = 0 AND product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($productIds)) . ')'; $productStatus = $objQuery->select($cols, $from, $where, $productIds); $results = array(); foreach ($productStatus as $status) { $results[$status['product_id']][] = $status['product_status_id']; } return $results; }
/** * クエリを構築する. * * 検索条件のキーに応じた WHERE 句と, クエリパラメーターを構築する. * クエリパラメーターは, SC_FormParam の入力値から取得する. * * 構築内容は, 引数の $where 及び $arrValues にそれぞれ追加される. * * @param string $key 検索条件のキー * @param string $where 構築する WHERE 句 * @param array $arrValues 構築するクエリパラメーター * @param SC_FormParam $objFormParam SC_FormParam インスタンス * @param SC_FormParam $objDb SC_Helper_DB_Ex インスタンス * @return void */ function buildQuery($key, &$where, &$arrValues, &$objFormParam, &$objDb) { $dbFactory = SC_DB_DBFactory_Ex::getInstance(); switch ($key) { // 商品ID case 'search_product_id': $where .= ' AND product_id = ?'; $arrValues[] = sprintf('%d', $objFormParam->getValue($key)); break; // 商品コード // 商品コード case 'search_product_code': $where .= ' AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code ILIKE ?)'; $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key)); break; // 商品名 // 商品名 case 'search_name': $where .= ' AND name LIKE ?'; $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key)); break; // カテゴリ // カテゴリ case 'search_category_id': list($tmp_where, $tmp_Values) = $objDb->sfGetCatWhere($objFormParam->getValue($key)); if ($tmp_where != '') { $where .= ' AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')'; $arrValues = array_merge((array) $arrValues, (array) $tmp_Values); } break; // 種別 // 種別 case 'search_status': $tmp_where = ''; foreach ($objFormParam->getValue($key) as $element) { if ($element != '') { if (SC_Utils_Ex::isBlank($tmp_where)) { $tmp_where .= ' AND (status = ?'; } else { $tmp_where .= ' OR status = ?'; } $arrValues[] = $element; } } if (!SC_Utils_Ex::isBlank($tmp_where)) { $tmp_where .= ')'; $where .= " {$tmp_where} "; } break; // 登録・更新日(開始) // 登録・更新日(開始) case 'search_startyear': $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_startyear'), $objFormParam->getValue('search_startmonth'), $objFormParam->getValue('search_startday')); $where .= ' AND update_date >= ?'; $arrValues[] = $date; break; // 登録・更新日(終了) // 登録・更新日(終了) case 'search_endyear': $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_endyear'), $objFormParam->getValue('search_endmonth'), $objFormParam->getValue('search_endday'), true); $where .= ' AND update_date <= ?'; $arrValues[] = $date; break; // 商品ステータス // 商品ステータス case 'search_product_statuses': $arrPartVal = $objFormParam->getValue($key); $count = count($arrPartVal); if ($count >= 1) { $where .= ' ' . 'AND product_id IN (' . ' SELECT product_id FROM dtb_product_status WHERE product_status_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', $count) . ')' . ')'; $arrValues = array_merge($arrValues, $arrPartVal); } break; default: break; } }
/** * カテゴリから商品を検索する場合のWHERE文と値を返す. * * @param integer $category_id カテゴリID * @return array 商品を検索する場合の配列 */ public function sfGetCatWhere($category_id) { // 子カテゴリIDの取得 $arrRet = SC_Helper_DB_Ex::sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $category_id); $where = 'category_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($arrRet)) . ')'; return array($where, $arrRet); }
/** * 指定されたキーと複数値の有効性のDB確認 * * @param string $table テーブル名 * @param string $tblkey テーブルキー名 * @param string $keyname フォームキー名 * @param array $item 入力データ配列 * @param string $delimiter 分割文字 * @return boolean true:有効なデータがある false:有効ではない */ public function lfIsDbRecordMulti($table, $tblkey, $keyname, $item, $delimiter = ',') { if (array_search($keyname, $this->arrFormKeyList) === FALSE) { return true; } if ($item[$keyname] == '') { return true; } $arrItems = explode($delimiter, $item[$keyname]); //空項目のチェック 1つでも空指定があったら不正とする。 if (array_search('', $arrItems) !== FALSE) { return false; } $count = count($arrItems); $where = $tblkey . ' IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', $count) . ')'; $objQuery =& SC_Query_Ex::getSingletonInstance(); $db_count = $objQuery->count($table, $where, $arrItems); if ($count != $db_count) { return false; } return true; }
/** * 購入金額に応じた支払方法を取得する. * * @param integer $total 購入金額 * @param integer $deliv_id 配送業者ID * @return array 購入金額に応じた支払方法の配列 */ function getPaymentsByPrice($total, $deliv_id) { $arrPaymentIds = $this->getPayments($deliv_id); if (SC_Utils_Ex::isBlank($arrPaymentIds)) { return array(); } $objQuery =& SC_Query_Ex::getSingletonInstance(); // 削除されていない支払方法を取得 $where = 'del_flg = 0 AND payment_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($arrPaymentIds)) . ')'; $objQuery->setOrder('rank DESC'); $payments = $objQuery->select('payment_id, payment_method, rule_max, upper_rule, note, payment_image, charge', 'dtb_payment', $where, $arrPaymentIds); $arrPayment = array(); foreach ($payments as $data) { // 下限と上限が設定されている if (strlen($data['rule_max']) != 0 && strlen($data['upper_rule']) != 0) { if ($data['rule_max'] <= $total && $data['upper_rule'] >= $total) { $arrPayment[] = $data; } } elseif (strlen($data['rule_max']) != 0) { if ($data['rule_max'] <= $total) { $arrPayment[] = $data; } } elseif (strlen($data['upper_rule']) != 0) { if ($data['upper_rule'] >= $total) { $arrPayment[] = $data; } } else { $arrPayment[] = $data; } } return $arrPayment; }
/** * 複数商品に追加項目値をセットする。 * * @param array $arrProducts 複数商品配列のポインタ */ function applyValuesToProducts(&$arrProducts) { $arrProductIds = array(); $arrPoints = array(); if (is_array($arrProducts)) { foreach ($arrProducts as &$arrPoint) { $product_id = $arrPoint['product_id']; $arrPoints[$product_id] =& $arrPoint; $arrProductIds[] = $product_id; } } if (!empty($arrProductIds)) { $objQuery = SC_Query_Ex::getSingletonInstance(); //まず項目情報を全商品にセットする $table = 'plg_apc_dtb_columns'; $arrColumns = $objQuery->select('*', $table); foreach ($arrColumns as $arrColumn) { foreach ($arrPoints as $product_id => &$arrPoint) { $arrPoints[$product_id][PAPC_PREFIX . $arrColumn['column_id']] = $arrColumn; } } //次に商品情報をセットする $table = <<<EOSQL plg_apc_dtb_values AS val INNER JOIN plg_apc_dtb_columns columns ON val.column_id = columns.column_id EOSQL; $where = sprintf('product_id IN (%s)', SC_Utils_Ex::repeatStrWithSeparator('?', count($arrProductIds))); $arrWhereValues = $arrProductIds; $arrValues = $objQuery->select('*', $table, $where, $arrWhereValues); foreach ($arrValues as $arrValue) { $product_id = $arrValue['product_id']; if (!empty($arrPoints[$product_id])) { $arrPoints[$product_id][PAPC_PREFIX . $arrValue['column_id']] = $arrValue; } } } }