Failed Conditions
Pull Request — experimental/sf (#3247)
by Kiyotaka
114:07 queued 103:28
created

EditController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 21
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 1

Importance

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

How to fix   Many Parameters   

Many Parameters

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

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Controller\Admin\Order;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Eccube\Controller\AbstractController;
18
use Eccube\Entity\Customer;
19
use Eccube\Entity\Master\CustomerStatus;
20
use Eccube\Entity\Master\DeviceType;
21
use Eccube\Entity\Master\OrderStatus;
22
use Eccube\Event\EccubeEvents;
23
use Eccube\Event\EventArgs;
24
use Eccube\Form\Type\AddCartType;
25
use Eccube\Form\Type\Admin\OrderType;
26
use Eccube\Form\Type\Admin\SearchCustomerType;
27
use Eccube\Form\Type\Admin\SearchProductType;
28
use Eccube\Repository\CategoryRepository;
29
use Eccube\Repository\CustomerRepository;
30
use Eccube\Repository\DeliveryRepository;
31
use Eccube\Repository\Master\DeviceTypeRepository;
32
use Eccube\Repository\OrderRepository;
33
use Eccube\Repository\ProductRepository;
34
use Eccube\Service\PurchaseFlow\PurchaseContext;
35
use Eccube\Service\PurchaseFlow\PurchaseException;
36
use Eccube\Service\PurchaseFlow\PurchaseFlow;
37
use Eccube\Service\TaxRuleService;
38
use Knp\Component\Pager\Paginator;
39
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
40
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
41
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
42
use Symfony\Component\HttpFoundation\Request;
43
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
44
use Symfony\Component\Serializer\Serializer;
45
use Symfony\Component\Serializer\SerializerInterface;
46
47
class EditController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
48
{
49
    /**
50
     * @var TaxRuleService
51
     */
52
    protected $taxRuleService;
53
54
    /**
55
     * @var DeviceTypeRepository
56
     */
57
    protected $deviceTypeRepository;
58
59
    /**
60
     * @var ProductRepository
61
     */
62
    protected $productRepository;
63
64
    /**
65
     * @var CategoryRepository
66
     */
67
    protected $categoryRepository;
68
69
    /**
70
     * @var CustomerRepository
71
     */
72
    protected $customerRepository;
73
74
    /**
75
     * @var Serializer
76
     */
77
    protected $serializer;
78
79
    /**
80
     * @var DeliveryRepository
81
     */
82
    protected $deliveryRepository;
83
84
    /**
85
     * @var PurchaseFlow
86
     */
87
    protected $purchaseFlow;
88
89
    /**
90
     * @var OrderRepository
91
     */
92
    protected $orderRepository;
93
94
    /**
95
     * EditController constructor.
96
     *
97
     * @param TaxRuleService $taxRuleService
0 ignored issues
show
introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
98
     * @param DeviceTypeRepository $deviceTypeRepository
99
     * @param ProductRepository $productRepository
0 ignored issues
show
introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
100
     * @param CategoryRepository $categoryRepository
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
101
     * @param CustomerRepository $customerRepository
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
102
     * @param SerializerInterface $serializer
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
103
     * @param DeliveryRepository $deliveryRepository
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
104
     * @param PurchaseFlow $orderPurchaseFlow
0 ignored issues
show
introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
105
     * @param OrderRepository $orderRepository
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
106
     */
107 11 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
108
        TaxRuleService $taxRuleService,
109
        DeviceTypeRepository $deviceTypeRepository,
110
        ProductRepository $productRepository,
111
        CategoryRepository $categoryRepository,
112
        CustomerRepository $customerRepository,
113
        SerializerInterface $serializer,
114
        DeliveryRepository $deliveryRepository,
115
        PurchaseFlow $orderPurchaseFlow,
116
        OrderRepository $orderRepository
117
    ) {
118 11
        $this->taxRuleService = $taxRuleService;
119 11
        $this->deviceTypeRepository = $deviceTypeRepository;
120 11
        $this->productRepository = $productRepository;
121 11
        $this->categoryRepository = $categoryRepository;
122 11
        $this->customerRepository = $customerRepository;
123 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...
124 11
        $this->deliveryRepository = $deliveryRepository;
125 11
        $this->purchaseFlow = $orderPurchaseFlow;
126 11
        $this->orderRepository = $orderRepository;
127
    }
128
129
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
130
     * 受注登録/編集画面.
131
     *
132
     * @Route("/%eccube_admin_route%/order/new", name="admin_order_new")
133
     * @Route("/%eccube_admin_route%/order/{id}/edit", requirements={"id" = "\d+"}, name="admin_order_edit")
134
     * @Template("@admin/Order/edit.twig")
135
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
136 7
    public function index(Request $request, $id = null)
137
    {
138 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...
139 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...
140
141 7
        if (is_null($id)) {
142
            // 空のエンティティを作成.
143 3
            $TargetOrder = $this->newOrder();
144
        } else {
145 4
            $TargetOrder = $this->orderRepository->find($id);
146 4
            if (is_null($TargetOrder)) {
147
                throw new NotFoundHttpException();
148
            }
149
        }
150
151
        // 編集前の受注情報を保持
152 7
        $OriginOrder = clone $TargetOrder;
153 7
        $OriginItems = new ArrayCollection();
154 7
        foreach ($TargetOrder->getOrderItems() as $Item) {
155 4
            $OriginItems->add($Item);
156
        }
157
158 7
        $builder = $this->formFactory
159 7
            ->createBuilder(OrderType::class, $TargetOrder,
160
                [
161 7
                    'SortedItems' => $TargetOrder->getItems(),
162
                ]
163
            );
164
165 7
        $event = new EventArgs(
166
            [
167 7
                'builder' => $builder,
168 7
                'OriginOrder' => $OriginOrder,
169 7
                'TargetOrder' => $TargetOrder,
170
            ],
171 7
            $request
172
        );
173 7
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_INITIALIZE, $event);
174
175 7
        $form = $builder->getForm();
176 7
        $form->handleRequest($request);
177 7
        $purchaseContext = new PurchaseContext($OriginOrder, $OriginOrder->getCustomer());
178
179 7
        if ($form->isSubmitted()) {
180 5
            $event = new EventArgs(
181
                [
182 5
                    'builder' => $builder,
183 5
                    'OriginOrder' => $OriginOrder,
184 5
                    'TargetOrder' => $TargetOrder,
185 5
                    'PurchaseContext' => $purchaseContext,
186
                ],
187 5
                $request
188
            );
189 5
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event);
190
191 5
            $flowResult = $this->purchaseFlow->validate($TargetOrder, $purchaseContext);
192 5
            if ($flowResult->hasWarning()) {
193
                foreach ($flowResult->getWarning() as $warning) {
194
                    // TODO Warning の場合の処理
195
                    $this->addWarning($warning->getMessage(), 'admin');
196
                }
197
            }
198
199 5
            if ($flowResult->hasError()) {
200
                foreach ($flowResult->getErrors() as $error) {
201
                    $this->addError($error->getMessage(), 'admin');
202
                }
203
            }
204
205
            // 登録ボタン押下
206 5
            switch ($request->get('mode')) {
207
                case 'register':
208 5
                    log_info('受注登録開始', [$TargetOrder->getId()]);
209
210 5
                    if ($flowResult->hasError() === false && $form->isValid()) {
211
                        try {
212 5
                            $this->purchaseFlow->prepare($TargetOrder, $purchaseContext);
213 5
                            $this->purchaseFlow->commit($TargetOrder, $purchaseContext);
214
                        } catch (PurchaseException $e) {
215
                            $this->addError($e->getMessage(), 'admin');
216
                            break;
217
                        }
218
219 5
                        $this->entityManager->persist($TargetOrder);
220 5
                        $this->entityManager->flush();
221
222 5
                        foreach ($OriginItems as $Item) {
223 3
                            if (false === $TargetOrder->getOrderItems()->contains($Item)) {
224 3
                                $this->entityManager->remove($Item);
225
                            }
226
                        }
227 5
                        $this->entityManager->flush();
228
229
                        // TODO 集計系に移動
230
//                        if ($Customer) {
231
//                            // 会員の場合、購入回数、購入金額などを更新
232
//                            $app['eccube.repository.customer']->updateBuyData($app, $Customer, $TargetOrder->getOrderStatus()->getId());
233
//                        }
234
235 5
                        $event = new EventArgs(
236
                            [
237 5
                                'form' => $form,
238 5
                                'OriginOrder' => $OriginOrder,
239 5
                                'TargetOrder' => $TargetOrder,
240
                                //'Customer' => $Customer,
241
                            ],
242 5
                            $request
243
                        );
244 5
                        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_COMPLETE, $event);
245
246 5
                        $this->addSuccess('admin.order.save.complete', 'admin');
247
248 5
                        log_info('受注登録完了', [$TargetOrder->getId()]);
249
250 5
                        return $this->redirectToRoute('admin_order_edit', ['id' => $TargetOrder->getId()]);
251
                    }
252
253
                    break;
254
255
                case 'add_delivery':
256
                    // お届け先情報の新規追加
257
258
                    $form = $builder->getForm();
259
260
                    $Shipping = new \Eccube\Entity\Shipping();
261
                    $TargetOrder->addShipping($Shipping);
262
263
                    $Shipping->setOrder($TargetOrder);
264
265
                    $form->setData($TargetOrder);
266
267
                    break;
268
269
                default:
270
                    break;
271
            }
