Failed Conditions
Push — experimental/sf ( 267a6e...28d741 )
by Ryo
1408:20 queued 1400:20
created

EditController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 11
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
ccs 12
cts 12
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 Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Criteria;
18
use Eccube\Controller\AbstractController;
19
use Eccube\Entity\Customer;
20
use Eccube\Entity\Master\CustomerStatus;
21
use Eccube\Entity\Master\DeviceType;
22
use Eccube\Entity\Master\OrderItemType;
23
use Eccube\Entity\Master\OrderStatus;
24
use Eccube\Entity\Order;
25
use Eccube\Entity\Shipping;
26
use Eccube\Event\EccubeEvents;
27
use Eccube\Event\EventArgs;
28
use Eccube\Form\Type\AddCartType;
29
use Eccube\Form\Type\Admin\OrderType;
30
use Eccube\Form\Type\Admin\SearchCustomerType;
31
use Eccube\Form\Type\Admin\SearchProductType;
32
use Eccube\Repository\CategoryRepository;
33
use Eccube\Repository\CustomerRepository;
34
use Eccube\Repository\DeliveryRepository;
35
use Eccube\Repository\Master\DeviceTypeRepository;
36
use Eccube\Repository\Master\OrderItemTypeRepository;
37
use Eccube\Repository\OrderRepository;
38
use Eccube\Repository\ProductRepository;
39
use Eccube\Service\PurchaseFlow\Processor\OrderNoProcessor;
40
use Eccube\Service\PurchaseFlow\PurchaseContext;
41
use Eccube\Service\PurchaseFlow\PurchaseException;
42
use Eccube\Service\PurchaseFlow\PurchaseFlow;
43
use Eccube\Service\TaxRuleService;
44
use Knp\Component\Pager\Paginator;
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\HttpKernel\Exception\NotFoundHttpException;
50
use Symfony\Component\Serializer\Serializer;
51
use Symfony\Component\Serializer\SerializerInterface;
52
53
class EditController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
54
{
55
    /**
56
     * @var TaxRuleService
57
     */
58
    protected $taxRuleService;
59
60
    /**
61
     * @var DeviceTypeRepository
62
     */
63
    protected $deviceTypeRepository;
64
65
    /**
66
     * @var ProductRepository
67
     */
68
    protected $productRepository;
69
70
    /**
71
     * @var CategoryRepository
72
     */
73
    protected $categoryRepository;
74
75
    /**
76
     * @var CustomerRepository
77
     */
78
    protected $customerRepository;
79
80
    /**
81
     * @var Serializer
82
     */
83
    protected $serializer;
84
85
    /**
86
     * @var DeliveryRepository
87
     */
88
    protected $deliveryRepository;
89
90
    /**
91
     * @var PurchaseFlow
92
     */
93
    protected $purchaseFlow;
94
95
    /**
96
     * @var OrderRepository
97
     */
98
    protected $orderRepository;
99
100
    /**
101
     * @var OrderNoProcessor
102
     */
103
    protected $orderNoProcessor;
104
105
    /**
106
     * @var OrderItemTypeRepository
107
     */
108
    protected $orderItemTypeRepository;
109
110
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$orderItemTypeRepository" missing
Loading history...
111
     * EditController constructor.
112
     *
113
     * @param TaxRuleService $taxRuleService
0 ignored issues
show
introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
114
     * @param DeviceTypeRepository $deviceTypeRepository
115
     * @param ProductRepository $productRepository
0 ignored issues
show
introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
116
     * @param CategoryRepository $categoryRepository
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
117
     * @param CustomerRepository $customerRepository
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
118
     * @param SerializerInterface $serializer
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
119
     * @param DeliveryRepository $deliveryRepository
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
120
     * @param PurchaseFlow $orderPurchaseFlow
0 ignored issues
show
introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
121
     * @param OrderRepository $orderRepository
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
122
     * @param OrderNoProcessor $orderNoProcessor
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
123
     */
124 11
    public function __construct(
125
        TaxRuleService $taxRuleService,
126
        DeviceTypeRepository $deviceTypeRepository,
127
        ProductRepository $productRepository,
128
        CategoryRepository $categoryRepository,
129
        CustomerRepository $customerRepository,
130
        SerializerInterface $serializer,
131
        DeliveryRepository $deliveryRepository,
132
        PurchaseFlow $orderPurchaseFlow,
133
        OrderRepository $orderRepository,
134
        OrderNoProcessor $orderNoProcessor,
135
        OrderItemTypeRepository $orderItemTypeRepository
136
    ) {
137 11
        $this->taxRuleService = $taxRuleService;
138 11
        $this->deviceTypeRepository = $deviceTypeRepository;
139 11
        $this->productRepository = $productRepository;
140 11
        $this->categoryRepository = $categoryRepository;
141 11
        $this->customerRepository = $customerRepository;
142 11
        $this->serializer = $serializer;
0 ignored issues
show
Documentation Bug introduced by
$serializer is of type object<Symfony\Component...er\SerializerInterface>, but the property $serializer was declared to be of type object<Symfony\Component\Serializer\Serializer>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
143 11
        $this->deliveryRepository = $deliveryRepository;
144 11
        $this->purchaseFlow = $orderPurchaseFlow;
145 11
        $this->orderRepository = $orderRepository;
146 11
        $this->orderNoProcessor = $orderNoProcessor;
147 11
        $this->orderItemTypeRepository = $orderItemTypeRepository;
148
    }
149
150
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
151
     * 受注登録/編集画面.
152
     *
153
     * @Route("/%eccube_admin_route%/order/new", name="admin_order_new")
154
     * @Route("/%eccube_admin_route%/order/{id}/edit", requirements={"id" = "\d+"}, name="admin_order_edit")
155
     * @Template("@admin/Order/edit.twig")
156
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
157 7
    public function index(Request $request, $id = null)
158
    {
159 7
        $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...
160 7
        $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...
161 7
        $isNewOrder = false;
162
163 7
        if (is_null($id)) {
164
            // 空のエンティティを作成.
165 3
            $TargetOrder = $this->newOrder();
166 3
            $isNewOrder = true;
167
        } else {
168 4
            $TargetOrder = $this->orderRepository->find($id);
169 4
            if (is_null($TargetOrder)) {
170
                throw new NotFoundHttpException();
171
            }
172
        }
173
174
        // 編集前の受注情報を保持
175 7
        $OriginOrder = clone $TargetOrder;
176 7
        $OriginItems = new ArrayCollection();
177 7
        foreach ($TargetOrder->getOrderItems() as $Item) {
178 4
            $OriginItems->add($Item);
179
        }
180
181 7
        $builder = $this->formFactory
182 7
            ->createBuilder(OrderType::class, $TargetOrder,
183
                [
184 7
                    'SortedItems' => $TargetOrder->getItems(),
185
                ]
186
            );
187
188 7
        $event = new EventArgs(
189
            [
190 7
                'builder' => $builder,
191 7
                'OriginOrder' => $OriginOrder,
192 7
                'TargetOrder' => $TargetOrder,
193
            ],
194 7
            $request
195
        );
196 7
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_INITIALIZE, $event);
197
198 7
        $form = $builder->getForm();
199 7
        $form->handleRequest($request);
200 7
        $purchaseContext = new PurchaseContext($OriginOrder, $OriginOrder->getCustomer());
201
202 7
        if ($form->isSubmitted()) {
203 5
            $event = new EventArgs(
204
                [
205 5
                    'builder' => $builder,
206 5
                    'OriginOrder' => $OriginOrder,
207 5
                    'TargetOrder' => $TargetOrder,
208 5
                    'PurchaseContext' => $purchaseContext,
209
                ],
210 5
                $request
211
            );
212 5
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event);
213
214 5
            $flowResult = $this->purchaseFlow->validate($TargetOrder, $purchaseContext);
215 5
            if ($flowResult->hasWarning()) {
216
                foreach ($flowResult->getWarning() as $warning) {
217
                    // TODO Warning の場合の処理
218
                    $this->addWarning($warning->getMessage(), 'admin');
219
                }
220
            }
221
222 5
            if ($flowResult->hasError()) {
223
                foreach ($flowResult->getErrors() as $error) {
224
                    $this->addError($error->getMessage(), 'admin');
225
                }
226
            }
227
228
            // 登録ボタン押下
229 5
            switch ($request->get('mode')) {
230
                case 'register':
231 5
                    log_info('受注登録開始', [$TargetOrder->getId()]);
232
233 5
                    if ($flowResult->hasError() === false && $form->isValid()) {
234
                        try {
235 5
                            $this->purchaseFlow->prepare($TargetOrder, $purchaseContext);
236 5
                            $this->purchaseFlow->commit($TargetOrder, $purchaseContext);
237
                        } catch (PurchaseException $e) {
238
                            $this->addError($e->getMessage(), 'admin');
239
                            break;
240
                        }
241
242 5
                        $this->entityManager->persist($TargetOrder);
243 5
                        $this->entityManager->flush();
244
245 5
                        foreach ($OriginItems as $Item) {
246 3
                            if ($TargetOrder->getOrderItems()->contains($Item) === false) {
247 3
                                $this->entityManager->remove($Item);
248
                            }
249
                        }
250 5
                        $this->entityManager->flush();
251
252
                        // 新規登録時はMySQL対応のためflushしてから採番
253 5
                        $this->orderNoProcessor->process($TargetOrder, $purchaseContext);
254 5
                        $this->entityManager->flush();
255
256 5
                        $Customer = $TargetOrder->getCustomer();
257 5
                        if ($Customer) {
258
                            // 会員の場合、購入回数、購入金額などを更新
259 5
                            $this->customerRepository->updateBuyData($Customer, $isNewOrder);
260
                        }
261
262 5
                        $event = new EventArgs(
263
                            [
264 5
                                'form' => $form,
265 5
                                'OriginOrder' => $OriginOrder,
266 5
                                'TargetOrder' => $TargetOrder,
267 5
                                'Customer' => $Customer,
268
                            ],
269 5
                            $request
270
                        );
271 5
                        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_COMPLETE, $event);
272
273 5
                        $this->addSuccess('admin.order.save.complete', 'admin');
274
275 5
                        log_info('受注登録完了', [$TargetOrder->getId()]);
276
277 5
                        return $this->redirectToRoute('admin_order_edit', ['id' => $TargetOrder->getId()]);
278
                    }
279
280
                    break;
281
282
                case 'add_delivery':
283
                    // お届け先情報の新規追加
284
285
                    $form = $builder->getForm();
286
287
                    $Shipping = new Shipping();
288
                    $TargetOrder->addShipping($Shipping);
289
290
                    $Shipping->setOrder($TargetOrder);
291
292
                    $form->setData($TargetOrder);
293
294
                    break;
295
296
                default:
297
                    break;
298
            }
