Completed
Push — support-coverage ( 9b57a3...b5dae6 )
by Kentaro
41:38
created

OrderController   C

Complexity

Total Complexity 32

Size/Duplication

Total Lines 504
Duplicated Lines 8.93 %

Coupling/Cohesion

Components 1
Dependencies 24

Test Coverage

Coverage 86.57%

Importance

Changes 0
Metric Value
dl 45
loc 504
ccs 174
cts 201
cp 0.8657
rs 5.0285
c 0
b 0
f 0
wmc 32
lcom 1
cbo 24

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 1
D index() 0 118 9
A bulkDelete() 0 19 3
D bulkOrderStatus() 8 74 10
B exportOrder() 37 72 4
B exportShipping() 0 80 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
namespace Eccube\Controller\Admin\Order;
25
26
use Eccube\Common\Constant;
27
use Eccube\Controller\AbstractController;
28
use Eccube\Entity\Csv;
29
use Eccube\Entity\Master\CsvType;
30
use Eccube\Entity\OrderItem;
31
use Eccube\Entity\Shipping;
32
use Eccube\Event\EccubeEvents;
33
use Eccube\Event\EventArgs;
34
use Eccube\Form\Type\Admin\SearchOrderType;
35
use Eccube\Repository\CustomerRepository;
36
use Eccube\Repository\Master\OrderStatusRepository;
37
use Eccube\Repository\Master\PageMaxRepository;
38
use Eccube\Repository\Master\ProductStatusRepository;
39
use Eccube\Repository\Master\SexRepository;
40
use Eccube\Repository\OrderRepository;
41
use Eccube\Repository\PaymentRepository;
42
use Eccube\Service\CsvExportService;
43
use Eccube\Util\FormUtil;
44
use Knp\Component\Pager\PaginatorInterface;
45
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
46
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
47
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
48
use Symfony\Component\HttpFoundation\Request;
49
use Symfony\Component\HttpFoundation\StreamedResponse;
50
use Eccube\Entity\Master\OrderStatus;
51
use Symfony\Component\HttpFoundation\RedirectResponse;
52
use Eccube\Entity\Order;
53
use Eccube\Service\PurchaseFlow\PurchaseContext;
54
use Eccube\Service\PurchaseFlow\PurchaseFlow;
55
use Eccube\Service\PurchaseFlow\PurchaseException;
56
57
class OrderController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
58
{
59
    /**
60
     * @var PurchaseFlow
61
     */
62
    protected $purchaseFlow;
63
64
    /**
65
     * @var CsvExportService
66
     */
67
    protected $csvExportService;
68
69
    /**
70
     * @var CustomerRepository
71
     */
72
    protected $customerRepository;
73
74
    /**
75
     * @var PaymentRepository
76
     */
77
    protected $paymentRepository;
78
79
    /**
80
     * @var SexRepository
81
     */
82
    protected $sexRepository;
83
84
    /**
85
     * @var OrderStatusRepository
86
     */
87
    protected $orderStatusRepository;
88
89
    /**
90
     * @var PageMaxRepository
91
     */
92
    protected $pageMaxRepository;
93
94
    /**
95
     * @var ProductStatusRepository
96
     */
97
    protected $productStatusRepository;
98
99
    /**
100
     * @var OrderRepository
101
     */
102
    protected $orderRepository;
103
104
    /**
105
     * OrderController constructor.
106
     *
107
     * @param PurchaseFlow $orderPurchaseFlow
0 ignored issues
show
introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
108
     * @param CsvExportService $csvExportService
0 ignored issues
show
introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
109
     * @param CustomerRepository $customerRepository
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
110
     * @param PaymentRepository $paymentRepository
0 ignored issues
show
introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
111
     * @param SexRepository $sexRepository
0 ignored issues
show
introduced by
Expected 11 spaces after parameter type; 1 found
Loading history...
112
     * @param OrderStatusRepository $orderStatusRepository
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
113
     * @param PageMaxRepository $pageMaxRepository
0 ignored issues
show
introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
114
     * @param ProductStatusRepository $productStatusRepository
115
     * @param OrderRepository $orderRepository
0 ignored issues
show
introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
116
     */
117 13
    public function __construct(
118
        PurchaseFlow $orderPurchaseFlow,
119
        CsvExportService $csvExportService,
120
        CustomerRepository $customerRepository,
121
        PaymentRepository $paymentRepository,
122
        SexRepository $sexRepository,
123
        OrderStatusRepository $orderStatusRepository,
124
        PageMaxRepository $pageMaxRepository,
125
        ProductStatusRepository $productStatusRepository,
126
        OrderRepository $orderRepository
127
    ) {
128 13
        $this->purchaseFlow = $orderPurchaseFlow;
129 13
        $this->csvExportService = $csvExportService;
130 13
        $this->customerRepository = $customerRepository;
131 13
        $this->paymentRepository = $paymentRepository;
132 13
        $this->sexRepository = $sexRepository;
133 13
        $this->orderStatusRepository = $orderStatusRepository;
134 13
        $this->pageMaxRepository = $pageMaxRepository;
135 13
        $this->productStatusRepository = $productStatusRepository;
136 13
        $this->orderRepository = $orderRepository;
137
    }
138
139
    /**
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...
140
     * 受注一覧画面.
141
     *
142
     * - 検索条件, ページ番号, 表示件数はセッションに保持されます.
143
     * - クエリパラメータでresume=1が指定された場合、検索条件, ページ番号, 表示件数をセッションから復旧します.
144
     * - 各データの, セッションに保持するアクションは以下の通りです.
145
     *   - 検索ボタン押下時
146
     *      - 検索条件をセッションに保存します
147
     *      - ページ番号は1で初期化し、セッションに保存します。
148
     *   - 表示件数変更時
149
     *      - クエリパラメータpage_countをセッションに保存します。
150
     *      - ただし, mtb_page_maxと一致しない場合, eccube_default_page_countが保存されます.
151
     *   - ページング時
152
     *      - URLパラメータpage_noをセッションに保存します.
153
     *   - 初期表示
154
     *      - 検索条件は空配列, ページ番号は1で初期化し, セッションに保存します.
155
     *
156
     * @Route("/%eccube_admin_route%/order", name="admin_order")
157
     * @Route("/%eccube_admin_route%/order/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_order_page")
158
     * @Template("@admin/Order/index.twig")
159
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
160 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...
161
    {
162 9
        $builder = $this->formFactory
163 9
            ->createBuilder(SearchOrderType::class);
164
165 9
        $event = new EventArgs(
166
            [
167 9
                'builder' => $builder,
168
            ],
169 9
            $request
170
        );
171 9
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_INITIALIZE, $event);
172
173 9
        $searchForm = $builder->getForm();
174
175
        /**
176
         * ページの表示件数は, 以下の順に優先される.
177
         * - リクエストパラメータ
178
         * - セッション
179
         * - デフォルト値
180
         * また, セッションに保存する際は mtb_page_maxと照合し, 一致した場合のみ保存する.
181
         **/
182 9
        $page_count = $this->session->get('eccube.admin.order.search.page_count',
183 9
                $this->eccubeConfig->get('eccube_default_page_count'));
184
185 9
        $page_count_param = (int) $request->get('page_count');
186 9
        $pageMaxis = $this->pageMaxRepository->findAll();
187
188 9
        if ($page_count_param) {
189 1
            foreach ($pageMaxis as $pageMax) {
190 1
                if ($page_count_param == $pageMax->getName()) {
191
                    $page_count = $pageMax->getName();
192
                    $this->session->set('eccube.admin.order.search.page_count', $page_count);
193 1
                    break;
194
                }
195
            }
196
        }
197
198 9
        if ('POST' === $request->getMethod()) {
199 7
            $searchForm->handleRequest($request);
200
201 7
            if ($searchForm->isValid()) {
202
                /**
203
                 * 検索が実行された場合は, セッションに検索条件を保存する.
204
                 * ページ番号は最初のページ番号に初期化する.
205
                 */
206 7
                $page_no = 1;
207 7
                $searchData = $searchForm->getData();
208
209
                // 検索条件, ページ番号をセッションに保持.
210 7
                $this->session->set('eccube.admin.order.search', FormUtil::getViewData($searchForm));
211 7
                $this->session->set('eccube.admin.order.search.page_no', $page_no);
212
            } else {
213
                // 検索エラーの際は, 詳細検索枠を開いてエラー表示する.
214
                return [
215 7
                    'searchForm' => $searchForm->createView(),
216
                    'pagination' => [],
217
                    'pageMaxis' => $pageMaxis,
218
                    'page_no' => $page_no,
219
                    'page_count' => $page_count,
220
                    'has_errors' => true,
221
                ];
222
            }
223
        } else {
224 3
            if (null !== $page_no || $request->get('resume')) {
225
                /*
226
                 * ページ送りの場合または、他画面から戻ってきた場合は, セッションから検索条件を復旧する.
227
                 */
228 1
                if ($page_no) {
229
                    // ページ送りで遷移した場合.
230 1
                    $this->session->set('eccube.admin.order.search.page_no', (int) $page_no);
231
                } else {
232
                    // 他画面から遷移した場合.
233
                    $page_no = $this->session->get('eccube.admin.order.search.page_no', 1);
234
                }
235 1
                $viewData = $this->session->get('eccube.admin.order.search', []);
236 1
                $searchData = FormUtil::submitAndGetData($searchForm, $viewData);
237
            } else {
238
                /**
239
                 * 初期表示の場合.
240
                 */
241 2
                $page_no = 1;
242 2
                $searchData = [];
243
244
                // セッション中の検索条件, ページ番号を初期化.
245 2
                $this->session->set('eccube.admin.order.search', $searchData);
246 2
                $this->session->set('eccube.admin.order.search.page_no', $page_no);
247
            }
248
        }
249
250 9
        $qb = $this->orderRepository->getQueryBuilderBySearchDataForAdmin($searchData);
251
252 9
        $event = new EventArgs(
253
            [
254 9
                'qb' => $qb,
255 9
                'searchData' => $searchData,
256
            ],
257 9
            $request
258
        );
259
260 9
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_SEARCH, $event);
261
262 9
        $pagination = $paginator->paginate(
263 9
            $qb,
264 9
            $page_no,
265 9
            $page_count
266
        );