272
        }
273
274
        // 会員検索フォーム
275 2
        $builder = $this->formFactory
276 2
            ->createBuilder(SearchCustomerType::class);
277
278 2
        $event = new EventArgs(
279
            [
280 2
                'builder' => $builder,
281 2
                'OriginOrder' => $OriginOrder,
282 2
                'TargetOrder' => $TargetOrder,
283
            ],
284 2
            $request
285
        );
286 2
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_INITIALIZE, $event);
287
288 2
        $searchCustomerModalForm = $builder->getForm();
289
290
        // 商品検索フォーム
291 2
        $builder = $this->formFactory
292 2
            ->createBuilder(SearchProductType::class);
293
294 2
        $event = new EventArgs(
295
            [
296 2
                'builder' => $builder,
297 2
                'OriginOrder' => $OriginOrder,
298 2
                'TargetOrder' => $TargetOrder,
299
            ],
300 2
            $request
301
        );
302 2
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_INITIALIZE, $event);
303
304 2
        $searchProductModalForm = $builder->getForm();
305
306
        // 配送業者のお届け時間
307 2
        $times = [];
308 2
        $deliveries = $this->deliveryRepository->findAll();
309 2 View Code Duplication
        foreach ($deliveries as $Delivery) {
310 2
            $deliveryTiems = $Delivery->getDeliveryTimes();
311 2
            foreach ($deliveryTiems as $DeliveryTime) {
312 2
                $times[$Delivery->getId()][$DeliveryTime->getId()] = $DeliveryTime->getDeliveryTime();
313
            }
314
        }