299
        }
300
301
        // 会員検索フォーム
302 2
        $builder = $this->formFactory
303 2
            ->createBuilder(SearchCustomerType::class);
304
305 2
        $event = new EventArgs(
306
            [
307 2
                'builder' => $builder,
308 2
                'OriginOrder' => $OriginOrder,
309 2
                'TargetOrder' => $TargetOrder,
310
            ],
311 2
            $request
312
        );
313 2
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_INITIALIZE, $event);
314
315 2
        $searchCustomerModalForm = $builder->getForm();
316
317
        // 商品検索フォーム
318 2
        $builder = $this->formFactory
319 2
            ->createBuilder(SearchProductType::class);
320
321 2
        $event = new EventArgs(
322
            [
323 2
                'builder' => $builder,
324 2
                'OriginOrder' => $OriginOrder,
325 2
                'TargetOrder' => $TargetOrder,
326
            ],
327 2
            $request
328
        );
329 2
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_INITIALIZE, $event);
330
331 2
        $searchProductModalForm = $builder->getForm();
332
333
        // 配送業者のお届け時間
334 2
        $times = [];
335 2
        $deliveries = $this->deliveryRepository->findAll();
336 2 View Code Duplication
        foreach ($deliveries as $Delivery) {
337 2
            $deliveryTiems = $Delivery->getDeliveryTimes();
338 2
            foreach ($deliveryTiems as $DeliveryTime) {
339 2
                $times[$Delivery->getId()][$DeliveryTime->getId()] = $DeliveryTime->getDeliveryTime();
340
            }
341
        }