267
268
        return [
269 9
            'searchForm' => $searchForm->createView(),
270 9
            'pagination' => $pagination,
271 9
            'pageMaxis' => $pageMaxis,
272 9
            'page_no' => $page_no,
273 9
            'page_count' => $page_count,
274
            'has_errors' => false,
275 9
            'OrderStatuses' => $this->orderStatusRepository->findBy([], ['sort_no' => 'ASC']),
276
        ];
277
    }
278
279
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$request" missing
Loading history...
280
     * @Method("POST")
281
     * @Route("/%eccube_admin_route%/order/bulk_delete", name="admin_order_bulk_delete")
282
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
283 1
    public function bulkDelete(Request $request)
284
    {
285 1
        $this->isTokenValid();
286 1
        $ids = $request->get('ids');
287 1
        foreach ($ids as $order_id) {
288 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...
289 1
                ->find($order_id);
290 1
            if ($Order) {
291 1
                $this->entityManager->remove($Order);
292 1
                log_info('受注削除', [$Order->getId()]);
293
            }
294
        }
295
296 1
        $this->entityManager->flush();
297
298 1
        $this->addSuccess('admin.order.delete.complete', 'admin');
299
300 1
        return $this->redirect($this->generateUrl('admin_order', ['resume' => Constant::ENABLED]));
301
    }