315
316
        return [
317 2
            'form' => $form->createView(),
318 2
            'searchCustomerModalForm' => $searchCustomerModalForm->createView(),
319 2
            'searchProductModalForm' => $searchProductModalForm->createView(),
320 2
            'Order' => $TargetOrder,
321 2
            'id' => $id,
322 2
            'shippingDeliveryTimes' => $this->serializer->serialize($times, 'json'),
323
        ];
324
    }
325
326
    /**
327
     * 顧客情報を検索する.
328
     *
329
     * @Route("/%eccube_admin_route%/order/search/customer", name="admin_order_search_customer")
330
     *
331
     * @param Request $request
332
     *
333
     * @return \Symfony\Component\HttpFoundation\JsonResponse
334
     */
335 2
    public function searchCustomer(Request $request)
336
    {
337 2
        if ($request->isXmlHttpRequest()) {
338 2
            log_debug('search customer start.');
339
340
            $searchData = [
341 2
                'multi' => $request->get('search_word'),
342
            ];
343
344 2
            $qb = $this->customerRepository->getQueryBuilderBySearchData($searchData);
345
346 2
            $event = new EventArgs(
347
                [
348 2
                    'qb' => $qb,
349 2
                    'data' => $searchData,
350
                ],
351 2
                $request
352
            );
353 2
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event);
354
355
            /** @var Customer[] $Customers */
356 2
            $Customers = $qb->getQuery()->getResult();
357
358 2
            if (empty($Customers)) {
359
                log_debug('search customer not found.');
360
            }
361
362 2
            $data = [];
363 2
            $formatName = '%s%s(%s%s)';
364 2 View Code Duplication
            foreach ($Customers as $Customer) {
365 2
                $data[] = [
366 2
                    'id' => $Customer->getId(),
367 2
                    'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(),
368 2
                        $Customer->getKana01(),
369 2
                        $Customer->getKana02()),
370 2
                    'phone_number' => $Customer->getPhoneNumber(),
371 2
                    'email' => $Customer->getEmail(),
372
                ];
373
            }