342
343
        return [
344 2
            'form' => $form->createView(),
345 2
            'searchCustomerModalForm' => $searchCustomerModalForm->createView(),
346 2
            'searchProductModalForm' => $searchProductModalForm->createView(),
347 2
            'Order' => $TargetOrder,
348 2
            'id' => $id,
349 2
            'shippingDeliveryTimes' => $this->serializer->serialize($times, 'json'),
350
        ];
351
    }
352
353
    /**
354
     * 顧客情報を検索する.
355
     *
356
     * @Route("/%eccube_admin_route%/order/search/customer", name="admin_order_search_customer")
357
     *
358
     * @param Request $request
359
     *
360
     * @return \Symfony\Component\HttpFoundation\JsonResponse
361
     */
362 2
    public function searchCustomer(Request $request)
363
    {
364 2
        if ($request->isXmlHttpRequest()) {
365 2
            log_debug('search customer start.');
366
367
            $searchData = [
368 2
                'multi' => $request->get('search_word'),
369
            ];
370
371 2
            $qb = $this->customerRepository->getQueryBuilderBySearchData($searchData);
372
373 2
            $event = new EventArgs(
374
                [
375 2
                    'qb' => $qb,
376 2
                    'data' => $searchData,
377
                ],
378 2
                $request
379
            );
380 2
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event);
381
382
            /** @var Customer[] $Customers */
383 2
            $Customers = $qb->getQuery()->getResult();
384
385 2
            if (empty($Customers)) {
386
                log_debug('search customer not found.');
387
            }
388
389 2
            $data = [];
390 2
            $formatName = '%s%s(%s%s)';
391 2 View Code Duplication
            foreach ($Customers as $Customer) {
392 2
                $data[] = [
393 2
                    'id' => $Customer->getId(),
394 2
                    'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(),
395 2
                        $Customer->getKana01(),
396 2
                        $Customer->getKana02()),
397 2
                    'phone_number' => $Customer->getPhoneNumber(),
398 2
                    'email' => $Customer->getEmail(),
399
                ];
400
            }
