These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* |
||
3 | * This file is part of EC-CUBE |
||
4 | * |
||
5 | * Copyright(c) 2000-2015 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 | namespace Eccube\Controller\Admin\Order; |
||
26 | |||
27 | use Eccube\Application; |
||
28 | use Eccube\Common\Constant; |
||
29 | use Eccube\Controller\AbstractController; |
||
30 | use Eccube\Entity\Master\CsvType; |
||
31 | use Eccube\Event\EccubeEvents; |
||
32 | use Eccube\Event\EventArgs; |
||
33 | use Symfony\Component\HttpFoundation\Request; |
||
34 | use Symfony\Component\HttpFoundation\StreamedResponse; |
||
35 | |||
36 | class OrderController extends AbstractController |
||
37 | { |
||
38 | |||
39 | 9 | public function index(Application $app, Request $request, $page_no = null) |
|
40 | { |
||
41 | |||
42 | 9 | $session = $request->getSession(); |
|
43 | |||
44 | 9 | $builder = $app['form.factory'] |
|
45 | 9 | ->createBuilder('admin_search_order'); |
|
46 | |||
47 | 9 | $event = new EventArgs( |
|
48 | array( |
||
49 | 9 | 'builder' => $builder, |
|
50 | ), |
||
51 | $request |
||
52 | ); |
||
53 | 9 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_INITIALIZE, $event); |
|
54 | |||
55 | 9 | $searchForm = $builder->getForm(); |
|
56 | |||
57 | 9 | $pagination = array(); |
|
58 | |||
59 | 9 | $disps = $app['eccube.repository.master.disp']->findAll(); |
|
60 | 9 | $pageMaxis = $app['eccube.repository.master.page_max']->findAll(); |
|
61 | 9 | $page_count = $app['config']['default_page_count']; |
|
62 | 9 | $page_status = null; |
|
63 | 9 | $active = false; |
|
64 | |||
65 | 9 | if ('POST' === $request->getMethod()) { |
|
66 | |||
67 | 7 | $searchForm->handleRequest($request); |
|
68 | |||
69 | 7 | View Code Duplication | if ($searchForm->isValid()) { |
0 ignored issues
–
show
|
|||
70 | 7 | $searchData = $searchForm->getData(); |
|
71 | |||
72 | // paginator |
||
73 | 7 | $qb = $app['eccube.repository.order']->getQueryBuilderBySearchDataForAdmin($searchData); |
|
74 | |||
75 | 7 | $event = new EventArgs( |
|
76 | array( |
||
77 | 7 | 'form' => $searchForm, |
|
78 | 7 | 'qb' => $qb, |
|
79 | ), |
||
80 | $request |
||
81 | ); |
||
82 | 7 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_SEARCH, $event); |
|
83 | |||
84 | 7 | $page_no = 1; |
|
85 | 7 | $pagination = $app['paginator']()->paginate( |
|
86 | $qb, |
||
87 | $page_no, |
||
88 | $page_count |
||
89 | ); |
||
90 | |||
91 | // sessionのデータ保持 |
||
92 | 7 | $session->set('eccube.admin.order.search', $searchData); |
|
93 | 7 | $session->set('eccube.admin.order.search.page_no', $page_no); |
|
94 | } |
||
95 | } else { |
||
96 | 4 | if (is_null($page_no) && $request->get('resume') != Constant::ENABLED) { |
|
97 | // sessionを削除 |
||
98 | 2 | $session->remove('eccube.admin.order.search'); |
|
99 | 2 | $session->remove('eccube.admin.order.search.page_no'); |
|
100 | } else { |
||
101 | // pagingなどの処理 |
||
102 | 2 | $searchData = $session->get('eccube.admin.order.search'); |
|
103 | 2 | if (is_null($page_no)) { |
|
104 | $page_no = intval($session->get('eccube.admin.order.search.page_no')); |
||
105 | } else { |
||
106 | 2 | $session->set('eccube.admin.order.search.page_no', $page_no); |
|
107 | } |
||
108 | |||
109 | 2 | if (!is_null($searchData)) { |
|
110 | |||
111 | // 公開ステータス |
||
112 | 2 | $status = $request->get('status'); |
|
113 | 2 | if (!empty($status)) { |
|
114 | if ($status != $app['config']['admin_product_stock_status']) { |
||
115 | $searchData['status']->clear(); |
||
116 | $searchData['status']->add($status); |
||
117 | } else { |
||
118 | $searchData['stock_status'] = $app['config']['disabled']; |
||
119 | } |
||
120 | $page_status = $status; |
||
121 | } |
||
122 | // 表示件数 |
||
123 | 2 | $pcount = $request->get('page_count'); |
|
124 | |||
125 | 2 | $page_count = empty($pcount) ? $page_count : $pcount; |
|
126 | |||
127 | 2 | $qb = $app['eccube.repository.order']->getQueryBuilderBySearchDataForAdmin($searchData); |
|
128 | |||
129 | 2 | $event = new EventArgs( |
|
130 | array( |
||
131 | 2 | 'form' => $searchForm, |
|
132 | 2 | 'qb' => $qb, |
|
133 | ), |
||
134 | $request |
||
135 | ); |
||
136 | 2 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_SEARCH, $event); |
|
137 | |||
138 | 2 | $pagination = $app['paginator']()->paginate( |
|
139 | $qb, |
||
140 | $page_no, |
||
141 | $page_count |
||
142 | ); |
||
143 | |||
144 | // セッションから検索条件を復元 |
||
145 | 2 | if (!empty($searchData['status'])) { |
|
146 | 2 | $searchData['status'] = $app['eccube.repository.master.order_status']->find($searchData['status']); |
|
147 | } |
||
148 | 2 | if (count($searchData['multi_status']) > 0) { |
|
149 | $statusIds = array(); |
||
150 | foreach ($searchData['multi_status'] as $Status) { |
||
151 | $statusIds[] = $Status->getId(); |
||
152 | } |
||
153 | $searchData['multi_status'] = $app['eccube.repository.master.order_status']->findBy(array('id' => $statusIds)); |
||
154 | } |
||
155 | 2 | View Code Duplication | if (count($searchData['sex']) > 0) { |
156 | 2 | $sex_ids = array(); |
|
157 | 2 | foreach ($searchData['sex'] as $Sex) { |
|
158 | 2 | $sex_ids[] = $Sex->getId(); |
|
159 | } |
||
160 | 2 | $searchData['sex'] = $app['eccube.repository.master.sex']->findBy(array('id' => $sex_ids)); |
|
161 | } |
||
162 | 2 | View Code Duplication | if (count($searchData['payment']) > 0) { |
163 | 2 | $payment_ids = array(); |
|
164 | 2 | foreach ($searchData['payment'] as $Payment) { |
|
165 | 2 | $payment_ids[] = $Payment->getId(); |
|
166 | } |
||
167 | 2 | $searchData['payment'] = $app['eccube.repository.payment']->findBy(array('id' => $payment_ids)); |
|
168 | } |
||
169 | 2 | $searchForm->setData($searchData); |
|
170 | } |
||
171 | } |
||
172 | } |
||
173 | |||
174 | 9 | return $app->render('Order/index.twig', array( |
|
175 | 9 | 'searchForm' => $searchForm->createView(), |
|
176 | 9 | 'pagination' => $pagination, |
|
177 | 9 | 'disps' => $disps, |
|
178 | 9 | 'pageMaxis' => $pageMaxis, |
|
179 | 9 | 'page_no' => $page_no, |
|
180 | 9 | 'page_status' => $page_status, |
|
181 | 9 | 'page_count' => $page_count, |
|
182 | 9 | 'active' => $active, |
|
183 | )); |
||
184 | |||
185 | } |
||
186 | |||
187 | 2 | public function delete(Application $app, Request $request, $id) |
|
188 | { |
||
189 | 2 | $this->isTokenValid($app); |
|
190 | 2 | $session = $request->getSession(); |
|
191 | 2 | $page_no = intval($session->get('eccube.admin.order.search.page_no')); |
|
192 | 2 | $page_no = $page_no ? $page_no : Constant::ENABLED; |
|
193 | |||
194 | 2 | $Order = $app['orm.em']->getRepository('Eccube\Entity\Order') |
|
195 | 2 | ->find($id); |
|
196 | |||
197 | 2 | if (!$Order) { |
|
198 | $app->deleteMessage(); |
||
199 | return $app->redirect($app->url('admin_order_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED); |
||
200 | } |
||
201 | |||
202 | 2 | log_info('受注削除開始', array($Order->getId())); |
|
203 | |||
204 | 2 | $Order->setDelFlg(Constant::ENABLED); |
|
205 | |||
206 | 2 | $app['orm.em']->persist($Order); |
|
207 | 2 | $app['orm.em']->flush(); |
|
208 | |||
209 | 2 | $Customer = $Order->getCustomer(); |
|
210 | 2 | if ($Customer) { |
|
211 | // 会員の場合、購入回数、購入金額などを更新 |
||
212 | 2 | $app['eccube.repository.customer']->updateBuyData($app, $Customer, $Order->getOrderStatus()->getId()); |
|
213 | } |
||
214 | |||
215 | 2 | $event = new EventArgs( |
|
216 | array( |
||
217 | 2 | 'Order' => $Order, |
|
218 | 2 | 'Customer' => $Customer, |
|
219 | ), |
||
220 | $request |
||
221 | ); |
||
222 | 2 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_DELETE_COMPLETE, $event); |
|
223 | |||
224 | 2 | $app->addSuccess('admin.order.delete.complete', 'admin'); |
|
225 | |||
226 | 2 | log_info('受注削除完了', array($Order->getId())); |
|
227 | |||
228 | 2 | return $app->redirect($app->url('admin_order_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED); |
|
229 | } |
||
230 | |||
231 | |||
232 | /** |
||
233 | * 受注CSVの出力. |
||
234 | * |
||
235 | * @param Application $app |
||
236 | * @param Request $request |
||
237 | * @return StreamedResponse |
||
238 | */ |
||
239 | public function exportOrder(Application $app, Request $request) |
||
240 | { |
||
241 | |||
242 | // タイムアウトを無効にする. |
||
243 | set_time_limit(0); |
||
244 | |||
245 | // sql loggerを無効にする. |
||
246 | $em = $app['orm.em']; |
||
247 | $em->getConfiguration()->setSQLLogger(null); |
||
248 | |||
249 | $response = new StreamedResponse(); |
||
250 | $response->setCallback(function () use ($app, $request) { |
||
251 | |||
252 | // CSV種別を元に初期化. |
||
253 | $app['eccube.service.csv.export']->initCsvType(CsvType::CSV_TYPE_ORDER); |
||
254 | |||
255 | // ヘッダ行の出力. |
||
256 | $app['eccube.service.csv.export']->exportHeader(); |
||
257 | |||
258 | // 受注データ検索用のクエリビルダを取得. |
||
259 | $qb = $app['eccube.service.csv.export'] |
||
260 | ->getOrderQueryBuilder($request); |
||
261 | |||
262 | // データ行の出力. |
||
263 | $app['eccube.service.csv.export']->setExportQueryBuilder($qb); |
||
264 | View Code Duplication | $app['eccube.service.csv.export']->exportData(function ($entity, $csvService) use ($app, $request) { |
|
265 | |||
266 | $Csvs = $csvService->getCsvs(); |
||
267 | |||
268 | $Order = $entity; |
||
269 | $OrderDetails = $Order->getOrderDetails(); |
||
270 | |||
271 | foreach ($OrderDetails as $OrderDetail) { |
||
272 | $ExportCsvRow = new \Eccube\Entity\ExportCsvRow(); |
||
273 | |||
274 | // CSV出力項目と合致するデータを取得. |
||
275 | foreach ($Csvs as $Csv) { |
||
276 | // 受注データを検索. |
||
277 | $ExportCsvRow->setData($csvService->getData($Csv, $Order)); |
||
278 | if ($ExportCsvRow->isDataNull()) { |
||
279 | // 受注データにない場合は, 受注明細を検索. |
||
280 | $ExportCsvRow->setData($csvService->getData($Csv, $OrderDetail)); |
||
281 | } |
||
282 | |||
283 | $event = new EventArgs( |
||
284 | array( |
||
285 | 'csvService' => $csvService, |
||
286 | 'Csv' => $Csv, |
||
287 | 'OrderDetail' => $OrderDetail, |
||
288 | 'ExportCsvRow' => $ExportCsvRow, |
||
289 | ), |
||
290 | $request |
||
291 | ); |
||
292 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_CSV_EXPORT_ORDER, $event); |
||
293 | |||
294 | $ExportCsvRow->pushData(); |
||
295 | } |
||
296 | |||
297 | //$row[] = number_format(memory_get_usage(true)); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
65% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them.
Loading history...
|
|||
298 | // 出力. |
||
299 | $csvService->fputcsv($ExportCsvRow->getRow()); |
||
300 | } |
||
301 | }); |
||
302 | }); |
||
303 | |||
304 | $now = new \DateTime(); |
||
305 | $filename = 'order_' . $now->format('YmdHis') . '.csv'; |
||
306 | $response->headers->set('Content-Type', 'application/octet-stream'); |
||
307 | $response->headers->set('Content-Disposition', 'attachment; filename=' . $filename); |
||
0 ignored issues
–
show
|
|||
308 | $response->send(); |
||
309 | |||
310 | log_info('受注CSV出力ファイル名', array($filename)); |
||
311 | |||
312 | return $response; |
||
313 | } |
||
314 | |||
315 | /** |
||
316 | * 配送CSVの出力. |
||
317 | * |
||
318 | * @param Application $app |
||
319 | * @param Request $request |
||
0 ignored issues
–
show
|
|||
320 | * @return StreamedResponse |
||
321 | */ |
||
322 | public function exportShipping(Application $app, Request $request) |
||
323 | { |
||
324 | // タイムアウトを無効にする. |
||
325 | set_time_limit(0); |
||
326 | |||
327 | // sql loggerを無効にする. |
||
328 | $em = $app['orm.em']; |
||
329 | $em->getConfiguration()->setSQLLogger(null); |
||
330 | |||
331 | $response = new StreamedResponse(); |
||
332 | $response->setCallback(function () use ($app, $request) { |
||
333 | |||
334 | // CSV種別を元に初期化. |
||
335 | $app['eccube.service.csv.export']->initCsvType(CsvType::CSV_TYPE_SHIPPING); |
||
336 | |||
337 | // ヘッダ行の出力. |
||
338 | $app['eccube.service.csv.export']->exportHeader(); |
||
339 | |||
340 | // 受注データ検索用のクエリビルダを取得. |
||
341 | $qb = $app['eccube.service.csv.export'] |
||
342 | ->getOrderQueryBuilder($request); |
||
343 | |||
344 | // データ行の出力. |
||
345 | $app['eccube.service.csv.export']->setExportQueryBuilder($qb); |
||
346 | $app['eccube.service.csv.export']->exportData(function ($entity, $csvService) use ($app, $request) { |
||
347 | |||
348 | $Csvs = $csvService->getCsvs(); |
||
349 | |||
350 | /** @var $Order \Eccube\Entity\Order */ |
||
351 | $Order = $entity; |
||
352 | /** @var $Shippings \Eccube\Entity\Shipping[] */ |
||
353 | $Shippings = $Order->getShippings(); |
||
354 | |||
355 | foreach ($Shippings as $Shipping) { |
||
356 | /** @var $ShipmentItems \Eccube\Entity\ShipmentItem */ |
||
357 | $ShipmentItems = $Shipping->getShipmentItems(); |
||
358 | foreach ($ShipmentItems as $ShipmentItem) { |
||
359 | $ExportCsvRow = new \Eccube\Entity\ExportCsvRow(); |
||
360 | |||
361 | // CSV出力項目と合致するデータを取得. |
||
362 | foreach ($Csvs as $Csv) { |
||
363 | // 受注データを検索. |
||
364 | $ExportCsvRow->setData($csvService->getData($Csv, $Order)); |
||
365 | if ($ExportCsvRow->isDataNull()) { |
||
366 | // 配送情報を検索. |
||
367 | $ExportCsvRow->setData($csvService->getData($Csv, $Shipping)); |
||
368 | } |
||
369 | if ($ExportCsvRow->isDataNull()) { |
||
370 | // 配送商品を検索. |
||
371 | $ExportCsvRow->setData($csvService->getData($Csv, $ShipmentItem)); |
||
372 | } |
||
373 | |||
374 | $event = new EventArgs( |
||
375 | array( |
||
376 | 'csvService' => $csvService, |
||
377 | 'Csv' => $Csv, |
||
378 | 'ShipmentItem' => $ShipmentItem, |
||
379 | 'ExportCsvRow' => $ExportCsvRow, |
||
380 | ), |
||
381 | $request |
||
382 | ); |
||
383 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_CSV_EXPORT_SHIPPING, $event); |
||
384 | |||
385 | $ExportCsvRow->pushData(); |
||
386 | } |
||
387 | //$row[] = number_format(memory_get_usage(true)); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
65% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them.
Loading history...
|
|||
388 | // 出力. |
||
389 | $csvService->fputcsv($ExportCsvRow->getRow()); |
||
390 | } |
||
391 | } |
||
392 | }); |
||
393 | }); |
||
394 | |||
395 | $now = new \DateTime(); |
||
396 | $filename = 'shipping_' . $now->format('YmdHis') . '.csv'; |
||
397 | $response->headers->set('Content-Type', 'application/octet-stream'); |
||
398 | $response->headers->set('Content-Disposition', 'attachment; filename=' . $filename); |
||
0 ignored issues
–
show
|
|||
399 | $response->send(); |
||
400 | |||
401 | log_info('配送CSV出力ファイル名', array($filename)); |
||
402 | |||
403 | return $response; |
||
404 | } |
||
405 | } |
||
406 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.