302
303
    /**
304
     * 受注CSVの出力.
305
     *
306
     * @Route("/%eccube_admin_route%/order/export/order", name="admin_order_export_order")
307
     *
308
     * @param Request $request
309
     *
310
     * @return StreamedResponse
311
     */
312 1
    public function exportOrder(Request $request)
313
    {
314
        // タイムアウトを無効にする.
315 1
        set_time_limit(0);
316
317
        // sql loggerを無効にする.
318 1
        $em = $this->entityManager;
319 1
        $em->getConfiguration()->setSQLLogger(null);
320
321 1
        $response = new StreamedResponse();
322 1
        $response->setCallback(function () use ($request) {
323
            // CSV種別を元に初期化.
324 1
            $this->csvExportService->initCsvType(CsvType::CSV_TYPE_ORDER);
325
326
            // ヘッダ行の出力.
327 1
            $this->csvExportService->exportHeader();
328
329
            // 受注データ検索用のクエリビルダを取得.
330 1
            $qb = $this->csvExportService
331 1
                ->getOrderQueryBuilder($request);
332
333
            // データ行の出力.
334 1
            $this->csvExportService->setExportQueryBuilder($qb);
335 1 View Code Duplication
            $this->csvExportService->exportData(function ($entity, $csvService) use ($request) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
336 1
                $Csvs = $csvService->getCsvs();
337
338 1
                $Order = $entity;
339 1
                $OrderItems = $Order->getOrderItems();
340
341 1
                foreach ($OrderItems as $OrderItem) {
342 1
                    $ExportCsvRow = new \Eccube\Entity\ExportCsvRow();
343
344
                    // CSV出力項目と合致するデータを取得.
345 1
                    foreach ($Csvs as $Csv) {
346
                        // 受注データを検索.
347 1
                        $ExportCsvRow->setData($csvService->getData($Csv, $Order));
348 1
                        if ($ExportCsvRow->isDataNull()) {
349
                            // 受注データにない場合は, 受注明細を検索.
350 1
                            $ExportCsvRow->setData($csvService->getData($Csv, $OrderItem));
351
                        }
352
353 1
                        $event = new EventArgs(
354
                            [
355 1
                                'csvService' => $csvService,
356 1
                                'Csv' => $Csv,
357 1
                                'OrderItem' => $OrderItem,
358 1
                                'ExportCsvRow' => $ExportCsvRow,
359
                            ],
360 1
                            $request
361
                        );
362 1
                        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_CSV_EXPORT_ORDER, $event);
363
364 1
                        $ExportCsvRow->pushData();
365
                    }
366
367
                    //$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...
368
                    // 出力.
369 1
                    $csvService->fputcsv($ExportCsvRow->getRow());
370
                }
371 1
            });
372 1
        });
