OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / ec_main / include / container / ec_mainPurchasehistoryWidgetContainer.php
1 <?php
2 /**
3  * index.php用コンテナクラス
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
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
15  */
16 require_once($gEnvManager->getCurrentWidgetContainerPath() .    '/ec_mainBaseWidgetContainer.php');
17
18 class ec_mainPurchasehistoryWidgetContainer extends ec_mainBaseWidgetContainer
19 {
20         private $orderId;                               // 現在選択中の受注ID
21         private $lastOrderId;                   // 最新の受注ID
22         private $isExistsOrder;                 // 購入履歴があるかどうか
23                 
24         /**
25          * コンストラクタ
26          */
27         function __construct()
28         {
29                 // 親クラスを呼び出す
30                 parent::__construct();
31         }
32         /**
33          * テンプレートファイルを設定
34          *
35          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
36          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
37          *
38          * @param RequestManager $request               HTTPリクエスト処理クラス
39          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
40          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
41          */
42         function _setTemplate($request, &$param)
43         {       
44                 return 'purchasehistory.tmpl.html';
45         }
46         /**
47          * テンプレートにデータ埋め込む
48          *
49          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
50          *
51          * @param RequestManager $request               HTTPリクエスト処理クラス
52          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
53          * @param                                                               なし
54          */
55         function _assign($request, &$param)
56         {
57                 $now = date("Y/m/d H:i:s");     // 現在日時
58                 $this->currency = photo_shopCommonDef::DEFAULT_CURRENCY;                // デフォルト通貨
59                 
60                 // 画像情報を取得
61                 $this->_productImageWidth = 0;          // 商品画像幅
62                 $this->_productImageHeight = 0;         // 商品画像高さ
63                 $ret = self::$_mainDb->getProductImageInfo(photo_shopCommonDef::PRODUCT_IMAGE_SMALL, $row);
64                 if ($ret){
65                         $this->_productImageWidth = $row['is_width'];
66                         $this->_productImageHeight = $row['is_height'];
67                 }
68                 
69                 $this->orderId = $request->trimValueOf('item_order');           // 受注ID
70                 $act = $request->trimValueOf('act');
71                 
72                 // 注文履歴をすべて取得
73                 self::$_orderDb->getOrderHeaderByUser($this->_userId, array($this, 'orderListLoop'));
74
75                 $showOrderDetail = false;               // 受注情報を表示フラグクリア
76                 if ($act == 'selorder'){                // 注文項目を選択
77                         // データにアクセス可能かチェック
78                         if (self::$_orderDb->isOrderByUser($this->orderId, $this->_userId)){
79                                 $showOrderDetail = true;                // 受注情報を表示
80                         } else {
81                                 $this->setAppErrorMsg('アクセスできません');
82                         }
83                 } else {        // 初期処理
84                         if ($this->isExistsOrder){                      // 購入履歴があるかどうか
85                                 $this->orderId = $this->lastOrderId;
86                                 $showOrderDetail = true;                // 受注情報を表示
87                         }
88                 }
89                 
90                 if ($showOrderDetail){          // 受注情報にアクセス可能なとき
91                         // 受注情報を取得
92                         $ret = self::$_orderDb->getOrder($this->orderId, $row);
93                         if ($ret){
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'];       // 値引き説明
102
103                                 // 通貨情報を取得
104                                 $ret = self::$_ecObj->db->getCurrency($this->currency, $this->_langId, $row);
105                                 if ($ret){
106                                         $prePrice = $this->convertToDispString($row['cu_symbol']);
107                                         $postPrice = $this->convertToDispString($row['cu_post_symbol']);
108                                 }
109                 
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);              // 総額
118                                 
119                                 // 値引き額表示
120                                 if ($discount > 0){
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 . ')'));
125                                 }
126                                 // 項目の表示制御
127                                 if ($delivFee == 0) $this->tmpl->setAttribute('deliv_visible', 'visibility', 'hidden');
128                                 if ($charge == 0) $this->tmpl->setAttribute('charge_visible', 'visibility', 'hidden');
129                                 
130                                 // 受注商品を取得
131                                 $this->_useOrderDetail = true;          // カート内容でなく、受注内容を取得
132                                 self::$_orderDb->getOrderDetailList($this->orderId, $this->_langId, array($this, '_defaultCartLoop'));
133                         }
134                 }
135                 if ($this->isExistsOrder){                      // 購入履歴があるかどうか
136                         $this->tmpl->setAttribute('order_history', 'visibility', 'visible');
137                 } else {
138                         $this->tmpl->addVar("_widget", "message", '購入履歴がありません');
139                 }
140                 
141                 $this->tmpl->addVar("_widget", "history_url", $this->getUrl($this->gEnv->createCurrentPageUrl() . '&task=purchasehistory', true));              // 購入履歴URL
142         }
143         /**
144          * 取得したデータをテンプレートに設定する
145          *
146          * @param int $index                    行番号(0~)
147          * @param array $fetchedRow             フェッチ取得した行
148          * @param object $param                 未使用
149          * @return bool                                 true=処理続行の場合、false=処理終了の場合
150          */
151         function orderListLoop($index, $fetchedRow, $param)
152         {
153                 $selected = '';
154                 if ($fetchedRow['or_id'] == $this->orderId){            // 選択中の受注ID
155                         $selected = 'selected';
156                 }
157                 $row = array(
158                         'value'    => $this->convertToDispString($fetchedRow['or_id']),                 // ID
159                         'name'     => $this->convertToDispDateTime($fetchedRow['or_regist_dt'], 0, 10),         // 注文日時
160                         'selected' => $selected                                                                                                         // 選択中かどうか
161                 );
162                 $this->tmpl->addVars('orderlist', $row);
163                 $this->tmpl->parseTemplate('orderlist', 'a');
164                 
165                 $this->isExistsOrder = true;                    // 購入履歴があるかどうか
166                 if ($index == 0) $this->lastOrderId = $fetchedRow['or_id'];                     // 最近の受注ID
167                 return true;
168         }
169 }
170 ?>