401
402 2
            $event = new EventArgs(
403
                [
404 2
                    'data' => $data,
405 2
                    'Customers' => $Customers,
406
                ],
407 2
                $request
408
            );
409 2
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event);
410 2
            $data = $event->getArgument('data');
411
412 2
            return $this->json($data);
413
        }
414
    }
415
416
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$paginator" missing
Loading history...
417
     * 顧客情報を検索する.
418
     *
419
     * @Route("/%eccube_admin_route%/order/search/customer/html", name="admin_order_search_customer_html")
420
     * @Route("/%eccube_admin_route%/order/search/customer/html/page/{page_no}", requirements={"page_No" = "\d+"}, name="admin_order_search_customer_html_page")
421
     * @Template("@admin/Order/search_customer.twig")
422
     *
423
     * @param Request $request
424
     * @param integer $page_no
425
     *
426
     * @return \Symfony\Component\HttpFoundation\JsonResponse
427
     */
428
    public function searchCustomerHtml(Request $request, $page_no = null, Paginator $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...
429
    {
430
        if ($request->isXmlHttpRequest()) {
431
            log_debug('search customer start.');
432
            $page_count = $this->eccubeConfig['eccube_default_page_count'];
433
            $session = $this->session;
434
435
            if ('POST' === $request->getMethod()) {
436
                $page_no = 1;
437
438
                $searchData = [
439
                    'multi' => $request->get('search_word'),
440
                    'customer_status' => [
441
                        CustomerStatus::REGULAR,
442
                    ],
443
                ];
444
445
                $session->set('eccube.admin.order.customer.search', $searchData);
446
                $session->set('eccube.admin.order.customer.search.page_no', $page_no);
447
            } else {
448
                $searchData = (array) $session->get('eccube.admin.order.customer.search');
449
                if (is_null($page_no)) {
450
                    $page_no = intval($session->get('eccube.admin.order.customer.search.page_no'));
451
                } else {
452
                    $session->set('eccube.admin.order.customer.search.page_no', $page_no);
453
                }
454
            }
455
456
            $qb = $this->customerRepository->getQueryBuilderBySearchData($searchData);
457
458
            $event = new EventArgs(
459
                [
460
                    'qb' => $qb,
461
                    'data' => $searchData,
462
                ],
463
                $request
464
            );
465
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event);
466
467
            /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
468
            $pagination = $paginator->paginate(
469
                $qb,
470
                $page_no,
471
                $page_count,
472
                ['wrap-queries' => true]
473
            );
474
475
            /** @var $Customers \Eccube\Entity\Customer[] */
476
            $Customers = $pagination->getItems();
477
478
            if (empty($Customers)) {
479
                log_debug('search customer not found.');
480
            }
481
482
            $data = [];
483
            $formatName = '%s%s(%s%s)';
484 View Code Duplication
            foreach ($Customers as $Customer) {
485
                $data[] = [
486
                    'id' => $Customer->getId(),
487
                    'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(),
488
                        $Customer->getKana01(),
489
                        $Customer->getKana02()),
490
                    'phone_number' => $Customer->getPhoneNumber(),
491
                    'email' => $Customer->getEmail(),
492
                ];
493
            }
494
495
            $event = new EventArgs(
496
                [
497
                    'data' => $data,
498
                    'Customers' => $pagination,
499
                ],
500
                $request
501
            );
502
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event);
503
            $data = $event->getArgument('data');
