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: productrateWidgetContainer.php 5436 2012-12-07 09:55:12Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseIWidgetContainer.php');
17 require_once($gEnvManager->getCurrentIWidgetDbPath() . '/productrateDb.php');
19 class productrateWidgetContainer extends BaseIWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $langId; // 言語ID
28 function __construct()
31 parent::__construct();
34 $this->db = new productrateDb();
39 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
40 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
42 * @param RequestManager $request HTTPリクエスト処理クラス
43 * @param string $act 実行処理
44 * @param object $configObj 定義情報オブジェクト
45 * @param object $optionObj 可変パラメータオブジェクト
46 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
48 function _setTemplate($request, $act, $configObj, $optionObj)
50 return 'index.tmpl.html';
55 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
57 * @param RequestManager $request HTTPリクエスト処理クラス
58 * @param string $act 実行処理
59 * @param object $configObj 定義情報オブジェクト
60 * @param object $optionObj 可変パラメータオブジェクト
63 function _assign($request, $act, $configObj, $optionObj)
66 $id = $optionObj->id; // ユニークなID(配送方法ID)
67 $init = $optionObj->init; // データ初期化を行うかどうか
68 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
71 $time = $request->trimValueOf('iw_' . $id . '_demand_time'); // 希望日時
73 if ($act == 'calc'){ // 計算のとき
75 $useMin = $configObj->useMin; // 無料となる購入額を使用するかどうか
76 $minPrice = $configObj->minPrice; // 最小購入額
79 $productTotal = $optionObj->productTotal; // 商品合計額
80 $cartId = $optionObj->cartId; // カートID
84 $this->db->getCartItemList($cartId, $this->langId, array($this, 'cartLoop'));
86 if ($useMin == 1){ // 購入最低額以上は無料かどうか
87 if ($productTotal >= $minPrice) $this->price = 0;
91 // *** ここで返した値が配送用データとしてDBに保存される ***
92 $resultObj->price = $this->price;
93 $resultObj->time = $time; // 時間帯
94 $this->setResultObj($resultObj);
95 } else if ($act == 'content'){ // 画面作成の場合
97 $inputDate = $configObj->inputDate; // 希望日時の入力許可
99 // 呼び出し側の設定値を使用しない場合は、画面からの入力値を使用
100 if ($init) $time = $optionObj->time; // 希望時間
102 // 配達希望日時の入力を許可するときは、フィールドを表示し、取得値を設定
104 $this->tmpl->setAttribute('field_input', 'visibility', 'visible');
105 $this->tmpl->addVar('field_input', 'demand_time', $time);
108 $this->tmpl->addVar('field_input', 'id', $id);
112 * 取得したデータをテンプレートに設定する
114 * @param int $index 行番号(0~)
115 * @param array $fetchedRow フェッチ取得した行
116 * @param object $param 未使用
117 * @return bool true=処理続行の場合、false=処理終了の場合
119 function cartLoop($index, $fetchedRow, $request)
121 $id = $fetchedRow['si_product_id']; // 商品ID
124 $ret = $this->db->getProductByProductId($id, $this->langId, $row);
126 $delivPrice = $row['pt_deliv_fee']; // 配送単価
127 $quantity = $fetchedRow['si_quantity']; // 商品数量
128 $this->price += $delivPrice * $quantity;