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: ec_mainPurchasehistoryWidgetContainer.php 5440 2012-12-08 09:37:39Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/ec_mainBaseWidgetContainer.php');
18 class ec_mainPurchasehistoryWidgetContainer extends ec_mainBaseWidgetContainer
20 private $orderId; // 現在選択中の受注ID
21 private $lastOrderId; // 最新の受注ID
22 private $isExistsOrder; // 購入履歴があるかどうか
27 function __construct()
30 parent::__construct();
35 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
36 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
38 * @param RequestManager $request HTTPリクエスト処理クラス
39 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
40 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
42 function _setTemplate($request, &$param)
44 return 'purchasehistory.tmpl.html';
49 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
51 * @param RequestManager $request HTTPリクエスト処理クラス
52 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
55 function _assign($request, &$param)
57 $now = date("Y/m/d H:i:s"); // 現在日時
58 $this->currency = photo_shopCommonDef::DEFAULT_CURRENCY; // デフォルト通貨
61 $this->_productImageWidth = 0; // 商品画像幅
62 $this->_productImageHeight = 0; // 商品画像高さ
63 $ret = self::$_mainDb->getProductImageInfo(photo_shopCommonDef::PRODUCT_IMAGE_SMALL, $row);
65 $this->_productImageWidth = $row['is_width'];
66 $this->_productImageHeight = $row['is_height'];
69 $this->orderId = $request->trimValueOf('item_order'); // 受注ID
70 $act = $request->trimValueOf('act');
73 self::$_orderDb->getOrderHeaderByUser($this->_userId, array($this, 'orderListLoop'));
75 $showOrderDetail = false; // 受注情報を表示フラグクリア
76 if ($act == 'selorder'){ // 注文項目を選択
78 if (self::$_orderDb->isOrderByUser($this->orderId, $this->_userId)){
79 $showOrderDetail = true; // 受注情報を表示
81 $this->setAppErrorMsg('アクセスできません');
84 if ($this->isExistsOrder){ // 購入履歴があるかどうか
85 $this->orderId = $this->lastOrderId;
86 $showOrderDetail = true; // 受注情報を表示
90 if ($showOrderDetail){ // 受注情報にアクセス可能なとき
92 $ret = self::$_orderDb->getOrder($this->orderId, $row);
94 $this->currency = $row['or_currency_id']; // 通貨
95 $subtotal = $row['or_subtotal']; // 商品総額
96 $discount = $row['or_discount']; // 値引き額
97 $delivFee = $row['or_deliv_fee']; // 配送料
98 $charge = $row['or_charge']; // 手数料
99 $total = $row['or_total']; // 総額
100 $orderDt = $row['or_regist_dt']; // 注文日時
101 $discountDesc = $row['or_discount_desc']; // 値引き説明
104 $ret = self::$_ecObj->db->getCurrency($this->currency, $this->_langId, $row);
106 $prePrice = $this->convertToDispString($row['cu_symbol']);
107 $postPrice = $this->convertToDispString($row['cu_post_symbol']);
110 $subtotalStr = self::$_ecObj->convertByCurrencyFormat($this->currency, $this->_langId, $subtotal);
111 $this->tmpl->addVar("order_history", "subtotal", $prePrice . $subtotalStr . $postPrice); // 商品総額
112 $delivFeeStr = self::$_ecObj->convertByCurrencyFormat($this->currency, $this->_langId, $delivFee);
113 $this->tmpl->addVar("deliv_visible", "delivery_fee", $prePrice . $delivFeeStr . $postPrice); // 送料
114 $chargeStr = self::$_ecObj->convertByCurrencyFormat($this->currency, $this->_langId, $charge);
115 $this->tmpl->addVar("charge_visible", "charge", $prePrice . $chargeStr . $postPrice); // 手数料
116 $totalStr = self::$_ecObj->convertByCurrencyFormat($this->currency, $this->_langId, $total);
117 $this->tmpl->addVar("order_history", "total", $prePrice . $totalStr . $postPrice); // 総額
121 $this->tmpl->setAttribute('show_discount', 'visibility', 'visible');
122 $priceStr = '-' . self::$_ecObj->convertByCurrencyFormat($this->currency, $this->_langId, $discount);
123 $this->tmpl->addVar("show_discount", "discount", $prePrice . $priceStr . $postPrice);
124 if (!empty($discountDesc)) $this->tmpl->addVar("show_discount", "discount_desc", $this->convertToDispString('(' . $discountDesc . ')'));
127 if ($delivFee == 0) $this->tmpl->setAttribute('deliv_visible', 'visibility', 'hidden');
128 if ($charge == 0) $this->tmpl->setAttribute('charge_visible', 'visibility', 'hidden');
131 $this->_useOrderDetail = true; // カート内容でなく、受注内容を取得
132 self::$_orderDb->getOrderDetailList($this->orderId, $this->_langId, array($this, '_defaultCartLoop'));
135 if ($this->isExistsOrder){ // 購入履歴があるかどうか
136 $this->tmpl->setAttribute('order_history', 'visibility', 'visible');
138 $this->tmpl->addVar("_widget", "message", '購入履歴がありません');
141 $this->tmpl->addVar("_widget", "history_url", $this->getUrl($this->gEnv->createCurrentPageUrl() . '&task=purchasehistory', true)); // 購入履歴URL
144 * 取得したデータをテンプレートに設定する
146 * @param int $index 行番号(0~)
147 * @param array $fetchedRow フェッチ取得した行
148 * @param object $param 未使用
149 * @return bool true=処理続行の場合、false=処理終了の場合
151 function orderListLoop($index, $fetchedRow, $param)
154 if ($fetchedRow['or_id'] == $this->orderId){ // 選択中の受注ID
155 $selected = 'selected';
158 'value' => $this->convertToDispString($fetchedRow['or_id']), // ID
159 'name' => $this->convertToDispDateTime($fetchedRow['or_regist_dt'], 0, 10), // 注文日時
160 'selected' => $selected // 選択中かどうか
162 $this->tmpl->addVars('orderlist', $row);
163 $this->tmpl->parseTemplate('orderlist', 'a');
165 $this->isExistsOrder = true; // 購入履歴があるかどうか
166 if ($index == 0) $this->lastOrderId = $fetchedRow['or_id']; // 最近の受注ID