374
375 2
            $event = new EventArgs(
376
                [
377 2
                    'data' => $data,
378 2
                    'Customers' => $Customers,
379
                ],
380 2
                $request
381
            );
382 2
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event);
383 2
            $data = $event->getArgument('data');
384
385 2
            return $this->json($data);
386
        }
387
    }
388
389
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$paginator" missing
Loading history...
390
     * 顧客情報を検索する.
391
     *
392
     * @Route("/%eccube_admin_route%/order/search/customer/html", name="admin_order_search_customer_html")
393
     * @Route("/%eccube_admin_route%/order/search/customer/html/page/{page_no}", requirements={"page_No" = "\d+"}, name="admin_order_search_customer_html_page")
394
     * @Template("@admin/Order/search_customer.twig")
395
     *
396
     * @param Request $request
397
     * @param integer $page_no
398
     *
399
     * @return \Symfony\Component\HttpFoundation\JsonResponse
400
     */
401
    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...
402
    {
403
        if ($request->isXmlHttpRequest()) {
404
            log_debug('search customer start.');
405
            $page_count = $this->eccubeConfig['eccube_default_page_count'];
406
            $session = $this->session;
407
408
            if ('POST' === $request->getMethod()) {
409
                $page_no = 1;
410
411
                $searchData = [
412
                    'multi' => $request->get('search_word'),
413
                    'customer_status' => [
414
                        CustomerStatus::REGULAR,
415
                    ],
416
                ];
417
418
                $session->set('eccube.admin.order.customer.search', $searchData);
419
                $session->set('eccube.admin.order.customer.search.page_no', $page_no);
420
            } else {
421
                $searchData = (array) $session->get('eccube.admin.order.customer.search');
422
                if (is_null($page_no)) {
423
                    $page_no = intval($session->get('eccube.admin.order.customer.search.page_no'));
424
                } else {
425
                    $session->set('eccube.admin.order.customer.search.page_no', $page_no);
426
                }
427
            }
428
429
            $qb = $this->customerRepository->getQueryBuilderBySearchData($searchData);
430
431
            $event = new EventArgs(
432
                [
433
                    'qb' => $qb,
434
                    'data' => $searchData,
435
                ],
436
                $request
437
            );
438
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event);
439
440
            /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
441
            $pagination = $paginator->paginate(
442
                $qb,
443
                $page_no,
444
                $page_count,
445
                ['wrap-queries' => true]
446
            );
447
448
            /** @var $Customers \Eccube\Entity\Customer[] */
449
            $Customers = $pagination->getItems();
450
451
            if (empty($Customers)) {
452
                log_debug('search customer not found.');
453
            }
454
455
            $data = [];
456
            $formatName = '%s%s(%s%s)';
457 View Code Duplication
            foreach ($Customers as $Customer) {
458
                $data[] = [
459
                    'id' => $Customer->getId(),
460
                    'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(),
461
                        $Customer->getKana01(),
462
                        $Customer->getKana02()),
463
                    'phone_number' => $Customer->getPhoneNumber(),
464
                    'email' => $Customer->getEmail(),
465
                ];
466
            }
467
468
            $event = new EventArgs(
469
                [
470
                    'data' => $data,
471
                    'Customers' => $pagination,
472
                ],
473
                $request
474
            );
475
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event);
476
            $data = $event->getArgument('data');