504
505
            return [
506
                'data' => $data,
507
                'pagination' => $pagination,
508
            ];
509
        }
510
    }
511
512
    /**
513
     * 顧客情報を検索する.
514
     *
515
     * @Method("POST")
516
     * @Route("/%eccube_admin_route%/order/search/customer/id", name="admin_order_search_customer_by_id")
517
     *
518
     * @param Request $request
519
     *
520
     * @return \Symfony\Component\HttpFoundation\JsonResponse
521
     */
522 1
    public function searchCustomerById(Request $request)
523
    {
524 1
        if ($request->isXmlHttpRequest()) {
525 1
            log_debug('search customer by id start.');
526
527
            /** @var $Customer \Eccube\Entity\Customer */
528 1
            $Customer = $this->customerRepository
529 1
                ->find($request->get('id'));
530
531 1
            $event = new EventArgs(
532
                [
533 1
                    'Customer' => $Customer,
534
                ],
535 1
                $request
536
            );
537 1
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_INITIALIZE, $event);
538
539 1
            if (is_null($Customer)) {
540
                log_debug('search customer by id not found.');
541
542
                return $this->json([], 404);
543
            }
544
545 1
            log_debug('search customer by id found.');
546
547
            $data = [
548 1
                'id' => $Customer->getId(),
549 1
                'name01' => $Customer->getName01(),
550 1
                'name02' => $Customer->getName02(),
551 1
                'kana01' => $Customer->getKana01(),
552 1
                'kana02' => $Customer->getKana02(),
553 1
                'postal_code' => $Customer->getPostalCode(),
554 1
                'pref' => is_null($Customer->getPref()) ? null : $Customer->getPref()->getId(),
555 1
                'addr01' => $Customer->getAddr01(),
556 1
                'addr02' => $Customer->getAddr02(),
557 1
                'email' => $Customer->getEmail(),
558 1
                'phone_number' => $Customer->getPhoneNumber(),
559 1
                'company_name' => $Customer->getCompanyName(),
560
            ];
561
562 1
            $event = new EventArgs(
563
                [
564 1
                    'data' => $data,
565 1
                    'Customer' => $Customer,
566
                ],
567 1
                $request
568
            );
569 1
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_COMPLETE, $event);
570 1
            $data = $event->getArgument('data');
