Failed Conditions
Pull Request — experimental/3.1 (#2529)
by Kentaro
34:12
created

EditController::index()   D

Complexity

Conditions 16
Paths 221

Size

Total Lines 183
Code Lines 106

Duplication

Lines 6
Ratio 3.28 %

Code Coverage

Tests 0
CRAP Score 272

Importance

Changes 0
Metric Value
cc 16
eloc 106
nc 221
nop 3
dl 6
loc 183
ccs 0
cts 97
cp 0
crap 272
rs 4.207
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 Doctrine\Common\Collections\ArrayCollection;
27
use Doctrine\ORM\EntityManager;
28
use Eccube\Annotation\Component;
29
use Eccube\Annotation\Inject;
30
use Eccube\Application;
31
use Eccube\Controller\AbstractController;
32
use Eccube\Entity\Master\CustomerStatus;
33
use Eccube\Entity\Master\DeviceType;
34
use Eccube\Event\EccubeEvents;
35
use Eccube\Event\EventArgs;
36
use Eccube\Form\Type\AddCartType;
37
use Eccube\Form\Type\Admin\OrderType;
38
use Eccube\Form\Type\Admin\SearchCustomerType;
39
use Eccube\Form\Type\Admin\SearchProductType;
40
use Eccube\Repository\CategoryRepository;
41
use Eccube\Repository\CustomerRepository;
42
use Eccube\Repository\DeliveryRepository;
43
use Eccube\Repository\Master\DeviceTypeRepository;
44
use Eccube\Repository\OrderRepository;
45
use Eccube\Repository\ProductRepository;
46
use Eccube\Service\PurchaseFlow\PurchaseException;
47
use Eccube\Service\PurchaseFlow\PurchaseFlow;
48
use Eccube\Service\TaxRuleService;
49
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
50
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
51
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
52
use Symfony\Bridge\Monolog\Logger;
53
use Symfony\Component\EventDispatcher\EventDispatcher;
54
use Symfony\Component\Form\FormFactory;
55
use Symfony\Component\HttpFoundation\Request;
56
use Symfony\Component\HttpFoundation\Session\Session;
57
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
58
use Symfony\Component\Serializer\Serializer;
59
60
/**
61
 * @Component
62
 * @Route(service=EditController::class)
63
 */
64
class EditController extends AbstractController
65
{
66
    /**
67
     * @Inject(TaxRuleService::class)
68
     * @var TaxRuleService
69
     */
70
    protected $taxRuleService;
71
72
    /**
73
     * @Inject(DeviceTypeRepository::class)
74
     * @var DeviceTypeRepository
75
     */
76
    protected $deviceTypeRepository;
77
78
    /**
79
     * @Inject(ProductRepository::class)
80
     * @var ProductRepository
81
     */
82
    protected $productRepository;
83
84
    /**
85
     * @Inject(CategoryRepository::class)
86
     * @var CategoryRepository
87
     */
88
    protected $categoryRepository;
89
90
    /**
91
     * @Inject("session")
92
     * @var Session
93
     */
94
    protected $session;
95
96
    /**
97
     * @Inject("config")
98
     * @var array
99
     */
100
    protected $appConfig;
101
102
    /**
103
     * @Inject(CustomerRepository::class)
104
     * @var CustomerRepository
105
     */
106
    protected $customerRepository;
107
108
    /**
109
     * @Inject("monolog")
110
     * @var Logger
111
     */
112
    protected $logger;
113
114
    /**
115
     * @Inject("serializer")
116
     * @var Serializer
117
     */
118
    protected $serializer;
119
120
    /**
121
     * @Inject(DeliveryRepository::class)
122
     * @var DeliveryRepository
123
     */
124
    protected $deliveryRepository;
125
126
    /**
127
     * @Inject("eccube.purchase.flow.order")
128
     * @var PurchaseFlow
129
     */
130
    protected $purchaseFlow;
131
132
    /**
133
     * @Inject("eccube.event.dispatcher")
134
     * @var EventDispatcher
135
     */
136
    protected $eventDispatcher;
137
138
    /**
139
     * @Inject("form.factory")
140
     * @var FormFactory
141
     */
142
    protected $formFactory;
143
144
    /**
145
     * @Inject(OrderRepository::class)
146
     * @var OrderRepository
147
     */
148
    protected $orderRepository;
149
150
    /**
151
     * @Inject("orm.em")
152
     * @var EntityManager
153
     */
154
    protected $entityManager;
155
156
157
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
158
     * 受注登録/編集画面.
159
     *
160
     * @Route("/{_admin}/order/edit", name="admin_order_new")
161
     * @Route("/{_admin}/order/{id}/edit", requirements={"id" = "\d+"}, name="admin_order_edit")
162
     * @Template("Order/edit.twig")
163
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
164
    public function index(Application $app, Request $request, $id = null)
165
    {
166
        $TargetOrder = null;
0 ignored issues
show
Unused Code introduced by
$TargetOrder is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
167
        $OriginOrder = null;
0 ignored issues
show
Unused Code introduced by
$OriginOrder is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
168
169
        if (is_null($id)) {
170
            // 空のエンティティを作成.
171
            $TargetOrder = $this->newOrder($app);
172
        } else {
173
            $TargetOrder = $this->orderRepository->find($id);
174
            if (is_null($TargetOrder)) {
175
                throw new NotFoundHttpException();
176
            }
177
        }
178
179
        // 編集前の受注情報を保持
180
        $OriginOrder = clone $TargetOrder;
181
        $OriginalOrderItems = new ArrayCollection();
182
183
        // 編集前の情報を保持
184
        foreach ($TargetOrder->getOrderItems() as $tmpOrderItem) {
185
            $OriginalOrderItems->add($tmpOrderItem);
186
        }
187
188
        $builder = $this->formFactory
189
            ->createBuilder(OrderType::class, $TargetOrder,
190
                            [
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
191
                                'SortedItems' => $TargetOrder->getItems()
192
                            ]
193
            );
194
195
        $event = new EventArgs(
196
            array(
197
                'builder' => $builder,
198
                'OriginOrder' => $OriginOrder,
199
                'TargetOrder' => $TargetOrder,
200
            ),
201
            $request
202
        );
203
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_INITIALIZE, $event);
204
205
        $form = $builder->getForm();
206
        $form->handleRequest($request);
207
        $purchaseContext = $app['eccube.purchase.context']($OriginOrder);
208
209
        if ($form->isSubmitted()) {
210
            $event = new EventArgs(
211
                array(
212
                    'builder' => $builder,
213
                    'OriginOrder' => $OriginOrder,
214
                    'TargetOrder' => $TargetOrder,
215
                    'PurchaseContext' => $purchaseContext,
216
                ),
217
                $request
218
            );
219
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event);
220
221
222
            $flowResult = $this->purchaseFlow->calculate($TargetOrder, $purchaseContext);
223
            if ($flowResult->hasWarning()) {
224
                foreach ($flowResult->getWarning() as $warning) {
225
                    // TODO Warning の場合の処理
226
                    $app->addWarning($warning->getMessage(), 'admin');
227
                }
228
            }
229
            if ($flowResult->hasError()) {
230
                foreach ($flowResult->getErrors() as $error) {
231
                    $app->addError($error->getMessage(), 'admin');
232
                }
233
            }
234
235
            // 登録ボタン押下
236
            switch ($request->get('mode')) {
237
                case 'register':
238
                    log_info('受注登録開始', array($TargetOrder->getId()));
239
240
                    if ($flowResult->hasError() === false && $form->isValid()) {
241
                        try {
242
                            $this->purchaseFlow->purchase($TargetOrder, $purchaseContext);
243
                        } catch (PurchaseException $e) {
244
                            $app->addError($e->getMessage(), 'admin');
245
                            break;
246
                        }
247
248
                        $this->entityManager->persist($TargetOrder);
249
                        $this->entityManager->flush();
250
251
                        // TODO 集計系に移動
252
//                        if ($Customer) {
253
//                            // 会員の場合、購入回数、購入金額などを更新
254
//                            $app['eccube.repository.customer']->updateBuyData($app, $Customer, $TargetOrder->getOrderStatus()->getId());
255
//                        }
256
257
                        $event = new EventArgs(
258
                            array(
259
                                'form' => $form,
260
                                'OriginOrder' => $OriginOrder,
261
                                'TargetOrder' => $TargetOrder,
262
                                //'Customer' => $Customer,
263
                            ),
264
                            $request
265
                        );
266
                        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_COMPLETE, $event);
267
268
                        $app->addSuccess('admin.order.save.complete', 'admin');
269
270
                        log_info('受注登録完了', array($TargetOrder->getId()));
271
272
                        return $app->redirect($app->url('admin_order_edit', array('id' => $TargetOrder->getId())));
273
                    }
274
275
                    break;
276
277
                case 'add_delivery':
278
                    // お届け先情報の新規追加
279
280
                    $form = $builder->getForm();
281
282
                    $Shipping = new \Eccube\Entity\Shipping();
283
                    $TargetOrder->addShipping($Shipping);
284
285
                    $Shipping->setOrder($TargetOrder);
286
287
                    $form->setData($TargetOrder);
288
289
                    break;
290
291
                default:
292
                    break;
293
            }
294
        }