477
478
            return [
479
                'data' => $data,
480
                'pagination' => $pagination,
481
            ];
482
        }
483
    }
484
485
    /**
486
     * 顧客情報を検索する.
487
     *
488
     * @Method("POST")
489
     * @Route("/%eccube_admin_route%/order/search/customer/id", name="admin_order_search_customer_by_id")
490
     *
491
     * @param Request $request
492
     *
493
     * @return \Symfony\Component\HttpFoundation\JsonResponse
494
     */
495 1
    public function searchCustomerById(Request $request)
496
    {
497 1
        if ($request->isXmlHttpRequest()) {
498 1
            log_debug('search customer by id start.');
499
500
            /** @var $Customer \Eccube\Entity\Customer */
501 1
            $Customer = $this->customerRepository
502 1
                ->find($request->get('id'));
503
504 1
            $event = new EventArgs(
505
                [
506 1
                    'Customer' => $Customer,
507
                ],
508 1
                $request
509
            );
510 1
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_INITIALIZE, $event);
511
512 1
            if (is_null($Customer)) {
513
                log_debug('search customer by id not found.');
514
515
                return $this->json([], 404);
516
            }
517
518 1
            log_debug('search customer by id found.');
519
520
            $data = [
521 1
                'id' => $Customer->getId(),
522 1
                'name01' => $Customer->getName01(),
523 1
                'name02' => $Customer->getName02(),
524 1
                'kana01' => $Customer->getKana01(),
525 1
                'kana02' => $Customer->getKana02(),
526 1
                'postal_code' => $Customer->getPostalCode(),
527 1
                'pref' => is_null($Customer->getPref()) ? null : $Customer->getPref()->getId(),
528 1
                'addr01' => $Customer->getAddr01(),
529 1
                'addr02' => $Customer->getAddr02(),
530 1
                'email' => $Customer->getEmail(),
531 1
                'phone_number' => $Customer->getPhoneNumber(),
532 1
                'company_name' => $Customer->getCompanyName(),
533
            ];
534
535 1
            $event = new EventArgs(
536
                [
537 1
                    'data' => $data,
538 1
                    'Customer' => $Customer,
539
                ],
540 1
                $request
541
            );
542 1
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_COMPLETE, $event);
543 1
            $data = $event->getArgument('data');
544
545 1
            return $this->json($data);
546
        }
547
    }
548
549
    /**
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...
550
     * @Route("/%eccube_admin_route%/order/search/product", name="admin_order_search_product")
551
     * @Route("/%eccube_admin_route%/order/search/product/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_order_search_product_page")
552
     * @Template("@admin/Order/search_product.twig")
553
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
554 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...
555
    {
556 1
        if ($request->isXmlHttpRequest()) {
557 1
            log_debug('search product start.');
558 1
            $page_count = $this->eccubeConfig['eccube_default_page_count'];
559 1
            $session = $this->session;
560
561 1
            if ('POST' === $request->getMethod()) {
562 1
                $page_no = 1;
563
564
                $searchData = [
565 1
                    'id' => $request->get('id'),
566
                ];
567
568 1
                if ($categoryId = $request->get('category_id')) {
569
                    $Category = $this->categoryRepository->find($categoryId);
570
                    $searchData['category_id'] = $Category;
571
                }
572
573 1
                $session->set('eccube.admin.order.product.search', $searchData);
574 1
                $session->set('eccube.admin.order.product.search.page_no', $page_no);
575
            } else {
576
                $searchData = (array) $session->get('eccube.admin.order.product.search');
577
                if (is_null($page_no)) {
578
                    $page_no = intval($session->get('eccube.admin.order.product.search.page_no'));
579
                } else {
580
                    $session->set('eccube.admin.order.product.search.page_no', $page_no);
581
                }
582
            }
583
584 1
            $qb = $this->productRepository
585 1
                ->getQueryBuilderBySearchDataForAdmin($searchData);
586
587 1
            $event = new EventArgs(
588
                [
589 1
                    'qb' => $qb,
590 1
                    'searchData' => $searchData,
591
                ],
592 1
                $request
593
            );
594 1
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH, $event);
595
596
            /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
597 1
            $pagination = $paginator->paginate(
598 1
                $qb,
599 1
                $page_no,
600 1
                $page_count,
601 1
                ['wrap-queries' => true]
602
            );
603
604
            /** @var $Products \Eccube\Entity\Product[] */
