1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
6 | * |
---|
7 | * http://www.lockon.co.jp/ |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 |
---|
12 | * of the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this program; if not, write to the Free Software |
---|
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | /** |
---|
25 | * 会員の登録配送先を管理するヘルパークラス. |
---|
26 | * |
---|
27 | * @package Helper |
---|
28 | * @author pineray |
---|
29 | * @version $Id:$ |
---|
30 | */ |
---|
31 | class SC_Helper_Address |
---|
32 | { |
---|
33 | /** |
---|
34 | * お届け先を登録 |
---|
35 | * |
---|
36 | * @param array $sqlval |
---|
37 | * @return array() |
---|
38 | */ |
---|
39 | public function registAddress($sqlval) |
---|
40 | { |
---|
41 | if (self::delivErrorCheck($sqlval)) { |
---|
42 | SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', false, "入力値が不正です。<br />正しい値を入力してください。"); |
---|
43 | SC_Response_Ex::actionExit(); |
---|
44 | } |
---|
45 | |
---|
46 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
47 | $customer_id = $sqlval['customer_id']; |
---|
48 | $other_deliv_id = $sqlval['other_deliv_id']; |
---|
49 | |
---|
50 | // 追加 |
---|
51 | if (strlen($other_deliv_id == 0)) { |
---|
52 | // 別のお届け先最大登録数に達している場合、エラー |
---|
53 | $from = 'dtb_other_deliv'; |
---|
54 | $where = 'customer_id = ?'; |
---|
55 | $arrVal = array($customer_id); |
---|
56 | $deliv_count = $objQuery->count($from, $where, $arrVal); |
---|
57 | if ($deliv_count >= DELIV_ADDR_MAX) { |
---|
58 | SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', false, '別のお届け先最大登録数に達しています。'); |
---|
59 | SC_Response_Ex::actionExit(); |
---|
60 | } |
---|
61 | |
---|
62 | // 別のお届け先を追加 |
---|
63 | $sqlval['other_deliv_id'] = $objQuery->nextVal('dtb_other_deliv_other_deliv_id'); |
---|
64 | $objQuery->insert($from, $sqlval); |
---|
65 | |
---|
66 | // 変更 |
---|
67 | } else { |
---|
68 | $from = 'dtb_other_deliv'; |
---|
69 | $where = 'customer_id = ? AND other_deliv_id = ?'; |
---|
70 | $arrVal = array($customer_id, $other_deliv_id); |
---|
71 | $deliv_count = $objQuery->count($from, $where, $arrVal); |
---|
72 | if ($deliv_count != 1) { |
---|
73 | SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', false, '一致する別のお届け先がありません。'); |
---|
74 | SC_Response_Ex::actionExit(); |
---|
75 | } |
---|
76 | |
---|
77 | // 別のお届け先を変更 |
---|
78 | $objQuery->update($from, $sqlval, $where, $arrVal); |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | * お届け先を取得 |
---|
84 | * |
---|
85 | * @param integer $other_deliv_id |
---|
86 | * @return array() |
---|
87 | */ |
---|
88 | public function getAddress($other_deliv_id) |
---|
89 | { |
---|
90 | $objCustomer = new SC_Customer_Ex(); |
---|
91 | $customer_id = $objCustomer->getValue('customer_id'); |
---|
92 | |
---|
93 | if (self::delivErrorCheck(array('customer_id' => $customer_id, 'other_deliv_id' => $other_deliv_id))) { |
---|
94 | SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', false, "入力値が不正です。<br />正しい値を入力してください。"); |
---|
95 | SC_Response_Ex::actionExit(); |
---|
96 | } |
---|
97 | |
---|
98 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
99 | |
---|
100 | $col = '*'; |
---|
101 | $from = 'dtb_other_deliv'; |
---|
102 | $where = 'customer_id = ? AND other_deliv_id = ?'; |
---|
103 | $arrVal = array($customer_id, $other_deliv_id); |
---|
104 | $address = $objQuery->getRow($col, $from, $where, $arrVal); |
---|
105 | |
---|
106 | return $address; |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | * お届け先の一覧を取得 |
---|
111 | * |
---|
112 | * @param integer $customerId |
---|
113 | * @param integer $startno |
---|
114 | * @return array |
---|
115 | */ |
---|
116 | public function getList($customer_id, $startno = '') |
---|
117 | { |
---|
118 | if (self::delivErrorCheck(array('customer_id' => $customer_id))) { |
---|
119 | SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', false, "入力値が不正です。<br />正しい値を入力してください。"); |
---|
120 | SC_Response_Ex::actionExit(); |
---|
121 | } |
---|
122 | |
---|
123 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
124 | $objQuery->setOrder('other_deliv_id DESC'); |
---|
125 | //スマートフォン用の処理 |
---|
126 | if ($startno != '') { |
---|
127 | $objQuery->setLimitOffset(SEARCH_PMAX, $startno); |
---|
128 | } |
---|
129 | |
---|
130 | $col = '*'; |
---|
131 | $from = 'dtb_other_deliv'; |
---|
132 | $where = 'customer_id = ?'; |
---|
133 | $arrVal = array($customer_id); |
---|
134 | return $objQuery->select($col, $from, $where, $arrVal); |
---|
135 | } |
---|
136 | |
---|
137 | /** |
---|
138 | * お届け先の削除 |
---|
139 | * |
---|
140 | * @param integer $delivId |
---|
141 | * @return void |
---|
142 | */ |
---|
143 | public function deleteAddress($other_deliv_id) |
---|
144 | { |
---|
145 | $objCustomer = new SC_Customer_Ex(); |
---|
146 | $customer_id = $objCustomer->getValue('customer_id'); |
---|
147 | |
---|
148 | if (self::delivErrorCheck(array('customer_id' => $customer_id, 'other_deliv_id' => $other_deliv_id))) { |
---|
149 | SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', false, "入力値が不正です。<br />正しい値を入力してください。"); |
---|
150 | SC_Response_Ex::actionExit(); |
---|
151 | } |
---|
152 | |
---|
153 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
154 | |
---|
155 | $from = 'dtb_other_deliv'; |
---|
156 | $where = 'customer_id = ? AND other_deliv_id = ?'; |
---|
157 | $arrVal = array($customer_id, $other_deliv_id); |
---|
158 | $objQuery->delete($from, $where, $arrVal); |
---|
159 | } |
---|
160 | |
---|
161 | /** |
---|
162 | * お届け先フォーム初期化 |
---|
163 | * |
---|
164 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
165 | * @return void |
---|
166 | */ |
---|
167 | public function setFormParam(&$objFormParam) |
---|
168 | { |
---|
169 | SC_Helper_Customer_Ex::sfCustomerCommonParam($objFormParam); |
---|
170 | $objFormParam->addParam('', 'other_deliv_id'); |
---|
171 | } |
---|
172 | |
---|
173 | /** |
---|
174 | * お届け先フォームエラーチェック |
---|
175 | * |
---|
176 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
177 | * @return void |
---|
178 | */ |
---|
179 | public function errorCheck(&$objFormParam) |
---|
180 | { |
---|
181 | $objErr = SC_Helper_Customer_Ex::sfCustomerCommonErrorCheck($objFormParam); |
---|
182 | |
---|
183 | return $objErr->arrErr; |
---|
184 | } |
---|
185 | |
---|
186 | /** |
---|
187 | * お届け先エラーチェック |
---|
188 | * |
---|
189 | * @param array $arrParam |
---|
190 | * @return true / false |
---|
191 | */ |
---|
192 | public function delivErrorCheck($arrParam) |
---|
193 | { |
---|
194 | $error_flg = false; |
---|
195 | |
---|
196 | if (is_null($arrParam['customer_id']) || !is_numeric($arrParam['customer_id']) || !preg_match("/^\d+$/", $arrParam['customer_id'])) { |
---|
197 | $error_flg = true; |
---|
198 | } |
---|
199 | |
---|
200 | if (strlen($arrParam['other_deliv_id']) > 0 && (!is_numeric($arrParam['other_deliv_id']) || !preg_match("/^\d+$/", $arrParam['other_deliv_id']))) { |
---|
201 | $error_flg = true; |
---|
202 | } |
---|
203 | |
---|
204 | return $error_flg; |
---|
205 | } |
---|
206 | } |
---|