373
374 1
        $now = new \DateTime();
375 1
        $filename = 'order_'.$now->format('YmdHis').'.csv';
376 1
        $response->headers->set('Content-Type', 'application/octet-stream');
377 1
        $response->headers->set('Content-Disposition', 'attachment; filename='.$filename);
378 1
        $response->send();
379
380 1
        log_info('受注CSV出力ファイル名', [$filename]);
381
382 1
        return $response;
383
    }
384
385
    /**
386
     * 配送CSVの出力.
387
     *
388
     * @Route("/%eccube_admin_route%/order/export/shipping", name="admin_order_export_shipping")
389
     *
390
     * @param Request $request
391
     *
392
     * @return StreamedResponse
393
     */
394 1
    public function exportShipping(Request $request)
395
    {
396
        // タイムアウトを無効にする.
397 1
        set_time_limit(0);
398
399
        // sql loggerを無効にする.
400 1
        $em = $this->entityManager;
401 1
        $em->getConfiguration()->setSQLLogger(null);
402
403 1
        $response = new StreamedResponse();
404 1
        $response->setCallback(function () use ($request) {
405
            // CSV種別を元に初期化.
406 1
            $this->csvExportService->initCsvType(CsvType::CSV_TYPE_SHIPPING);
407
408
            // ヘッダ行の出力.
409 1
            $this->csvExportService->exportHeader();
410
411
            // 受注データ検索用のクエリビルダを取得.
412 1
            $qb = $this->csvExportService
413 1
                ->getShippingQueryBuilder($request);
414
415
            // データ行の出力.
416 1
            $this->csvExportService->setExportQueryBuilder($qb);
417 1
            $this->csvExportService->exportData(function ($entity, $csvService) use ($request) {
418
                /** @var Csv[] $Csvs */
419 1
                $Csvs = $csvService->getCsvs();
420
421
                /** @var Shipping $Shipping */
422 1
                $Shipping = $entity;
423
                /** @var OrderItem[] $OrderItems */
424 1
                $OrderItems = $Shipping->getOrderItems();
425
426 1
                foreach ($OrderItems as $OrderItem) {
427 1
                    $ExportCsvRow = new \Eccube\Entity\ExportCsvRow();
428
429 1
                    $Order = $OrderItem->getOrder();
430
                    // CSV出力項目と合致するデータを取得.
431 1
                    foreach ($Csvs as $Csv) {
432
                        // 受注データを検索.
433 1
                        $ExportCsvRow->setData($csvService->getData($Csv, $Order));
434
435 1
                        if ($ExportCsvRow->isDataNull()) {
436
                            // 受注データにない場合は, 出荷データを検索.
437 1
                            $ExportCsvRow->setData($csvService->getData($Csv, $Shipping));
438
                        }
439 1
                        if ($ExportCsvRow->isDataNull()) {
440
                            // 出荷データにない場合は, 出荷明細を検索.
441 1
                            $ExportCsvRow->setData($csvService->getData($Csv, $OrderItem));
442
                        }
443
444 1
                        $event = new EventArgs(
445
                            [
446 1
                                'csvService' => $csvService,
447 1
                                'Csv' => $Csv,
448 1
                                'OrderItem' => $OrderItem,
449 1
                                'ExportCsvRow' => $ExportCsvRow,
450
                            ],
451 1
                            $request
452
                        );
453 1
                        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_CSV_EXPORT_SHIPPING, $event);
454
455 1
                        $ExportCsvRow->pushData();
456
                    }
457
                    //$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...
458
                    // 出力.
459 1
                    $csvService->fputcsv($ExportCsvRow->getRow());
460
                }
461 1
            });
462 1
        });