605 1
            $Products = $pagination->getItems();
606
607 1
            if (empty($Products)) {
608
                log_debug('search product not found.');
609
            }
610
611 1
            $forms = [];
612 1 View Code Duplication
            foreach ($Products as $Product) {
613
                /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
614 1
                $builder = $this->formFactory->createNamedBuilder('', AddCartType::class, null, [
615 1
                    'product' => $Product,
616
                ]);
617 1
                $addCartForm = $builder->getForm();
618 1
                $forms[$Product->getId()] = $addCartForm->createView();
619
            }
620
621 1
            $event = new EventArgs(
622
                [
623 1
                    'forms' => $forms,
624 1
                    'Products' => $Products,
625 1
                    'pagination' => $pagination,
626
                ],
627 1
                $request
628
            );
629 1
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE, $event);
630
631
            return [
632 1
                'forms' => $forms,
633 1
                'Products' => $Products,
634 1
                'pagination' => $pagination,
635
            ];
636
        }
637
    }
638
639 3
    protected function newOrder()
640
    {
641 3
        $Order = new \Eccube\Entity\Order();
642
        // device type
643 3
        $DeviceType = $this->deviceTypeRepository->find(DeviceType::DEVICE_TYPE_ADMIN);
644 3
        $Order->setDeviceType($DeviceType);
645
646 3
        return $Order;
647
    }
648
649
    /**
650
     * 受注ステータスに応じて, 受注日/入金日/発送日を更新する,
651
     * 発送済ステータスが設定された場合は, お届け先情報の発送日も更新を行う.
652
     *
653
     * 編集の場合
654
     * - 受注ステータスが他のステータスから発送済へ変更された場合に発送日を更新
655
     * - 受注ステータスが他のステータスから入金済へ変更された場合に入金日を更新
656
     *
657
     * 新規登録の場合
658
     * - 受注日を更新
659
     * - 受注ステータスが発送済に設定された場合に発送日を更新
660
     * - 受注ステータスが入金済に設定された場合に入金日を更新
661
     *
662
     * @param $app
663
     * @param $TargetOrder
664
     * @param $OriginOrder
665
     *
666
     * TODO Service へ移動する
667
     */
668
    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...
669
    {
670
        $dateTime = new \DateTime();
671
672
        // 編集
673 View Code Duplication
        if ($TargetOrder->getId()) {
674
            // 発送済
675
            if ($TargetOrder->getOrderStatus()->getId() == OrderStatus::DELIVERED) {
676
                // 編集前と異なる場合のみ更新
677
                if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
678
                    $TargetOrder->setShippingDate($dateTime);
679
                    // お届け先情報の発送日も更新する.
680
                    $Shippings = $TargetOrder->getShippings();
681
                    foreach ($Shippings as $Shipping) {
682
                        $Shipping->setShippingDate($dateTime);
683
                    }
684
                }
685
                // 入金済
686
            } elseif ($TargetOrder->getOrderStatus()->getId() == OrderStatus::PAID) {
687
                // 編集前と異なる場合のみ更新
688
                if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
689
                    $TargetOrder->setPaymentDate($dateTime);
690
                }
691
            }
692
            // 新規
693
        } else {
694
            // 発送済
695
            if ($TargetOrder->getOrderStatus()->getId() == OrderStatus::DELIVERED) {
696
                $TargetOrder->setShippingDate($dateTime);
697
                // お届け先情報の発送日も更新する.
698
                $Shippings = $TargetOrder->getShippings();
699
                foreach ($Shippings as $Shipping) {
700
                    $Shipping->setShippingDate($dateTime);
701
                }
702
                // 入金済
703
            } elseif ($TargetOrder->getOrderStatus()->getId() == OrderStatus::PAID) {
704
                $TargetOrder->setPaymentDate($dateTime);
705
            }
706
            // 受注日時
707
            $TargetOrder->setOrderDate($dateTime);
708
        }
709
    }
710
}
711