7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2012 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: ecLib.php 5385 2012-11-16 01:27:36Z fishbone $
14 * @link http://www.magic3.org
16 require_once(dirname(__FILE__) . '/ecLibDb.php');
20 private $currencyType; // 通貨種別
21 private $taxType; // 税種別
22 private $taxRate; // 税率
23 private $decimalPlace; // 小数点位置
24 private $configArray; // Eコマース定義
25 public $db; // DB接続オブジェクト
28 const MEMBER_NO_HEAD = 'WEB'; // 自動生成する会員番号のヘッダ部
29 const MEMBER_NO_LENGTH = 5; // 自動生成する会員番号の数値桁数
34 function __construct()
37 $this->db = new ecLibDb();
40 $this->_initByDefault();
43 $this->configArray = $this->_loadConfig();
46 * オブジェクトをデフォルト通貨、言語で初期化
48 public function _initByDefault()
52 $type = $this->db->getDefaultCurrency();
53 $lang = $gEnvManager->getDefaultLanguage();
54 $this->setCurrencyType($type, $lang);
59 * @param string $type 通貨種別
60 * @param string $lang 言語
62 public function setCurrencyType($type, $lang)
64 if ($type != $this->currencyType){
66 $ret = $this->db->getCurrency($type, $lang, $row);
68 $this->decimalPlace = $row['cu_decimal_place'];
69 $this->currencyType = $type;
76 * @param string $type 税種別
77 * @param string $lang 言語
79 public function setTaxType($type, $lang)
81 if (empty($type)){ // 税タイプ未選択のとき
84 } else if ($type != $this->taxType){
86 $ret = $this->db->getTaxType($type, $lang, $row);
90 $rate = $this->db->getTaxRate($row['tt_tax_rate_id']);
91 $this->taxRate = $rate;
92 $this->taxType = $type;
99 * @param string $type 税種別
100 * @param string $lang 言語
103 public function getTaxRate($type, $lang)
107 $ret = $this->db->getTaxType($type, $lang, $row);
110 $rate = $this->db->getTaxRate($row['tt_tax_rate_id']);
117 * 税抜き価格から、現在の税種別の設定で税額を求める
118 * 現在の通貨の設定で価格の文字列を作成する
120 * @param float $srcPrice 税抜き価格
121 * @param string $dispPrice 税込み価格文字列表現
122 * @return float 税込み価格(数値)
124 public function getPriceWithTax($srcPrice, &$dispPrice)
126 $tax = $srcPrice * $this->taxRate * 0.01;
127 $total = $srcPrice + $tax;
130 $dispPrice = number_format($total, $this->decimalPlace);
136 * 税抜き価格から、現在の税種別の設定で税額を求める
137 * 現在の通貨の設定で価格の文字列を作成する
139 * @param float $srcPrice 税抜き価格
140 * @param string $dispPrice 税抜き価格文字列表現
141 * @return float 税抜き価格(数値)
143 public function getPriceWithoutTax($srcPrice, &$dispPrice)
146 $dispPrice = number_format($srcPrice, $this->decimalPlace);
152 * @return string カートID
154 public function createCartId()
157 $max = $this->db->getMaxSerialOfBasket();
158 $cartId = md5(time() . ($max + 1));
164 * @param string $currencyType 通貨種別
165 * @param string $lang 言語
166 * @param float $price 変換する価格
168 public function convertByCurrencyFormat($currencyType, $lang, $price)
173 $ret = $this->db->getCurrency($currencyType, $lang, $row);
175 $decimalPlace = $row['cu_decimal_place'];
176 $dispPrice = number_format($price, $decimalPlace);
183 * @return string デフォルトの通貨ID
185 public function getDefaultCurrency()
187 return $this->db->getDefaultCurrency();
192 * @return string 生成した会員NO
194 public function generateMemberNo()
197 $max = $this->db->getMaxMemberNo(self::MEMBER_NO_HEAD);
199 $no = self::MEMBER_NO_HEAD . sprintf("%0" . self::MEMBER_NO_LENGTH . "d", $max);
205 * @param int $userId ユーザID兼データ更新ユーザ
206 * @param bool $generateMemNo 会員NOを自動生成するかどうか
207 * @return true=成功、false=失敗
209 function makeTmpMemberToProperMember($userId, $generateMemNo=true)
212 if ($generateMemNo) $no = $this->generateMemberNo();
213 return $this->db->makeTmpMemberToProperMember($userId, $no);
218 * @param float $price 処理を行う価格
221 public function getCurrencyPrice($price)
223 return floor($price);
228 * @param string $key 定義キー
229 * @param string $default デフォルト値
232 function getConfig($key, $default = '')
234 $value = $this->configArray[$key];
235 if (!isset($value)) $value = $default;
241 * @return array 取得データ
243 function _loadConfig()
248 $ret = $this->db->getAllConfig($rows);
251 $configCount = count($rows);
252 for ($i = 0; $i < $configCount; $i++){
253 $key = $rows[$i]['cg_id'];
254 $value = $rows[$i]['cg_value'];
255 $retVal[$key] = $value;