295
296
        // 会員検索フォーム
297
        $builder = $this->formFactory
298
            ->createBuilder(SearchCustomerType::class);
299
300
        $event = new EventArgs(
301
            array(
302
                'builder' => $builder,
303
                'OriginOrder' => $OriginOrder,
304
                'TargetOrder' => $TargetOrder,
305
            ),
306
            $request
307
        );
308
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_INITIALIZE, $event);
309
310
        $searchCustomerModalForm = $builder->getForm();
311
312
        // 商品検索フォーム
313
        $builder = $this->formFactory
314
            ->createBuilder(SearchProductType::class);
315
316
        $event = new EventArgs(
317
            array(
318
                'builder' => $builder,
319
                'OriginOrder' => $OriginOrder,
320
                'TargetOrder' => $TargetOrder,
321
            ),
322
            $request
323
        );
324
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_INITIALIZE, $event);
325
326
        $searchProductModalForm = $builder->getForm();
327
328
        // 配送業者のお届け時間
329
        $times = array();
330
        $deliveries = $this->deliveryRepository->findAll();
331 View Code Duplication
        foreach ($deliveries as $Delivery) {
332
            $deliveryTiems = $Delivery->getDeliveryTimes();
333
            foreach ($deliveryTiems as $DeliveryTime) {
334
                $times[$Delivery->getId()][$DeliveryTime->getId()] = $DeliveryTime->getDeliveryTime();
335
            }
336
        }
