1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.lockon.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\Controller\Admin\Order; |
15
|
|
|
|
16
|
|
|
use Eccube\Common\Constant; |
17
|
|
|
use Eccube\Controller\AbstractController; |
18
|
|
|
use Eccube\Entity\Csv; |
19
|
|
|
use Eccube\Entity\ExportCsvRow; |
20
|
|
|
use Eccube\Entity\Master\CsvType; |
21
|
|
|
use Eccube\Entity\OrderItem; |
22
|
|
|
use Eccube\Event\EccubeEvents; |
23
|
|
|
use Eccube\Event\EventArgs; |
24
|
|
|
use Eccube\Form\Type\Admin\SearchOrderType; |
25
|
|
|
use Eccube\Repository\CustomerRepository; |
26
|
|
|
use Eccube\Repository\Master\OrderStatusRepository; |
27
|
|
|
use Eccube\Repository\Master\PageMaxRepository; |
28
|
|
|
use Eccube\Repository\Master\ProductStatusRepository; |
29
|
|
|
use Eccube\Repository\Master\SexRepository; |
30
|
|
|
use Eccube\Repository\OrderRepository; |
31
|
|
|
use Eccube\Repository\PaymentRepository; |
32
|
|
|
use Eccube\Service\CsvExportService; |
33
|
|
|
use Eccube\Util\FormUtil; |
34
|
|
|
use Knp\Component\Pager\PaginatorInterface; |
35
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
36
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
37
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
38
|
|
|
use Symfony\Component\HttpFoundation\Response; |
39
|
|
|
use Symfony\Component\HttpFoundation\Request; |
40
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
41
|
|
|
use Eccube\Entity\Master\OrderStatus; |
42
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
43
|
|
|
use Eccube\Entity\Order; |
44
|
|
|
use Eccube\Entity\Shipping; |
45
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
46
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseFlow; |
47
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseException; |
48
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
49
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
50
|
|
|
|
51
|
|
|
class OrderController extends AbstractController |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
/** |
54
|
|
|
* @var PurchaseFlow |
55
|
|
|
*/ |
56
|
|
|
protected $purchaseFlow; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var CsvExportService |
60
|
|
|
*/ |
61
|
|
|
protected $csvExportService; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var CustomerRepository |
65
|
|
|
*/ |
66
|
|
|
protected $customerRepository; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var PaymentRepository |
70
|
|
|
*/ |
71
|
|
|
protected $paymentRepository; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @var SexRepository |
75
|
|
|
*/ |
76
|
|
|
protected $sexRepository; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var OrderStatusRepository |
80
|
|
|
*/ |
81
|
|
|
protected $orderStatusRepository; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @var PageMaxRepository |
85
|
|
|
*/ |
86
|
|
|
protected $pageMaxRepository; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @var ProductStatusRepository |
90
|
|
|
*/ |
91
|
|
|
protected $productStatusRepository; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @var OrderRepository |
95
|
|
|
*/ |
96
|
|
|
protected $orderRepository; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @var ValidatorInterface |
100
|
|
|
*/ |
101
|
|
|
protected $validator; |
102
|
|
|
|
103
|
|
|
/** |
|
|
|
|
104
|
|
|
* OrderController constructor. |
105
|
|
|
* |
106
|
|
|
* @param PurchaseFlow $orderPurchaseFlow |
|
|
|
|
107
|
|
|
* @param CsvExportService $csvExportService |
|
|
|
|
108
|
|
|
* @param CustomerRepository $customerRepository |
|
|
|
|
109
|
|
|
* @param PaymentRepository $paymentRepository |
|
|
|
|
110
|
|
|
* @param SexRepository $sexRepository |
|
|
|
|
111
|
|
|
* @param OrderStatusRepository $orderStatusRepository |
|
|
|
|
112
|
|
|
* @param PageMaxRepository $pageMaxRepository |
|
|
|
|
113
|
|
|
* @param ProductStatusRepository $productStatusRepository |
114
|
|
|
* @param OrderRepository $orderRepository |
|
|
|
|
115
|
|
|
*/ |
116
|
14 |
|
public function __construct( |
117
|
|
|
PurchaseFlow $orderPurchaseFlow, |
118
|
|
|
CsvExportService $csvExportService, |
119
|
|
|
CustomerRepository $customerRepository, |
120
|
|
|
PaymentRepository $paymentRepository, |
121
|
|
|
SexRepository $sexRepository, |
122
|
|
|
OrderStatusRepository $orderStatusRepository, |
123
|
|
|
PageMaxRepository $pageMaxRepository, |
124
|
|
|
ProductStatusRepository $productStatusRepository, |
125
|
|
|
OrderRepository $orderRepository, |
126
|
|
|
ValidatorInterface $validator |
127
|
|
|
) { |
128
|
14 |
|
$this->purchaseFlow = $orderPurchaseFlow; |
129
|
14 |
|
$this->csvExportService = $csvExportService; |
130
|
14 |
|
$this->customerRepository = $customerRepository; |
131
|
14 |
|
$this->paymentRepository = $paymentRepository; |
132
|
14 |
|
$this->sexRepository = $sexRepository; |
133
|
14 |
|
$this->orderStatusRepository = $orderStatusRepository; |
134
|
14 |
|
$this->pageMaxRepository = $pageMaxRepository; |
135
|
14 |
|
$this->productStatusRepository = $productStatusRepository; |
136
|
14 |
|
$this->orderRepository = $orderRepository; |
137
|
14 |
|
$this->validator = $validator; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
|
|
|
|
141
|
|
|
* 受注一覧画面. |
142
|
|
|
* |
143
|
|
|
* - 検索条件, ページ番号, 表示件数はセッションに保持されます. |
144
|
|
|
* - クエリパラメータでresume=1が指定された場合、検索条件, ページ番号, 表示件数をセッションから復旧します. |
145
|
|
|
* - 各データの, セッションに保持するアクションは以下の通りです. |
146
|
|
|
* - 検索ボタン押下時 |
147
|
|
|
* - 検索条件をセッションに保存します |
148
|
|
|
* - ページ番号は1で初期化し、セッションに保存します。 |
149
|
|
|
* - 表示件数変更時 |
150
|
|
|
* - クエリパラメータpage_countをセッションに保存します。 |
151
|
|
|
* - ただし, mtb_page_maxと一致しない場合, eccube_default_page_countが保存されます. |
152
|
|
|
* - ページング時 |
153
|
|
|
* - URLパラメータpage_noをセッションに保存します. |
154
|
|
|
* - 初期表示 |
155
|
|
|
* - 検索条件は空配列, ページ番号は1で初期化し, セッションに保存します. |
156
|
|
|
* |
157
|
|
|
* @Route("/%eccube_admin_route%/order", name="admin_order") |
158
|
|
|
* @Route("/%eccube_admin_route%/order/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_order_page") |
159
|
|
|
* @Template("@admin/Order/index.twig") |
160
|
|
|
*/ |
|
|
|
|
161
|
8 |
|
public function index(Request $request, $page_no = null, PaginatorInterface $paginator) |
|
|
|
|
162
|
|
|
{ |
163
|
8 |
|
$builder = $this->formFactory |
164
|
8 |
|
->createBuilder(SearchOrderType::class); |
165
|
|
|
|
166
|
8 |
|
$event = new EventArgs( |
167
|
|
|
[ |
168
|
8 |
|
'builder' => $builder, |
169
|
|
|
], |
170
|
8 |
|
$request |
171
|
|
|
); |
172
|
8 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_INITIALIZE, $event); |
173
|
|
|
|
174
|
8 |
|
$searchForm = $builder->getForm(); |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* ページの表示件数は, 以下の順に優先される. |
178
|
|
|
* - リクエストパラメータ |
179
|
|
|
* - セッション |
180
|
|
|
* - デフォルト値 |
181
|
|
|
* また, セッションに保存する際は mtb_page_maxと照合し, 一致した場合のみ保存する. |
182
|
|
|
**/ |
183
|
8 |
|
$page_count = $this->session->get('eccube.admin.order.search.page_count', |
184
|
8 |
|
$this->eccubeConfig->get('eccube_default_page_count')); |
185
|
|
|
|
186
|
8 |
|
$page_count_param = (int) $request->get('page_count'); |
187
|
8 |
|
$pageMaxis = $this->pageMaxRepository->findAll(); |
188
|
|
|
|
189
|
8 |
|
if ($page_count_param) { |
190
|
1 |
|
foreach ($pageMaxis as $pageMax) { |
191
|
1 |
|
if ($page_count_param == $pageMax->getName()) { |
192
|
|
|
$page_count = $pageMax->getName(); |
193
|
|
|
$this->session->set('eccube.admin.order.search.page_count', $page_count); |
194
|
1 |
|
break; |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
199
|
8 |
|
if ('POST' === $request->getMethod()) { |
200
|
6 |
|
$searchForm->handleRequest($request); |
201
|
|
|
|
202
|
6 |
|
if ($searchForm->isValid()) { |
203
|
|
|
/** |
204
|
|
|
* 検索が実行された場合は, セッションに検索条件を保存する. |
205
|
|
|
* ページ番号は最初のページ番号に初期化する. |
206
|
|
|
*/ |
207
|
5 |
|
$page_no = 1; |
208
|
5 |
|
$searchData = $searchForm->getData(); |
209
|
|
|
|
210
|
|
|
// 検索条件, ページ番号をセッションに保持. |
211
|
5 |
|
$this->session->set('eccube.admin.order.search', FormUtil::getViewData($searchForm)); |
212
|
5 |
|
$this->session->set('eccube.admin.order.search.page_no', $page_no); |
213
|
|
|
} else { |
214
|
|
|
// 検索エラーの際は, 詳細検索枠を開いてエラー表示する. |
215
|
|
|
return [ |
216
|
6 |
|
'searchForm' => $searchForm->createView(), |
217
|
|
|
'pagination' => [], |
218
|
1 |
|
'pageMaxis' => $pageMaxis, |
219
|
1 |
|
'page_no' => $page_no, |
220
|
1 |
|
'page_count' => $page_count, |
221
|
|
|
'has_errors' => true, |
222
|
|
|
]; |
223
|
|
|
} |
224
|
|
|
} else { |
225
|
3 |
|
if (null !== $page_no || $request->get('resume')) { |
226
|
|
|
/* |
227
|
|
|
* ページ送りの場合または、他画面から戻ってきた場合は, セッションから検索条件を復旧する. |
228
|
|
|
*/ |
229
|
1 |
|
if ($page_no) { |
230
|
|
|
// ページ送りで遷移した場合. |
231
|
1 |
|
$this->session->set('eccube.admin.order.search.page_no', (int) $page_no); |
232
|
|
|
} else { |
233
|
|
|
// 他画面から遷移した場合. |
234
|
|
|
$page_no = $this->session->get('eccube.admin.order.search.page_no', 1); |
235
|
|
|
} |
236
|
1 |
|
$viewData = $this->session->get('eccube.admin.order.search', []); |
237
|
1 |
|
$searchData = FormUtil::submitAndGetData($searchForm, $viewData); |
238
|
|
|
} else { |
239
|
|
|
/** |
240
|
|
|
* 初期表示の場合. |
241
|
|
|
*/ |
242
|
2 |
|
$page_no = 1; |
243
|
2 |
|
$viewData = []; |
244
|
|
|
|
245
|
2 |
|
if ($statusId = (int) $request->get('order_status_id')) { |
246
|
|
|
$viewData = ['status' => $statusId]; |
247
|
|
|
} |
248
|
|
|
|
249
|
2 |
|
$searchData = FormUtil::submitAndGetData($searchForm, $viewData); |
250
|
|
|
|
251
|
|
|
// セッション中の検索条件, ページ番号を初期化. |
252
|
2 |
|
$this->session->set('eccube.admin.order.search', $viewData); |
253
|
2 |
|
$this->session->set('eccube.admin.order.search.page_no', $page_no); |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
|
257
|
8 |
|
$qb = $this->orderRepository->getQueryBuilderBySearchDataForAdmin($searchData); |
258
|
|
|
|
259
|
8 |
|
$event = new EventArgs( |
260
|
|
|
[ |
261
|
8 |
|
'qb' => $qb, |
262
|
8 |
|
'searchData' => $searchData, |
263
|
|
|
], |
264
|
8 |
|
$request |
265
|
|
|
); |
266
|
|
|
|
267
|
8 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_SEARCH, $event); |
268
|
|
|
|
269
|
8 |
|
$pagination = $paginator->paginate( |
270
|
8 |
|
$qb, |
271
|
8 |
|
$page_no, |
272
|
8 |
|
$page_count |
273
|
|
|
); |
274
|
|
|
|
275
|
|
|
return [ |
276
|
8 |
|
'searchForm' => $searchForm->createView(), |
277
|
8 |
|
'pagination' => $pagination, |
278
|
8 |
|
'pageMaxis' => $pageMaxis, |
279
|
8 |
|
'page_no' => $page_no, |
280
|
8 |
|
'page_count' => $page_count, |
281
|
|
|
'has_errors' => false, |
282
|
8 |
|
'OrderStatuses' => $this->orderStatusRepository->findBy([], ['sort_no' => 'ASC']), |
283
|
|
|
]; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
|
|
|
|
287
|
|
|
* @Method("POST") |
288
|
|
|
* @Route("/%eccube_admin_route%/order/bulk_delete", name="admin_order_bulk_delete") |
289
|
|
|
*/ |
|
|
|
|
290
|
1 |
|
public function bulkDelete(Request $request) |
291
|
|
|
{ |
292
|
1 |
|
$this->isTokenValid(); |
293
|
1 |
|
$ids = $request->get('ids'); |
294
|
1 |
|
foreach ($ids as $order_id) { |
295
|
1 |
|
$Order = $this->orderRepository |
|
|
|
|
296
|
1 |
|
->find($order_id); |
297
|
1 |
|
if ($Order) { |
298
|
1 |
|
$this->entityManager->remove($Order); |
299
|
1 |
|
log_info('受注削除', [$Order->getId()]); |
300
|
|
|
} |
301
|
|
|
} |
302
|
|
|
|
303
|
1 |
|
$this->entityManager->flush(); |
304
|
|
|
|
305
|
1 |
|
$this->addSuccess('admin.order.delete.complete', 'admin'); |
306
|
|
|
|
307
|
1 |
|
return $this->redirect($this->generateUrl('admin_order', ['resume' => Constant::ENABLED])); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* 受注CSVの出力. |
312
|
|
|
* |
313
|
|
|
* @Route("/%eccube_admin_route%/order/export/order", name="admin_order_export_order") |
314
|
|
|
* |
315
|
|
|
* @param Request $request |
316
|
|
|
* |
317
|
|
|
* @return StreamedResponse |
318
|
|
|
*/ |
319
|
1 |
View Code Duplication |
public function exportOrder(Request $request) |
|
|
|
|
320
|
|
|
{ |
321
|
1 |
|
$filename = 'order_'.(new \DateTime())->format('YmdHis').'.csv'; |
322
|
1 |
|
$response = $this->exportCsv($request, CsvType::CSV_TYPE_ORDER, $filename); |
323
|
|
|
log_info('受注CSV出力ファイル名', [$filename]); |
324
|
|
|
|
325
|
|
|
return $response; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* 配送CSVの出力. |
330
|
|
|
* |
331
|
|
|
* @Route("/%eccube_admin_route%/order/export/shipping", name="admin_order_export_shipping") |
332
|
|
|
* |
333
|
|
|
* @param Request $request |
334
|
|
|
* |
335
|
|
|
* @return StreamedResponse |
336
|
|
|
*/ |
337
|
|
View Code Duplication |
public function exportShipping(Request $request) |
|
|
|
|
338
|
|
|
{ |
339
|
|
|
$filename = 'shipping_'.(new \DateTime())->format('YmdHis').'.csv'; |
340
|
|
|
$response = $this->exportCsv($request, CsvType::CSV_TYPE_SHIPPING, $filename); |
341
|
|
|
log_info('配送CSV出力ファイル名', [$filename]); |
342
|
|
|
|
343
|
|
|
return $response; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @param Request $request |
348
|
|
|
* @param $csvTypeId |
349
|
|
|
* @param $fileName |
350
|
|
|
* |
351
|
|
|
* @return StreamedResponse |
352
|
|
|
*/ |
353
|
1 |
|
private function exportCsv(Request $request, $csvTypeId, $fileName) |
354
|
|
|
{ |
355
|
|
|
// タイムアウトを無効にする. |
356
|
1 |
|
set_time_limit(0); |
357
|
|
|
|
358
|
|
|
// sql loggerを無効にする. |
359
|
1 |
|
$em = $this->entityManager; |
360
|
1 |
|
$em->getConfiguration()->setSQLLogger(null); |
361
|
|
|
|
362
|
1 |
|
$response = new StreamedResponse(); |
363
|
1 |
|
$response->setCallback(function () use ($request, $csvTypeId) { |
364
|
|
|
// CSV種別を元に初期化. |
365
|
1 |
|
$this->csvExportService->initCsvType($csvTypeId); |
366
|
|
|
|
367
|
|
|
// ヘッダ行の出力. |
368
|
|
|
$this->csvExportService->exportHeader(); |
369
|
|
|
|
370
|
|
|
// 受注データ検索用のクエリビルダを取得. |
371
|
|
|
$qb = $this->csvExportService |
372
|
|
|
->getOrderQueryBuilder($request); |
373
|
|
|
|
374
|
|
|
// データ行の出力. |
375
|
|
|
$this->csvExportService->setExportQueryBuilder($qb); |
376
|
|
|
$this->csvExportService->exportData(function ($entity, $csvService) use ($request) { |
377
|
|
|
$Csvs = $csvService->getCsvs(); |
378
|
|
|
|
379
|
|
|
$Order = $entity; |
380
|
|
|
$OrderItems = $Order->getOrderItems(); |
381
|
|
|
|
382
|
|
|
foreach ($OrderItems as $OrderItem) { |
383
|
|
|
$ExportCsvRow = new ExportCsvRow(); |
384
|
|
|
|
385
|
|
|
// CSV出力項目と合致するデータを取得. |
386
|
|
|
foreach ($Csvs as $Csv) { |
387
|
|
|
// 受注データを検索. |
388
|
|
|
$ExportCsvRow->setData($csvService->getData($Csv, $Order)); |
389
|
|
|
if ($ExportCsvRow->isDataNull()) { |
390
|
|
|
// 受注データにない場合は, 受注明細を検索. |
391
|
|
|
$ExportCsvRow->setData($csvService->getData($Csv, $OrderItem)); |
392
|
|
|
} |
393
|
|
|
if ($ExportCsvRow->isDataNull() && $Shipping = $OrderItem->getShipping()) { |
394
|
|
|
// 受注明細データにない場合は, 出荷を検索. |
395
|
|
|
$ExportCsvRow->setData($csvService->getData($Csv, $Shipping)); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
$event = new EventArgs( |
399
|
|
|
[ |
400
|
|
|
'csvService' => $csvService, |
401
|
|
|
'Csv' => $Csv, |
402
|
|
|
'OrderItem' => $OrderItem, |
403
|
|
|
'ExportCsvRow' => $ExportCsvRow, |
404
|
|
|
], |
405
|
|
|
$request |
406
|
|
|
); |
407
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_CSV_EXPORT_ORDER, $event); |
408
|
|
|
|
409
|
|
|
$ExportCsvRow->pushData(); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
//$row[] = number_format(memory_get_usage(true)); |
413
|
|
|
// 出力. |
414
|
|
|
$csvService->fputcsv($ExportCsvRow->getRow()); |
415
|
|
|
} |
416
|
|
|
}); |
417
|
1 |
|
}); |
418
|
|
|
|
419
|
1 |
|
$response->headers->set('Content-Type', 'application/octet-stream'); |
420
|
1 |
|
$response->headers->set('Content-Disposition', 'attachment; filename='.$fileName); |
421
|
1 |
|
$response->send(); |
422
|
|
|
|
423
|
|
|
return $response; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* Bulk action to order status |
428
|
|
|
* |
429
|
|
|
* @Method("POST") |
430
|
|
|
* @Route("/%eccube_admin_route%/order/bulk/order-status/{id}", requirements={"id" = "\d+"}, name="admin_order_bulk_order_status") |
431
|
|
|
* |
432
|
|
|
* @param Request $request |
|
|
|
|
433
|
|
|
* @param OrderStatus $OrderStatus |
434
|
|
|
* |
435
|
|
|
* @return RedirectResponse |
436
|
|
|
*/ |
437
|
2 |
|
public function bulkOrderStatus(Request $request, OrderStatus $OrderStatus) |
|
|
|
|
438
|
|
|
{ |
439
|
2 |
|
$this->isTokenValid(); |
440
|
|
|
|
441
|
|
|
/** @var Order[] $Orders */ |
442
|
2 |
|
$Orders = $this->orderRepository->findBy(['id' => $request->get('ids')]); |
443
|
|
|
|
444
|
2 |
|
$count = 0; |
445
|
2 |
|
foreach ($Orders as $Order) { |
446
|
|
|
try { |
447
|
|
|
// TODO: should support event for plugin customize |
448
|
|
|
// 編集前の受注情報を保持 |
449
|
2 |
|
$OriginOrder = clone $Order; |
450
|
|
|
|
451
|
2 |
|
$Order->setOrderStatus($OrderStatus); |
452
|
|
|
|
453
|
2 |
|
$purchaseContext = new PurchaseContext($OriginOrder, $OriginOrder->getCustomer()); |
454
|
|
|
|
455
|
2 |
|
$flowResult = $this->purchaseFlow->validate($Order, $purchaseContext); |
456
|
2 |
|
if ($flowResult->hasWarning()) { |
457
|
|
|
foreach ($flowResult->getWarning() as $warning) { |
458
|
|
|
$msg = $this->translator->trans('admin.order.index.bulk_warning', [ |
459
|
|
|
'%orderId%' => $Order->getId(), |
|
|
|
|
460
|
|
|
'%message%' => $warning->getMessage(), |
|
|
|
|
461
|
|
|
]); |
462
|
|
|
$this->addWarning($msg, 'admin'); |
463
|
|
|
} |
464
|
|
|
} |
465
|
|
|
|
466
|
2 |
|
if ($flowResult->hasError()) { |
467
|
|
|
foreach ($flowResult->getErrors() as $error) { |
468
|
|
|
$msg = $this->translator->trans('admin.order.index.bulk_error', [ |
469
|
|
|
'%orderId%' => $Order->getId(), |
|
|
|
|
470
|
|
|
'%message%' => $error->getMessage(), |
|
|
|
|
471
|
|
|
]); |
472
|
|
|
$this->addError($msg, 'admin'); |
473
|
|
|
} |
474
|
|
|
continue; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
try { |
478
|
2 |
|
$this->purchaseFlow->commit($Order, $purchaseContext); |
479
|
|
|
} catch (PurchaseException $e) { |
480
|
|
|
$msg = $this->translator->trans('admin.order.index.bulk_error', [ |
481
|
|
|
'%orderId%' => $Order->getId(), |
|
|
|
|
482
|
|
|
'%message%' => $e->getMessage(), |
|
|
|
|
483
|
|
|
]); |
484
|
|
|
$this->addError($msg, 'admin'); |
485
|
|
|
continue; |
486
|
|
|
} |
487
|
|
|
|
488
|
2 |
|
$this->orderRepository->save($Order); |
489
|
|
|
|
490
|
2 |
|
$count++; |
491
|
|
|
} catch (\Exception $e) { |
492
|
2 |
|
$this->addError('#'.$Order->getId().': '.$e->getMessage(), 'admin'); |
493
|
|
|
} |
494
|
|
|
} |
495
|
|
|
try { |
496
|
2 |
View Code Duplication |
if ($count) { |
497
|
2 |
|
$this->entityManager->flush(); |
498
|
2 |
|
$msg = $this->translator->trans('admin.order.index.bulk_order_status_success_count', [ |
499
|
2 |
|
'%count%' => $count, |
500
|
2 |
|
'%status%' => $OrderStatus->getName(), |
501
|
|
|
]); |
502
|
2 |
|
$this->addSuccess($msg, 'admin'); |
503
|
|
|
} |
504
|
|
|
} catch (\Exception $e) { |
505
|
|
|
log_error('Bulk order status error', [$e]); |
506
|
|
|
$this->addError('admin.flash.register_failed', 'admin'); |
507
|
|
|
} |
508
|
|
|
|
509
|
2 |
|
return $this->redirectToRoute('admin_order', ['resume' => Constant::ENABLED]); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* Update to Tracking number. |
514
|
|
|
* |
515
|
|
|
* @Method("PUT") |
516
|
|
|
* @Route("/%eccube_admin_route%/shipping/{id}/tracking_number", requirements={"id" = "\d+"}, name="admin_shipping_update_tracking_number") |
517
|
|
|
* |
518
|
|
|
* @param Request $request |
|
|
|
|
519
|
|
|
* @param Shipping $shipping |
520
|
|
|
* |
521
|
|
|
* @return Response |
522
|
|
|
*/ |
523
|
2 |
|
public function updateTrackingNumber(Request $request, Shipping $shipping) |
524
|
|
|
{ |
525
|
2 |
|
if (!($request->isXmlHttpRequest() && $this->isTokenValid())) { |
526
|
|
|
return $this->json(['status' => 'NG'], 400); |
527
|
|
|
} |
528
|
|
|
|
529
|
2 |
|
$trackingNumber = mb_convert_kana($request->get('tracking_number'), 'a', 'utf-8'); |
530
|
|
|
/** @var \Symfony\Component\Validator\ConstraintViolationListInterface $errors */ |
531
|
2 |
|
$errors = $this->validator->validate( |
532
|
2 |
|
$trackingNumber, |
533
|
|
|
[ |
534
|
2 |
|
new Assert\Length(['max' => $this->eccubeConfig['eccube_stext_len']]), |
535
|
2 |
|
new Assert\Regex( |
536
|
2 |
|
['pattern' => '/^[0-9a-zA-Z-]+$/u', 'message' => trans('form.type.admin.nottrackingnumberstyle')] |
537
|
|
|
), |
538
|
|
|
] |
539
|
|
|
); |
540
|
|
|
|
541
|
2 |
|
if ($errors->count() != 0) { |
542
|
1 |
|
log_info('送り状番号入力チェックエラー'); |
543
|
1 |
|
$messages = []; |
544
|
|
|
/** @var \Symfony\Component\Validator\ConstraintViolationInterface $error */ |
545
|
1 |
|
foreach ($errors as $error) { |
546
|
1 |
|
$messages[] = $error->getMessage(); |
547
|
|
|
} |
548
|
|
|
|
549
|
1 |
|
return $this->json(['status' => 'NG', 'messages' => $messages], 400); |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
try { |
553
|
1 |
|
$shipping->setTrackingNumber($trackingNumber); |
554
|
1 |
|
$this->entityManager->flush($shipping); |
|
|
|
|
555
|
1 |
|
log_info('送り状番号変更処理完了', [$shipping->getId()]); |
556
|
1 |
|
$message = ['status' => 'OK', 'shipping_id' => $shipping->getId(), 'tracking_number' => $trackingNumber]; |
557
|
|
|
|
558
|
1 |
|
return $this->json($message); |
559
|
|
|
} catch (\Exception $e) { |
560
|
|
|
log_error('予期しないエラー', [$e->getMessage()]); |
561
|
|
|
|
562
|
|
|
return $this->json(['status' => 'NG'], 500); |
563
|
|
|
} |
564
|
|
|
} |
565
|
|
|
} |
566
|
|
|
|