571
572 1
            return $this->json($data);
573
        }
574
    }
575
576
    /**
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...
577
     * @Route("/%eccube_admin_route%/order/search/product", name="admin_order_search_product")
578
     * @Route("/%eccube_admin_route%/order/search/product/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_order_search_product_page")
579
     * @Template("@admin/Order/search_product.twig")
580
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
581 1
    public function searchProduct(Request $request, $page_no = null, Paginator $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...
582
    {
583 1
        if ($request->isXmlHttpRequest()) {
584 1
            log_debug('search product start.');
585 1
            $page_count = $this->eccubeConfig['eccube_default_page_count'];
586 1
            $session = $this->session;
587
588 1
            if ('POST' === $request->getMethod()) {
589 1
                $page_no = 1;
590
591
                $searchData = [
592 1
                    'id' => $request->get('id'),
593
                ];
594
595 1
                if ($categoryId = $request->get('category_id')) {
596
                    $Category = $this->categoryRepository->find($categoryId);
597
                    $searchData['category_id'] = $Category;
598
                }
599
600 1
                $session->set('eccube.admin.order.product.search', $searchData);
601 1
                $session->set('eccube.admin.order.product.search.page_no', $page_no);
602
            } else {
603
                $searchData = (array) $session->get('eccube.admin.order.product.search');
604
                if (is_null($page_no)) {
605
                    $page_no = intval($session->get('eccube.admin.order.product.search.page_no'));
606
                } else {
607
                    $session->set('eccube.admin.order.product.search.page_no', $page_no);
608
                }
609
            }
610
611 1
            $qb = $this->productRepository
612 1
                ->getQueryBuilderBySearchDataForAdmin($searchData);
613
614 1
            $event = new EventArgs(
615
                [
616 1
                    'qb' => $qb,
617 1
                    'searchData' => $searchData,
618
                ],
619 1
                $request
620
            );
621 1
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH, $event);
622
623
            /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
624 1
            $pagination = $paginator->paginate(
625 1
                $qb,
626 1
                $page_no,
627 1
                $page_count,
628 1
                ['wrap-queries' => true]
629
            );
630
631
            /** @var $Products \Eccube\Entity\Product[] */
632 1
            $Products = $pagination->getItems();
633
634 1
            if (empty($Products)) {
635
                log_debug('search product not found.');
636
            }
637
638 1
            $forms = [];
639 1 View Code Duplication
            foreach ($Products as $Product) {
640
                /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
641 1
                $builder = $this->formFactory->createNamedBuilder('', AddCartType::class, null, [
642 1
                    'product' => $Product,
643
                ]);
644 1
                $addCartForm = $builder->getForm();
645 1
                $forms[$Product->getId()] = $addCartForm->createView();
646
            }
647
648 1
            $event = new EventArgs(
649
                [
650 1
                    'forms' => $forms,
651 1
                    'Products' => $Products,
652 1
                    'pagination' => $pagination,
653
                ],
654 1
                $request
655
            );
656 1
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE, $event);
657
658
            return [
659 1
                'forms' => $forms,
660 1
                'Products' => $Products,
661 1
                'pagination' => $pagination,
662
            ];
663
        }
664
    }
665
666
    /**
667
     * その他明細情報を取得
668
     *
669
     * @Route("/%eccube_admin_route%/order/search/order_item_type", name="admin_order_search_order_item_type")
670
     * @Template("@admin/Order/order_item_type.twig")
671
     *
672
     * @param Request $request
673
     *
674
     * @return array
675
     */
