Completed
Push — 4.0 ( 268f2c...88f012 )
by Hideki
05:48 queued 10s
created

Eccube/Controller/Admin/Order/EditController.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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