Completed
Pull Request — experimental/sf (#3272)
by chihiro
39:46
created

OrderController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 9
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
ccs 10
cts 10
cp 1
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\Master\CsvType;
20
use Eccube\Entity\OrderItem;
21
use Eccube\Entity\Shipping;
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\Request;
39
use Symfony\Component\HttpFoundation\StreamedResponse;
40
use Eccube\Entity\Master\OrderStatus;
41
use Symfony\Component\HttpFoundation\RedirectResponse;
42
use Eccube\Entity\Order;
43
use Eccube\Service\PurchaseFlow\PurchaseContext;
44
use Eccube\Service\PurchaseFlow\PurchaseFlow;
45
use Eccube\Service\PurchaseFlow\PurchaseException;
46
47
class OrderController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
48
{
49
    /**
50
     * @var PurchaseFlow
51
     */
52
    protected $purchaseFlow;
53
54
    /**
55
     * @var CsvExportService
56
     */
57
    protected $csvExportService;
58
59
    /**
60
     * @var CustomerRepository
61
     */
62
    protected $customerRepository;
63
64
    /**
65
     * @var PaymentRepository
66
     */
67
    protected $paymentRepository;
68
69
    /**
70
     * @var SexRepository
71
     */
72
    protected $sexRepository;
73
74
    /**
75
     * @var OrderStatusRepository
76
     */
77
    protected $orderStatusRepository;
78
79
    /**
80
     * @var PageMaxRepository
81
     */
82
    protected $pageMaxRepository;
83
84
    /**
85
     * @var ProductStatusRepository
86
     */
87
    protected $productStatusRepository;
88
89
    /**
90
     * @var OrderRepository
91
     */
92
    protected $orderRepository;
93
94
    /**
95
     * OrderController constructor.
96
     *
97
     * @param PurchaseFlow $orderPurchaseFlow
0 ignored issues
show
introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
98
     * @param CsvExportService $csvExportService
0 ignored issues
show
introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
99
     * @param CustomerRepository $customerRepository
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
100
     * @param PaymentRepository $paymentRepository
0 ignored issues
show
introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
101
     * @param SexRepository $sexRepository
0 ignored issues
show
introduced by
Expected 11 spaces after parameter type; 1 found
Loading history...
102
     * @param OrderStatusRepository $orderStatusRepository
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
103
     * @param PageMaxRepository $pageMaxRepository
0 ignored issues
show
introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
104
     * @param ProductStatusRepository $productStatusRepository
105
     * @param OrderRepository $orderRepository
0 ignored issues
show
introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
106
     */
107 13
    public function __construct(
108
        PurchaseFlow $orderPurchaseFlow,
109
        CsvExportService $csvExportService,
110
        CustomerRepository $customerRepository,
111
        PaymentRepository $paymentRepository,
112
        SexRepository $sexRepository,
113
        OrderStatusRepository $orderStatusRepository,
114
        PageMaxRepository $pageMaxRepository,
115
        ProductStatusRepository $productStatusRepository,
116
        OrderRepository $orderRepository
117
    ) {
118 13
        $this->purchaseFlow = $orderPurchaseFlow;
119 13
        $this->csvExportService = $csvExportService;
120 13
        $this->customerRepository = $customerRepository;
121 13
        $this->paymentRepository = $paymentRepository;
122 13
        $this->sexRepository = $sexRepository;
123 13
        $this->orderStatusRepository = $orderStatusRepository;
124 13
        $this->pageMaxRepository = $pageMaxRepository;
125 13
        $this->productStatusRepository = $productStatusRepository;
126 13
        $this->orderRepository = $orderRepository;
127
    }
128
129
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$page_no" missing
Loading history...
introduced by
Doc comment for parameter "$paginator" missing
Loading history...
130
     * 受注一覧画面.
131
     *
132
     * - 検索条件, ページ番号, 表示件数はセッションに保持されます.
133
     * - クエリパラメータでresume=1が指定された場合、検索条件, ページ番号, 表示件数をセッションから復旧します.
134
     * - 各データの, セッションに保持するアクションは以下の通りです.
135
     *   - 検索ボタン押下時
136
     *      - 検索条件をセッションに保存します
137
     *      - ページ番号は1で初期化し、セッションに保存します。
138
     *   - 表示件数変更時
139
     *      - クエリパラメータpage_countをセッションに保存します。
140
     *      - ただし, mtb_page_maxと一致しない場合, eccube_default_page_countが保存されます.
141
     *   - ページング時
142
     *      - URLパラメータpage_noをセッションに保存します.
143
     *   - 初期表示
144
     *      - 検索条件は空配列, ページ番号は1で初期化し, セッションに保存します.
145
     *
146
     * @Route("/%eccube_admin_route%/order", name="admin_order")
147
     * @Route("/%eccube_admin_route%/order/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_order_page")
148
     * @Template("@admin/Order/index.twig")
149
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
150 9
    public function index(Request $request, $page_no = null, PaginatorInterface $paginator)
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
151
    {
152 9
        $builder = $this->formFactory
153 9
            ->createBuilder(SearchOrderType::class);
154
155 9
        $event = new EventArgs(
156
            [
157 9
                'builder' => $builder,
158
            ],
159 9
            $request
160
        );
161 9
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_INITIALIZE, $event);
162
163 9
        $searchForm = $builder->getForm();
164
165
        /**
166
         * ページの表示件数は, 以下の順に優先される.
167
         * - リクエストパラメータ
168
         * - セッション
169
         * - デフォルト値
170
         * また, セッションに保存する際は mtb_page_maxと照合し, 一致した場合のみ保存する.
171
         **/
172 9
        $page_count = $this->session->get('eccube.admin.order.search.page_count',
173 9
                $this->eccubeConfig->get('eccube_default_page_count'));
174
175 9
        $page_count_param = (int) $request->get('page_count');
176 9
        $pageMaxis = $this->pageMaxRepository->findAll();
177
178 9
        if ($page_count_param) {
179 1
            foreach ($pageMaxis as $pageMax) {
180 1
                if ($page_count_param == $pageMax->getName()) {
181
                    $page_count = $pageMax->getName();
182
                    $this->session->set('eccube.admin.order.search.page_count', $page_count);
183 1
                    break;
184
                }
185
            }
186
        }
187
188 9
        if ('POST' === $request->getMethod()) {
189 7
            $searchForm->handleRequest($request);
190
191 7
            if ($searchForm->isValid()) {
192
                /**
193
                 * 検索が実行された場合は, セッションに検索条件を保存する.
194
                 * ページ番号は最初のページ番号に初期化する.
195
                 */
196 6
                $page_no = 1;
197 6
                $searchData = $searchForm->getData();
198
199
                // 検索条件, ページ番号をセッションに保持.
200 6
                $this->session->set('eccube.admin.order.search', FormUtil::getViewData($searchForm));
201 6
                $this->session->set('eccube.admin.order.search.page_no', $page_no);
202
            } else {
203
                // 検索エラーの際は, 詳細検索枠を開いてエラー表示する.
204
                return [
205 7
                    'searchForm' => $searchForm->createView(),
206
                    'pagination' => [],
207 1
                    'pageMaxis' => $pageMaxis,
208 1
                    'page_no' => $page_no,
209 1
                    'page_count' => $page_count,
210
                    'has_errors' => true,
211
                ];
212
            }
213
        } else {
214 3
            if (null !== $page_no || $request->get('resume')) {
215
                /*
216
                 * ページ送りの場合または、他画面から戻ってきた場合は, セッションから検索条件を復旧する.
217
                 */
218 1
                if ($page_no) {
219
                    // ページ送りで遷移した場合.
220 1
                    $this->session->set('eccube.admin.order.search.page_no', (int) $page_no);
221
                } else {
222
                    // 他画面から遷移した場合.
223
                    $page_no = $this->session->get('eccube.admin.order.search.page_no', 1);
224
                }
225 1
                $viewData = $this->session->get('eccube.admin.order.search', []);
226 1
                $searchData = FormUtil::submitAndGetData($searchForm, $viewData);
227
            } else {
228
                /**
229
                 * 初期表示の場合.
230
                 */
231 2
                $page_no = 1;
232 2
                $viewData = [];
233
234 2
                if ($statusId = (int) $request->get('order_status_id')) {
235
                    $viewData = ['status' => $statusId];
236
                }
237
238 2
                $searchData = FormUtil::submitAndGetData($searchForm, $viewData);
239
240
                // セッション中の検索条件, ページ番号を初期化.
241 2
                $this->session->set('eccube.admin.order.search', $viewData);
242 2
                $this->session->set('eccube.admin.order.search.page_no', $page_no);
243
            }
244
        }
245
246 9
        $qb = $this->orderRepository->getQueryBuilderBySearchDataForAdmin($searchData);
247
248 9
        $event = new EventArgs(
249
            [
250 9
                'qb' => $qb,
251 9
                'searchData' => $searchData,
252
            ],
253 9
            $request
254
        );
255
256 9
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_SEARCH, $event);
257
258 9
        $pagination = $paginator->paginate(
259 9
            $qb,
260 9
            $page_no,
261 9
            $page_count
262
        );
263
264
        return [
265 9
            'searchForm' => $searchForm->createView(),
266 9
            'pagination' => $pagination,
267 9
            'pageMaxis' => $pageMaxis,
268 9
            'page_no' => $page_no,
269 9
            'page_count' => $page_count,
270
            'has_errors' => false,
271 9
            'OrderStatuses' => $this->orderStatusRepository->findBy([], ['sort_no' => 'ASC']),
272
        ];
273
    }
