OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / ec_main / include / iwidgets / productrate / include / container / productrateWidgetContainer.php
1 <?php
2 /**
3  * コンテナクラス
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: productrateWidgetContainer.php 5436 2012-12-07 09:55:12Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseIWidgetContainer.php');
17 require_once($gEnvManager->getCurrentIWidgetDbPath() . '/productrateDb.php');
18
19 class productrateWidgetContainer extends BaseIWidgetContainer
20 {
21         private $db;    // DB接続オブジェクト
22         private $langId;        // 言語ID
23         private $price;         // 送料
24         
25         /**
26          * コンストラクタ
27          */
28         function __construct()
29         {
30                 // 親クラスを呼び出す
31                 parent::__construct();
32                 
33                 // DBオブジェクト取得
34                 $this->db = new productrateDb();
35         }
36         /**
37          * テンプレートファイルを設定
38          *
39          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
40          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
41          *
42          * @param RequestManager $request               HTTPリクエスト処理クラス
43          * @param string         $act                   実行処理
44          * @param object         $configObj             定義情報オブジェクト
45          * @param object         $optionObj             可変パラメータオブジェクト
46          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
47          */
48         function _setTemplate($request, $act, $configObj, $optionObj)
49         {
50                 return 'index.tmpl.html';
51         }
52         /**
53          * テンプレートにデータ埋め込む
54          *
55          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
56          *
57          * @param RequestManager $request               HTTPリクエスト処理クラス
58          * @param string         $act                   実行処理
59          * @param object         $configObj             定義情報オブジェクト
60          * @param object         $optionObj             可変パラメータオブジェクト
61          * @param                                                               なし
62          */
63         function _assign($request, $act, $configObj, $optionObj)
64         {
65                 // 基本情報を取得
66                 $id             = $optionObj->id;               // ユニークなID(配送方法ID)
67                 $init   = $optionObj->init;             // データ初期化を行うかどうか
68                 $this->langId   = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
69                         
70                 // 入力値取得
71                 $time = $request->trimValueOf('iw_' . $id . '_demand_time');    // 希望日時
72                 
73                 if ($act == 'calc'){            // 計算のとき
74                         // 定義値取得
75                         $useMin = $configObj->useMin;           // 無料となる購入額を使用するかどうか
76                         $minPrice = $configObj->minPrice;       // 最小購入額
77
78                         // 可変データ取得
79                         $productTotal   = $optionObj->productTotal;                     // 商品合計額
80                         $cartId                 = $optionObj->cartId;                   // カートID
81
82                         // カートの商品を取得して、送料を求める
83                         $this->price = 0;
84                         $this->db->getCartItemList($cartId, $this->langId, array($this, 'cartLoop'));
85                         
86                         if ($useMin == 1){              // 購入最低額以上は無料かどうか
87                                 if ($productTotal >= $minPrice) $this->price = 0;
88                         }
89
90                         // 計算結果オブジェクトに設定
91                         // *** ここで返した値が配送用データとしてDBに保存される ***
92                         $resultObj->price = $this->price;
93                         $resultObj->time = $time;               // 時間帯
94                         $this->setResultObj($resultObj);
95                 } else if ($act == 'content'){          // 画面作成の場合
96                         // 定義値取得
97                         $inputDate = $configObj->inputDate;             // 希望日時の入力許可
98
99                         // 呼び出し側の設定値を使用しない場合は、画面からの入力値を使用
100                         if ($init) $time = $optionObj->time;            // 希望時間
101
102                         // 配達希望日時の入力を許可するときは、フィールドを表示し、取得値を設定
103                         if ($inputDate){
104                                 $this->tmpl->setAttribute('field_input', 'visibility', 'visible');
105                                 $this->tmpl->addVar('field_input', 'demand_time',       $time);
106                         }
107                         // ユニークIDを設定
108                         $this->tmpl->addVar('field_input', 'id',        $id);
109                 }
110         }
111         /**
112          * 取得したデータをテンプレートに設定する
113          *
114          * @param int $index                    行番号(0~)
115          * @param array $fetchedRow             フェッチ取得した行
116          * @param object $param                 未使用
117          * @return bool                                 true=処理続行の場合、false=処理終了の場合
118          */
119         function cartLoop($index, $fetchedRow, $request)
120         {
121                 $id = $fetchedRow['si_product_id'];     // 商品ID
122                 
123                 // 商品情報を取得
124                 $ret = $this->db->getProductByProductId($id, $this->langId, $row);
125                 if ($ret){
126                         $delivPrice = $row['pt_deliv_fee'];             // 配送単価
127                         $quantity = $fetchedRow['si_quantity']; // 商品数量
128                         $this->price += $delivPrice * $quantity;
129                 }
130                 return true;
131         }
132 }
133 ?>