337
338
        return [
339
            'form' => $form->createView(),
340
            'searchCustomerModalForm' => $searchCustomerModalForm->createView(),
341
            'searchProductModalForm' => $searchProductModalForm->createView(),
342
            'Order' => $TargetOrder,
343
            'id' => $id,
344
            'shippingDeliveryTimes' => $this->serializer->serialize($times, 'json'),
345
        ];
346
    }
347
348
    /**
349
     * 顧客情報を検索する.
350
     *
351
     * @Route("/{_admin}/order/search/customer", name="admin_order_search_customer")
352
     *
353
     * @param Application $app
354
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
355
     * @return \Symfony\Component\HttpFoundation\JsonResponse
356
     */
357 4
    public function searchCustomer(Application $app, Request $request)
358
    {
359 4
        if ($request->isXmlHttpRequest()) {
360 4
            $this->logger->addDebug('search customer start.');
361
362
            $searchData = array(
363 4
                'multi' => $request->get('search_word'),
364
            );
365
366 4
            $qb = $this->customerRepository->getQueryBuilderBySearchData($searchData);
367
368 4
            $event = new EventArgs(
369
                array(
370 4
                    'qb' => $qb,
371 4
                    'data' => $searchData,
372
                ),
373 4
                $request
374
            );
375 4
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event);
376
377 4
            $Customers = $qb->getQuery()->getResult();
378
379
380 4
            if (empty($Customers)) {
381
                $this->logger->addDebug('search customer not found.');
382
            }
383
384 4
            $data = array();
385
386 4
            $formatTel = '%s-%s-%s';
387 4
            $formatName = '%s%s(%s%s)';
388 4 View Code Duplication
            foreach ($Customers as $Customer) {
389 4
                $data[] = array(
390 4
                    'id' => $Customer->getId(),
391 4
                    'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(), $Customer->getKana01(),
392 4
                        $Customer->getKana02()),
393 4
                    'tel' => sprintf($formatTel, $Customer->getTel01(), $Customer->getTel02(), $Customer->getTel03()),
394 4
                    'email' => $Customer->getEmail(),
395
                );
396
            }