274
275
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$request" missing
Loading history...
276
     * @Method("POST")
277
     * @Route("/%eccube_admin_route%/order/bulk_delete", name="admin_order_bulk_delete")
278
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
279 1
    public function bulkDelete(Request $request)
280
    {
281 1
        $this->isTokenValid();
282 1
        $ids = $request->get('ids');
283 1
        foreach ($ids as $order_id) {
284 1
            $Order = $this->orderRepository
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $Order is correct as $this->orderRepository->find($order_id) (which targets Doctrine\ORM\EntityRepository::find()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
285 1
                ->find($order_id);
286 1
            if ($Order) {
287 1
                $this->entityManager->remove($Order);
288 1
                log_info('受注削除', [$Order->getId()]);
289
            }
290
        }
291
292 1
        $this->entityManager->flush();
293
294 1
        $this->addSuccess('admin.order.delete.complete', 'admin');
295
296 1
        return $this->redirect($this->generateUrl('admin_order', ['resume' => Constant::ENABLED]));
297
    }
298
299
    /**
300
     * 受注CSVの出力.
301
     *
302
     * @Route("/%eccube_admin_route%/order/export/order", name="admin_order_export_order")
303
     *
304
     * @param Request $request
305
     *
306
     * @return StreamedResponse
307
     */
308 1
    public function exportOrder(Request $request)
309
    {
310
        // タイムアウトを無効にする.
311 1
        set_time_limit(0);
312
313
        // sql loggerを無効にする.
314 1
        $em = $this->entityManager;
315 1
        $em->getConfiguration()->setSQLLogger(null);
316
317 1
        $response = new StreamedResponse();
318 1
        $response->setCallback(function () use ($request) {
319
            // CSV種別を元に初期化.
320 1
            $this->csvExportService->initCsvType(CsvType::CSV_TYPE_ORDER);
321
322
            // ヘッダ行の出力.
323 1
            $this->csvExportService->exportHeader();
324
325
            // 受注データ検索用のクエリビルダを取得.
326 1
            $qb = $this->csvExportService
327 1
                ->getOrderQueryBuilder($request);
328
329
            // データ行の出力.
330 1
            $this->csvExportService->setExportQueryBuilder($qb);
331 1 View Code Duplication
            $this->csvExportService->exportData(function ($entity, $csvService) use ($request) {
332 1
                $Csvs = $csvService->getCsvs();
333
334 1
                $Order = $entity;
335 1
                $OrderItems = $Order->getOrderItems();
336
337 1
                foreach ($OrderItems as $OrderItem) {
338 1
                    $ExportCsvRow = new \Eccube\Entity\ExportCsvRow();
339
340
                    // CSV出力項目と合致するデータを取得.
341 1
                    foreach ($Csvs as $Csv) {
342
                        // 受注データを検索.
343 1
                        $ExportCsvRow->setData($csvService->getData($Csv, $Order));
344 1
                        if ($ExportCsvRow->isDataNull()) {
345
                            // 受注データにない場合は, 受注明細を検索.
346 1
                            $ExportCsvRow->setData($csvService->getData($Csv, $OrderItem));
347
                        }
348
349 1
                        $event = new EventArgs(
350
                            [
351 1
                                'csvService' => $csvService,
352 1
                                'Csv' => $Csv,
353 1
                                'OrderItem' => $OrderItem,
354 1
                                'ExportCsvRow' => $ExportCsvRow,
355
                            ],
356 1
                            $request
357
                        );
358 1
                        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_CSV_EXPORT_ORDER, $event);
359
360 1
                        $ExportCsvRow->pushData();
361
                    }
362
363
                    //$row[] = number_format(memory_get_usage(true));
364
                    // 出力.
365 1
                    $csvService->fputcsv($ExportCsvRow->getRow());
366
                }
367 1
            });
368 1
        });
369
370 1
        $now = new \DateTime();
371 1
        $filename = 'order_'.$now->format('YmdHis').'.csv';
372 1
        $response->headers->set('Content-Type', 'application/octet-stream');
373 1
        $response->headers->set('Content-Disposition', 'attachment; filename='.$filename);
374 1
        $response->send();
375
376 1
        log_info('受注CSV出力ファイル名', [$filename]);
377
378 1
        return $response;
379
    }