463
464 1
        $now = new \DateTime();
465 1
        $filename = 'shipping_'.$now->format('YmdHis').'.csv';
466 1
        $response->headers->set('Content-Type', 'application/octet-stream');
467 1
        $response->headers->set('Content-Disposition', 'attachment; filename='.$filename);
468 1
        $response->send();
469
470 1
        log_info('出荷CSV出力ファイル名', [$filename]);
471
472 1
        return $response;
473
    }
474
475
    /**
476
     * Bulk action to order status
477
     *
478
     * @Method("POST")
479
     * @Route("/%eccube_admin_route%/order/bulk/order-status/{id}", requirements={"id" = "\d+"}, name="admin_order_bulk_order_status")
480
     *
481
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
482
     * @param OrderStatus $OrderStatus
483
     *
484
     * @return RedirectResponse
485
     */
486 2
    public function bulkOrderStatus(Request $request, OrderStatus $OrderStatus)
487
    {
488 2
        $this->isTokenValid();
489
490
        /** @var Order[] $Orders */
491 2
        $Orders = $this->orderRepository->findBy(['id' => $request->get('ids')]);
492
493 2
        $count = 0;
494 2
        foreach ($Orders as $Order) {
495
            try {
496
                // TODO: should support event for plugin customize
497
                // 編集前の受注情報を保持
498 2
                $OriginOrder = clone $Order;
499
500 2
                $Order->setOrderStatus($OrderStatus);
501
502 2
                $purchaseContext = new PurchaseContext($OriginOrder, $OriginOrder->getCustomer());
503
504 2
                $flowResult = $this->purchaseFlow->calculate($Order, $purchaseContext);
505 2
                if ($flowResult->hasWarning()) {
506
                    foreach ($flowResult->getWarning() as $warning) {
507
                        $msg = $this->translator->trans('admin.order.index.bulk_warning', [
508
                          '%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...
509
                          '%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...
510
                        ]);
511
                        $this->addWarning($msg, 'admin');
512
                    }
513
                }
514
515 2
                if ($flowResult->hasError()) {
516
                    foreach ($flowResult->getErrors() as $error) {
517
                        $msg = $this->translator->trans('admin.order.index.bulk_error', [
518
                          '%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...
519
                          '%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...
520
                        ]);
521
                        $this->addError($msg, 'admin');
522
                    }
523
                    continue;
524
                }
525
526
                try {
527 2
                    $this->purchaseFlow->purchase($Order, $purchaseContext);
528
                } catch (PurchaseException $e) {
529
                    $msg = $this->translator->trans('admin.order.index.bulk_error', [
530
                      '%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...
531
                      '%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...
532
                    ]);
533
                    $this->addError($msg, 'admin');
534
                    continue;
535
                }
536
537 2
                $this->orderRepository->save($Order);
538
539 2
                $count++;
540
            } catch (\Exception $e) {
541 2
                $this->addError('#'.$Order->getId().': '.$e->getMessage(), 'admin');
542
            }
543
        }
544
        try {
545 2 View Code Duplication
            if ($count) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
546 2
                $this->entityManager->flush();
547 2
                $msg = $this->translator->trans('admin.order.index.bulk_order_status_success_count', [
548 2
                    '%count%' => $count,
549 2
                    '%status%' => $OrderStatus->getName(),
550
                ]);
551 2
                $this->addSuccess($msg, 'admin');
552
            }
553
        } catch (\Exception $e) {
554
            log_error('Bulk order status error', [$e]);
555
            $this->addError('admin.flash.register_failed', 'admin');
556
        }
557
558 2
        return $this->redirectToRoute('admin_order', ['resume' => Constant::ENABLED]);
559
    }
560
}
561