397
398 4
            $event = new EventArgs(
399
                array(
400 4
                    'data' => $data,
401 4
                    'Customers' => $Customers,
402
                ),
403 4
                $request
404
            );
405 4
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event);
406 4
            $data = $event->getArgument('data');
407
408 4
            return $app->json($data);
409
        }
410
    }
411
412
    /**
413
     * 顧客情報を検索する.
414
     *
415
     * @Route("/{_admin}/order/search/customer/html", name="admin_order_search_customer_html")
416
     * @Route("/{_admin}/order/search/customer/html/page/{page_no}", requirements={"page_No" = "\d+"}, name="admin_order_search_customer_html_page")
417
     * @Template("Order/search_customer.twig")
418
     *
419
     * @param Application $app
420
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
421
     * @param integer $page_no
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
422
     * @return \Symfony\Component\HttpFoundation\JsonResponse
423
     */
424
    public function searchCustomerHtml(Application $app, Request $request, $page_no = null)
425
    {
426
        if ($request->isXmlHttpRequest()) {
427
            $this->logger->addDebug('search customer start.');
428
            $page_count = $this->appConfig['default_page_count'];
429
            $session = $this->session;
430
431
            if ('POST' === $request->getMethod()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
432
433
                $page_no = 1;
434
435
                $searchData = array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
436
                    'multi' => $request->get('search_word'),
437
                    'customer_status' => [
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
438
                        CustomerStatus::REGULAR
439
                    ]
440
                );
441
442
                $session->set('eccube.admin.order.customer.search', $searchData);
443
                $session->set('eccube.admin.order.customer.search.page_no', $page_no);
444
            } else {
445
                $searchData = (array)$session->get('eccube.admin.order.customer.search');
0 ignored issues
show
Coding Style introduced by
As per coding-style, a cast statement should be followed by a single space.
Loading history...
446
                if (is_null($page_no)) {
447
                    $page_no = intval($session->get('eccube.admin.order.customer.search.page_no'));
448
                } else {
449
                    $session->set('eccube.admin.order.customer.search.page_no', $page_no);
450
                }
451
            }
452
453
            $qb = $this->customerRepository->getQueryBuilderBySearchData($searchData);
454
455
            $event = new EventArgs(
456
                array(
457
                    'qb' => $qb,
458
                    'data' => $searchData,
459
                ),
460
                $request
461
            );
462
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event);
463
464
            /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
465
            $pagination = $app['paginator']()->paginate(
466
                $qb,
467
                $page_no,
468
                $page_count,
469
                array('wrap-queries' => true)
470
            );
471
472
            /** @var $Customers \Eccube\Entity\Customer[] */
473
            $Customers = $pagination->getItems();
474
475
            if (empty($Customers)) {
476
                $this->logger->addDebug('search customer not found.');
477
            }
478
479
            $data = array();
480
481
            $formatTel = '%s-%s-%s';
482
            $formatName = '%s%s(%s%s)';
483 View Code Duplication
            foreach ($Customers as $Customer) {
484
                $data[] = array(
485
                    'id' => $Customer->getId(),
486
                    'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(), $Customer->getKana01(),
487
                        $Customer->getKana02()),
488
                    'tel' => sprintf($formatTel, $Customer->getTel01(), $Customer->getTel02(), $Customer->getTel03()),
489
                    'email' => $Customer->getEmail(),
490
                );
491
            }
492
493
            $event = new EventArgs(
494
                array(
495
                    'data' => $data,
496
                    'Customers' => $pagination,
497
                ),
498
                $request
499
            );
500
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event);
501
            $data = $event->getArgument('data');
502
503
            return [
504
                'data' => $data,
505
                'pagination' => $pagination,
506
            ];
507
        }
508
    }
509
510
    /**
511
     * 顧客情報を検索する.
512
     *
513
     * @Method("POST")
514
     * @Route("/{_admin}/order/search/customer/id", name="admin_order_search_customer_by_id")
515
     *
516
     * @param Application $app
517
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
518
     * @return \Symfony\Component\HttpFoundation\JsonResponse
519
     */
520 2
    public function searchCustomerById(Application $app, Request $request)