380
381
    /**
382
     * 配送CSVの出力.
383
     *
384
     * @Route("/%eccube_admin_route%/order/export/shipping", name="admin_order_export_shipping")
385
     *
386
     * @param Request $request
387
     *
388
     * @return StreamedResponse
389
     */
390 1
    public function exportShipping(Request $request)
391
    {
392
        // タイムアウトを無効にする.
393 1
        set_time_limit(0);
394
395
        // sql loggerを無効にする.
396 1
        $em = $this->entityManager;
397 1
        $em->getConfiguration()->setSQLLogger(null);
398
399 1
        $response = new StreamedResponse();
400 1
        $response->setCallback(function () use ($request) {
401
            // CSV種別を元に初期化.
402 1
            $this->csvExportService->initCsvType(CsvType::CSV_TYPE_SHIPPING);
403
404
            // ヘッダ行の出力.
405 1
            $this->csvExportService->exportHeader();
406
407
            // 受注データ検索用のクエリビルダを取得.
408 1
            $qb = $this->csvExportService
409 1
                ->getShippingQueryBuilder($request);
410
411
            // データ行の出力.
412 1
            $this->csvExportService->setExportQueryBuilder($qb);
413 1
            $this->csvExportService->exportData(function ($entity, $csvService) use ($request) {
414
                /** @var Csv[] $Csvs */
415 1
                $Csvs = $csvService->getCsvs();
416
417
                /** @var Shipping $Shipping */
418 1
                $Shipping = $entity;
419
                /** @var OrderItem[] $OrderItems */
420 1
                $OrderItems = $Shipping->getOrderItems();
421
422 1
                foreach ($OrderItems as $OrderItem) {
423 1
                    $ExportCsvRow = new \Eccube\Entity\ExportCsvRow();
424
425 1
                    $Order = $OrderItem->getOrder();
426
                    // CSV出力項目と合致するデータを取得.
427 1
                    foreach ($Csvs as $Csv) {
428
                        // 受注データを検索.
429 1
                        $ExportCsvRow->setData($csvService->getData($Csv, $Order));
430
431 1
                        if ($ExportCsvRow->isDataNull()) {
432
                            // 受注データにない場合は, 出荷データを検索.
433 1
                            $ExportCsvRow->setData($csvService->getData($Csv, $Shipping));
434
                        }
435 1
                        if ($ExportCsvRow->isDataNull()) {
436
                            // 出荷データにない場合は, 出荷明細を検索.
437 1
                            $ExportCsvRow->setData($csvService->getData($Csv, $OrderItem));
438
                        }
439
440 1
                        $event = new EventArgs(
441
                            [
442 1
                                'csvService' => $csvService,
443 1
                                'Csv' => $Csv,
444 1
                                'OrderItem' => $OrderItem,
445 1
                                'ExportCsvRow' => $ExportCsvRow,
446
                            ],
447 1
                            $request
448
                        );
449 1
                        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_CSV_EXPORT_SHIPPING, $event);
450
451 1
                        $ExportCsvRow->pushData();
452
                    }
453
                    //$row[] = number_format(memory_get_usage(true));
454
                    // 出力.
455 1
                    $csvService->fputcsv($ExportCsvRow->getRow());
456
                }
457 1
            });
458 1
        });