676
    public function searchOrderItemType(Request $request)
677
    {
678
        if ($request->isXmlHttpRequest()) {
679
            log_debug('search order item type start.');
680
681
            $criteria = Criteria::create();
682
            $criteria
683
                ->where($criteria->expr()->andX(
684
                    $criteria->expr()->neq('id', OrderItemType::PRODUCT),
685
                    $criteria->expr()->neq('id', OrderItemType::TAX)
686
                ))
687
                ->orderBy(['sort_no' => 'ASC']);
688
689
            $OrderItemTypes = $this->orderItemTypeRepository->matching($criteria);
690
691
            $forms = [];
692
            foreach ($OrderItemTypes as $OrderItemType) {
693
                /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
694
                $builder = $this->formFactory->createBuilder();
695
                $form = $builder->getForm();
696
                $forms[$OrderItemType->getId()] = $form->createView();
697
            }
698
699
            return [
700
                'forms' => $forms,
701
                'OrderItemTypes' => $OrderItemTypes,
702
            ];
703
        }
704
    }
705
706 3
    protected function newOrder()
707
    {
708 3
        $Order = new Order();
709
        // device type
710 3
        $DeviceType = $this->deviceTypeRepository->find(DeviceType::DEVICE_TYPE_ADMIN);
711 3
        $Order->setDeviceType($DeviceType);
712
713 3
        $Shipping = new Shipping();
714 3
        $Order->addShipping($Shipping);
715 3
        $Shipping->setOrder($Order);
716
717 3
        return $Order;
718
    }
719
720
    /**
721
     * 受注ステータスに応じて, 受注日/入金日/発送日を更新する,
722
     * 発送済ステータスが設定された場合は, お届け先情報の発送日も更新を行う.
723
     *
724
     * 編集の場合
725
     * - 受注ステータスが他のステータスから発送済へ変更された場合に発送日を更新
726
     * - 受注ステータスが他のステータスから入金済へ変更された場合に入金日を更新
727
     *
728
     * 新規登録の場合
729
     * - 受注日を更新
730
     * - 受注ステータスが発送済に設定された場合に発送日を更新
731
     * - 受注ステータスが入金済に設定された場合に入金日を更新
732
     *
733
     * @param $app
734
     * @param $TargetOrder
735
     * @param $OriginOrder
736
     *
737
     * TODO Service へ移動する
738
     */
739
    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...
740
    {
741
        $dateTime = new \DateTime();
742
743
        // 編集
744
        if ($TargetOrder->getId()) {
745
            // 発送済
746
            if ($TargetOrder->getOrderStatus()->getId() == OrderStatus::DELIVERED) {
747
                // 編集前と異なる場合のみ更新
748
                if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
749
                    // お届け先情報の発送日も更新する.
750
                    $Shippings = $TargetOrder->getShippings();
751
                    foreach ($Shippings as $Shipping) {
752
                        $Shipping->setShippingDate($dateTime);
753
                    }
754
                }
755
                // 入金済
756
            } elseif ($TargetOrder->getOrderStatus()->getId() == OrderStatus::PAID) {
757
                // 編集前と異なる場合のみ更新
758
                if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
759
                    $TargetOrder->setPaymentDate($dateTime);
760
                }
761
            }
762
            // 新規
763
        } else {
764
            // 発送済
765
            if ($TargetOrder->getOrderStatus()->getId() == OrderStatus::DELIVERED) {
766
                // お届け先情報の発送日も更新する.
767
                $Shippings = $TargetOrder->getShippings();
768
                foreach ($Shippings as $Shipping) {
769
                    $Shipping->setShippingDate($dateTime);
770
                }
771
                // 入金済
772
            } elseif ($TargetOrder->getOrderStatus()->getId() == OrderStatus::PAID) {
773
                $TargetOrder->setPaymentDate($dateTime);
774
            }
775
            // 受注日時
776
            $TargetOrder->setOrderDate($dateTime);
777
        }
778
    }
779
}
780