521
    {
522 2
        if ($request->isXmlHttpRequest()) {
523 2
            $this->logger->addDebug('search customer by id start.');
524
525
            /** @var $Customer \Eccube\Entity\Customer */
526 2
            $Customer = $this->customerRepository
527 2
                ->find($request->get('id'));
528
529 2
            $event = new EventArgs(
530
                array(
531 2
                    'Customer' => $Customer,
532
                ),
533 2
                $request
534
            );
535 2
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_INITIALIZE, $event);
536
537 2
            if (is_null($Customer)) {
538
                $this->logger->addDebug('search customer by id not found.');
539
540
                return $app->json(array(), 404);
541
            }
542
543 2
            $this->logger->addDebug('search customer by id found.');
544
545
            $data = array(
546 2
                'id' => $Customer->getId(),
547 2
                'name01' => $Customer->getName01(),
548 2
                'name02' => $Customer->getName02(),
549 2
                'kana01' => $Customer->getKana01(),
550 2
                'kana02' => $Customer->getKana02(),
551 2
                'zip01' => $Customer->getZip01(),
552 2
                'zip02' => $Customer->getZip02(),
553 2
                'pref' => is_null($Customer->getPref()) ? null : $Customer->getPref()->getId(),
554 2
                'addr01' => $Customer->getAddr01(),
555 2
                'addr02' => $Customer->getAddr02(),
556 2
                'email' => $Customer->getEmail(),
557 2
                'tel01' => $Customer->getTel01(),
558 2
                'tel02' => $Customer->getTel02(),
559 2
                'tel03' => $Customer->getTel03(),
560 2
                'fax01' => $Customer->getFax01(),
561 2
                'fax02' => $Customer->getFax02(),
562 2
                'fax03' => $Customer->getFax03(),
563 2
                'company_name' => $Customer->getCompanyName(),
564
            );
565
566 2
            $event = new EventArgs(
567
                array(
568 2
                    'data' => $data,
569 2
                    'Customer' => $Customer,
570
                ),
571 2
                $request
572
            );
573 2
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_COMPLETE, $event);
574 2
            $data = $event->getArgument('data');
575
576 2
            return $app->json($data);
577
        }
578
    }
579
580
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$page_no" missing
Loading history...
581
     * @Route("/{_admin}/order/search/product", name="admin_order_search_product")
582
     * @Route("/{_admin}/order/search/product/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_order_search_product_page")
583
     * @Template("Order/search_product.twig")
584
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
585 2
    public function searchProduct(Application $app, Request $request, $page_no = null)
586
    {
587 2
        if ($request->isXmlHttpRequest()) {
588 2
            $this->logger->addDebug('search product start.');
589 2
            $page_count = $this->appConfig['default_page_count'];
590 2
            $session = $this->session;
591
592 2 View Code Duplication
            if ('POST' === $request->getMethod()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
593
594 2
                $page_no = 1;
595
596
                $searchData = array(
597 2
                    'id' => $request->get('id'),
598
                );
599
600 2
                if ($categoryId = $request->get('category_id')) {
601
                    $Category = $this->categoryRepository->find($categoryId);
602
                    $searchData['category_id'] = $Category;
603
                }
604
605 2
                $session->set('eccube.admin.order.product.search', $searchData);
606 2
                $session->set('eccube.admin.order.product.search.page_no', $page_no);
607
            } else {
608
                $searchData = (array)$session->get('eccube.admin.order.product.search');
0 ignored issues
show
Coding Style introduced by
As per coding-style, a cast statement should be followed by a single space.
Loading history...
609
                if (is_null($page_no)) {
610
                    $page_no = intval($session->get('eccube.admin.order.product.search.page_no'));
611
                } else {
612
                    $session->set('eccube.admin.order.product.search.page_no', $page_no);
613
                }
614
            }
615
616 2
            $qb = $this->productRepository
617 2
                ->getQueryBuilderBySearchDataForAdmin($searchData);
618
619 2
            $event = new EventArgs(
620
                array(
621 2
                    'qb' => $qb,
622 2
                    'searchData' => $searchData,
623
                ),
624 2
                $request
625
            );
626 2
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH, $event);
627
628
            /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
629 2
            $pagination = $app['paginator']()->paginate(
630 2
                $qb,
631 2
                $page_no,
632 2
                $page_count,
633 2
                array('wrap-queries' => true)
634
            );
635
636
            /** @var $Products \Eccube\Entity\Product[] */
637 2
            $Products = $pagination->getItems();
638
639 2
            if (empty($Products)) {
640
                $this->logger->addDebug('search product not found.');
641
            }
642
643 2
            $forms = array();
644 2 View Code Duplication
            foreach ($Products as $Product) {
645
                /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
646 2
                $builder = $this->formFactory->createNamedBuilder('', AddCartType::class, null, array(
647 2
                    'product' => $Product,
648
                ));
649 2
                $addCartForm = $builder->getForm();
650 2
                $forms[$Product->getId()] = $addCartForm->createView();
651
            }
652
653 2
            $event = new EventArgs(
654
                array(
655 2
                    'forms' => $forms,
656 2
                    'Products' => $Products,
657 2
                    'pagination' => $pagination,
658
                ),
659 2
                $request
660
            );
661 2
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE, $event);
662
663
            return [
664 2
                'forms' => $forms,
665 2
                'Products' => $Products,
666 2
                'pagination' => $pagination,
667
            ];