459
460 1
        $now = new \DateTime();
461 1
        $filename = 'shipping_'.$now->format('YmdHis').'.csv';
462 1
        $response->headers->set('Content-Type', 'application/octet-stream');
463 1
        $response->headers->set('Content-Disposition', 'attachment; filename='.$filename);
464 1
        $response->send();
465
466 1
        log_info('出荷CSV出力ファイル名', [$filename]);
467
468 1
        return $response;
469
    }
470
471
    /**
472
     * Bulk action to order status
473
     *
474
     * @Method("POST")
475
     * @Route("/%eccube_admin_route%/order/bulk/order-status/{id}", requirements={"id" = "\d+"}, name="admin_order_bulk_order_status")
476
     *
477
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
478
     * @param OrderStatus $OrderStatus
479
     *
480
     * @return RedirectResponse
481
     */
482 2
    public function bulkOrderStatus(Request $request, OrderStatus $OrderStatus)
483
    {
484 2
        $this->isTokenValid();
485
486
        /** @var Order[] $Orders */
487 2
        $Orders = $this->orderRepository->findBy(['id' => $request->get('ids')]);
488
489 2
        $count = 0;
490 2
        foreach ($Orders as $Order) {
491
            try {
492
                // TODO: should support event for plugin customize
493
                // 編集前の受注情報を保持
494 2
                $OriginOrder = clone $Order;
495
496 2
                $Order->setOrderStatus($OrderStatus);
497
498 2
                $purchaseContext = new PurchaseContext($OriginOrder, $OriginOrder->getCustomer());
499
500 2
                $flowResult = $this->purchaseFlow->validate($Order, $purchaseContext);
501 2
                if ($flowResult->hasWarning()) {
502
                    foreach ($flowResult->getWarning() as $warning) {
503
                        $msg = $this->translator->trans('admin.order.index.bulk_warning', [
504
                          '%orderId%' => $Order->getId(),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 28 spaces, but found 26.
Loading history...
505
                          '%message%' => $warning->getMessage(),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 28 spaces, but found 26.
Loading history...
506
                        ]);
507
                        $this->addWarning($msg, 'admin');
508
                    }
509
                }
510
511 2
                if ($flowResult->hasError()) {
512
                    foreach ($flowResult->getErrors() as $error) {
513
                        $msg = $this->translator->trans('admin.order.index.bulk_error', [
514
                          '%orderId%' => $Order->getId(),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 28 spaces, but found 26.
Loading history...
515
                          '%message%' => $error->getMessage(),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 28 spaces, but found 26.
Loading history...
516
                        ]);
517
                        $this->addError($msg, 'admin');
518
                    }
519
                    continue;
520
                }
521
522
                try {
523 2
                    $this->purchaseFlow->commit($Order, $purchaseContext);
524
                } catch (PurchaseException $e) {
525
                    $msg = $this->translator->trans('admin.order.index.bulk_error', [
526
                      '%orderId%' => $Order->getId(),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 24 spaces, but found 22.
Loading history...
527
                      '%message%' => $e->getMessage(),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 24 spaces, but found 22.
Loading history...
528
                    ]);
529
                    $this->addError($msg, 'admin');
530
                    continue;
531
                }
532
533 2
                $this->orderRepository->save($Order);
534
535 2
                $count++;
536
            } catch (\Exception $e) {
537 2
                $this->addError('#'.$Order->getId().': '.$e->getMessage(), 'admin');
538
            }
539
        }
540
        try {
541 2 View Code Duplication
            if ($count) {
542 2
                $this->entityManager->flush();
543 2
                $msg = $this->translator->trans('admin.order.index.bulk_order_status_success_count', [
544 2
                    '%count%' => $count,
545 2
                    '%status%' => $OrderStatus->getName(),
546
                ]);
547 2
                $this->addSuccess($msg, 'admin');
548
            }
549
        } catch (\Exception $e) {
550
            log_error('Bulk order status error', [$e]);
551
            $this->addError('admin.flash.register_failed', 'admin');
552
        }
553
554 2
        return $this->redirectToRoute('admin_order', ['resume' => Constant::ENABLED]);
555
    }
556
}
557