668
        }
669
    }
670
671
    protected function newOrder(Application $app)
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
672
    {
673
        $Order = new \Eccube\Entity\Order();
674
        // device type
675
        $DeviceType = $this->deviceTypeRepository->find(DeviceType::DEVICE_TYPE_ADMIN);
676
        $Order->setDeviceType($DeviceType);
677
678
        return $Order;
679
    }
680
681
    /**
682
     * 受注ステータスに応じて, 受注日/入金日/発送日を更新する,
683
     * 発送済ステータスが設定された場合は, お届け先情報の発送日も更新を行う.
684
     *
685
     * 編集の場合
686
     * - 受注ステータスが他のステータスから発送済へ変更された場合に発送日を更新
687
     * - 受注ステータスが他のステータスから入金済へ変更された場合に入金日を更新
688
     *
689
     * 新規登録の場合
690
     * - 受注日を更新
691
     * - 受注ステータスが発送済に設定された場合に発送日を更新
692
     * - 受注ステータスが入金済に設定された場合に入金日を更新
693
     *
694
     * @param $app
695
     * @param $TargetOrder
696
     * @param $OriginOrder
697
     *
698
     * TODO Service へ移動する
699
     */
700
    protected function updateDate($app, $TargetOrder, $OriginOrder)
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
701
    {
702
        $dateTime = new \DateTime();
703
704
        // 編集
705 View Code Duplication
        if ($TargetOrder->getId()) {
706
            // 発送済
707
            if ($TargetOrder->getOrderStatus()->getId() == $this->appConfig['order_deliv']) {
708
                // 編集前と異なる場合のみ更新
709
                if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
710
                    $TargetOrder->setCommitDate($dateTime);
711
                    // お届け先情報の発送日も更新する.
712
                    $Shippings = $TargetOrder->getShippings();
713
                    foreach ($Shippings as $Shipping) {
714
                        $Shipping->setShippingCommitDate($dateTime);
715
                    }
716
                }
717
                // 入金済
718
            } elseif ($TargetOrder->getOrderStatus()->getId() == $this->appConfig['order_pre_end']) {
719
                // 編集前と異なる場合のみ更新
720
                if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
721
                    $TargetOrder->setPaymentDate($dateTime);
722
                }
723
            }
724
            // 新規
725
        } else {
726
            // 発送済
727
            if ($TargetOrder->getOrderStatus()->getId() == $this->appConfig['order_deliv']) {
728
                $TargetOrder->setCommitDate($dateTime);
729
                // お届け先情報の発送日も更新する.
730
                $Shippings = $TargetOrder->getShippings();
731
                foreach ($Shippings as $Shipping) {
732
                    $Shipping->setShippingCommitDate($dateTime);
733
                }
734
                // 入金済
735
            } elseif ($TargetOrder->getOrderStatus()->getId() == $this->appConfig['order_pre_end']) {
736
                $TargetOrder->setPaymentDate($dateTime);
737
            }
738
            // 受注日時
739
            $TargetOrder->setOrderDate($dateTime);
740
        }
741
    }
742
}
743