Completed
Push — 4.0 ( 87d096...bcc1be )
by Kiyotaka
05:44 queued 11s
created

Eccube/Controller/Admin/Order/EditController.php (1 issue)

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\Order;
23
use Eccube\Entity\Shipping;
24
use Eccube\Event\EccubeEvents;
25
use Eccube\Event\EventArgs;
26
use Eccube\Form\Type\AddCartType;
27
use Eccube\Form\Type\Admin\OrderType;
28
use Eccube\Form\Type\Admin\SearchCustomerType;
29
use Eccube\Form\Type\Admin\SearchProductType;
30
use Eccube\Repository\CategoryRepository;
31
use Eccube\Repository\CustomerRepository;
32
use Eccube\Repository\DeliveryRepository;
33
use Eccube\Repository\Master\DeviceTypeRepository;
34
use Eccube\Repository\Master\OrderItemTypeRepository;
35
use Eccube\Repository\Master\OrderStatusRepository;
36
use Eccube\Repository\OrderRepository;
37
use Eccube\Repository\ProductRepository;
38
use Eccube\Service\OrderHelper;
39
use Eccube\Service\OrderStateMachine;
40
use Eccube\Service\PurchaseFlow\Processor\OrderNoProcessor;
41
use Eccube\Service\PurchaseFlow\PurchaseContext;
42
use Eccube\Service\PurchaseFlow\PurchaseException;
43
use Eccube\Service\PurchaseFlow\PurchaseFlow;
44
use Eccube\Service\TaxRuleService;
45
use Knp\Component\Pager\Paginator;
46
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
47
use Symfony\Component\HttpFoundation\Request;
48
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
49
use Symfony\Component\Routing\Annotation\Route;
50
use Symfony\Component\Routing\RouterInterface;
51
use Symfony\Component\Serializer\Serializer;
52
use Symfony\Component\Serializer\SerializerInterface;
53
54
class EditController extends AbstractController
55
{
56
    /**
57
     * @var TaxRuleService
58
     */
59
    protected $taxRuleService;
60
61
    /**
62
     * @var DeviceTypeRepository
63
     */
64
    protected $deviceTypeRepository;
65
66
    /**
67
     * @var ProductRepository
68
     */
69
    protected $productRepository;
70
71
    /**
72
     * @var CategoryRepository
73
     */
74
    protected $categoryRepository;
75
76
    /**
77
     * @var CustomerRepository
78
     */
79
    protected $customerRepository;
80
81
    /**
82
     * @var Serializer
83
     */
84
    protected $serializer;
85
86
    /**
87
     * @var DeliveryRepository
88
     */
89
    protected $deliveryRepository;
90
91
    /**
92
     * @var PurchaseFlow
93
     */
94
    protected $purchaseFlow;
95
96
    /**
97
     * @var OrderRepository
98
     */
99
    protected $orderRepository;
100
101
    /**
102
     * @var OrderNoProcessor
103
     */
104
    protected $orderNoProcessor;
105
106
    /**
107
     * @var OrderItemTypeRepository
108
     */
109
    protected $orderItemTypeRepository;
110
111
    /**
112
     * @var OrderStateMachine
113
     */
114
    protected $orderStateMachine;
115
116
    /**
117
     * @var OrderStatusRepository
118
     */
119
    protected $orderStatusRepository;
120
121
    /**
122
     * @var OrderHelper
123
     */
124
    private $orderHelper;
125
126
    /**
127
     * EditController constructor.
128
     *
129
     * @param TaxRuleService $taxRuleService
130
     * @param DeviceTypeRepository $deviceTypeRepository
131
     * @param ProductRepository $productRepository
132
     * @param CategoryRepository $categoryRepository
133
     * @param CustomerRepository $customerRepository
134
     * @param SerializerInterface $serializer
135 10
     * @param DeliveryRepository $deliveryRepository
136
     * @param PurchaseFlow $orderPurchaseFlow
137
     * @param OrderRepository $orderRepository
138
     * @param OrderNoProcessor $orderNoProcessor
139
     * @param OrderItemTypeRepository $orderItemTypeRepository
140
     * @param OrderStatusRepository $orderStatusRepository
141
     * @param OrderStateMachine $orderStateMachine
142
     * @param OrderHelper $orderHelper
143
     */
144
    public function __construct(
145
        TaxRuleService $taxRuleService,
146
        DeviceTypeRepository $deviceTypeRepository,
147
        ProductRepository $productRepository,
148
        CategoryRepository $categoryRepository,
149
        CustomerRepository $customerRepository,
150 10
        SerializerInterface $serializer,
151 10
        DeliveryRepository $deliveryRepository,
152 10
        PurchaseFlow $orderPurchaseFlow,
153 10
        OrderRepository $orderRepository,
154 10
        OrderNoProcessor $orderNoProcessor,
155 10
        OrderItemTypeRepository $orderItemTypeRepository,
156 10
        OrderStatusRepository $orderStatusRepository,
157 10
        OrderStateMachine $orderStateMachine,
158 10
        OrderHelper $orderHelper
159 10
    ) {
160 10
        $this->taxRuleService = $taxRuleService;
161 10
        $this->deviceTypeRepository = $deviceTypeRepository;
162 10
        $this->productRepository = $productRepository;
163
        $this->categoryRepository = $categoryRepository;
164
        $this->customerRepository = $customerRepository;
165
        $this->serializer = $serializer;
166
        $this->deliveryRepository = $deliveryRepository;
167
        $this->purchaseFlow = $orderPurchaseFlow;
168
        $this->orderRepository = $orderRepository;
169
        $this->orderNoProcessor = $orderNoProcessor;
170
        $this->orderItemTypeRepository = $orderItemTypeRepository;
171
        $this->orderStatusRepository = $orderStatusRepository;
172 7
        $this->orderStateMachine = $orderStateMachine;
173
        $this->orderHelper = $orderHelper;
174 7
    }
175 7
176
    /**
177 7
     * 受注登録/編集画面.
178
     *
179 3
     * @Route("/%eccube_admin_route%/order/new", name="admin_order_new")
180 3
     * @Route("/%eccube_admin_route%/order/{id}/edit", requirements={"id" = "\d+"}, name="admin_order_edit")
181
     * @Template("@admin/Order/edit.twig")
182 4
     */
183 4
    public function index(Request $request, $id = null, RouterInterface $router)
184
    {
185
        $TargetOrder = null;
186
        $OriginOrder = null;
187
188
        if (null === $id) {
189 7
            // 空のエンティティを作成.
190 7
            $TargetOrder = new Order();
191 7
            $TargetOrder->addShipping((new Shipping())->setOrder($TargetOrder));
192 4
193
            $preOrderId = $this->orderHelper->createPreOrderId();
194
            $TargetOrder->setPreOrderId($preOrderId);
195 7
        } else {
196
            $TargetOrder = $this->orderRepository->find($id);
197 7
            if (null === $TargetOrder) {
198
                throw new NotFoundHttpException();
199 7
            }
200 7
        }
201 7
202
        // 編集前の受注情報を保持
203 7
        $OriginOrder = clone $TargetOrder;
204
        $OriginItems = new ArrayCollection();
205 7
        foreach ($TargetOrder->getOrderItems() as $Item) {
206
            $OriginItems->add($Item);
207 7
        }
208
209 7
        $builder = $this->formFactory->createBuilder(OrderType::class, $TargetOrder);
210 7
211
        $event = new EventArgs(
212 7
            [
213 5
                'builder' => $builder,
214
                'OriginOrder' => $OriginOrder,
215 5
                'TargetOrder' => $TargetOrder,
216 5
            ],
217 5
            $request
218 5
        );
219
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_INITIALIZE, $event);
220 5
221
        $form = $builder->getForm();
222 5
223
        $form->handleRequest($request);
224 5
        $purchaseContext = new PurchaseContext($OriginOrder, $OriginOrder->getCustomer());
225
226 5
        if ($form->isSubmitted() && $form['OrderItems']->isValid()) {
227
            $event = new EventArgs(
228
                [
229
                    'builder' => $builder,
230
                    'OriginOrder' => $OriginOrder,
231
                    'TargetOrder' => $TargetOrder,
232 5
                    'PurchaseContext' => $purchaseContext,
233
                ],
234
                $request
235
            );
236
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event);
237
238
            $flowResult = $this->purchaseFlow->validate($TargetOrder, $purchaseContext);
239 5
240
            if ($flowResult->hasWarning()) {
241 5
                foreach ($flowResult->getWarning() as $warning) {
242
                    $this->addWarning($warning->getMessage(), 'admin');
243 5
                }
244
            }
245 5
246 5
            if ($flowResult->hasError()) {
247
                foreach ($flowResult->getErrors() as $error) {
248
                    $this->addError($error->getMessage(), 'admin');
249
                }
250
            }
251
252 5
            // 登録ボタン押下
253 5
            switch ($request->get('mode')) {
254
                case 'register':
255
                    log_info('受注登録開始', [$TargetOrder->getId()]);
256 5
257
                    if (!$flowResult->hasError() && $form->isValid()) {
258 3
                        try {
259
                            $this->purchaseFlow->prepare($TargetOrder, $purchaseContext);
260
                            $this->purchaseFlow->commit($TargetOrder, $purchaseContext);
261
                        } catch (PurchaseException $e) {
262
                            $this->addError($e->getMessage(), 'admin');
263
                            break;
264
                        }
265
266 3
                        $OldStatus = $OriginOrder->getOrderStatus();
267
                        $NewStatus = $TargetOrder->getOrderStatus();
268 3
269
                        // ステータスが変更されている場合はステートマシンを実行.
270
                        if ($TargetOrder->getId() && $OldStatus->getId() != $NewStatus->getId()) {
271 5
                            // 発送済に変更された場合は, 発送日をセットする.
272 5
                            if ($NewStatus->getId() == OrderStatus::DELIVERED) {
273
                                $TargetOrder->getShippings()->map(function (Shipping $Shipping) {
274 5
                                    if (!$Shipping->isShipped()) {
275 3
                                        $Shipping->setShippingDate(new \DateTime());
276 3
                                    }
277
                                });
278
                            }
279 5
                            // ステートマシンでステータスは更新されるので, 古いステータスに戻す.
280
                            $TargetOrder->setOrderStatus($OldStatus);
281
                            // FormTypeでステータスの遷移チェックは行っているのでapplyのみ実行.
282 5
                            $this->orderStateMachine->apply($TargetOrder, $NewStatus);
283 5
                        }
284
285
                        $this->entityManager->persist($TargetOrder);
286 5
                        $this->entityManager->flush();
287 5
288 5
                        foreach ($OriginItems as $Item) {
289
                            if ($TargetOrder->getOrderItems()->contains($Item) === false) {
290
                                $this->entityManager->remove($Item);
291 5
                            }
292
                        }
293 5
                        $this->entityManager->flush();
294 5
295 5
                        // 新規登録時はMySQL対応のためflushしてから採番
296 5
                        $this->orderNoProcessor->process($TargetOrder, $purchaseContext);
297
                        $this->entityManager->flush();
298 5
299
                        // 会員の場合、購入回数、購入金額などを更新
300 5
                        if ($Customer = $TargetOrder->getCustomer()) {
301
                            $this->orderRepository->updateOrderSummary($Customer);
302 5
                            $this->entityManager->flush($Customer);
0 ignored issues
show
The call to EntityManagerInterface::flush() has too many arguments starting with $Customer.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
303
                        }
304 5
305
                        $event = new EventArgs(
306 5
                            [
307
                                'form' => $form,
308
                                'OriginOrder' => $OriginOrder,
309
                                'TargetOrder' => $TargetOrder,
310
                                'Customer' => $Customer,
311
                            ],
312
                            $request
313
                        );
314
                        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_COMPLETE, $event);
315
316 2
                        $this->addSuccess('admin.common.save_complete', 'admin');
317 2
318
                        log_info('受注登録完了', [$TargetOrder->getId()]);
319 2
320 View Code Duplication
                        if ($returnLink = $form->get('return_link')->getData()) {
321 2
                            try {
322 2
                                // $returnLinkはpathの形式で渡される. pathが存在するかをルータでチェックする.
323 2
                                $pattern = '/^'.preg_quote($request->getBasePath(), '/').'/';
324
                                $returnLink = preg_replace($pattern, '', $returnLink);
325 2
                                $result = $router->match($returnLink);
326
                                // パラメータのみ抽出
327 2
                                $params = array_filter($result, function ($key) {
328
                                    return 0 !== \strpos($key, '_');
329 2
                                }, ARRAY_FILTER_USE_KEY);
330
331
                                // pathからurlを再構築してリダイレクト.
332 2
                                return $this->redirectToRoute($result['_route'], $params);
333 2
                            } catch (\Exception $e) {
334
                                // マッチしない場合はログ出力してスキップ.
335 2
                                log_warning('URLの形式が不正です。');
336
                            }
337 2
                        }
338 2
339 2
                        return $this->redirectToRoute('admin_order_edit', ['id' => $TargetOrder->getId()]);
340
                    }
341 2
342
                    break;
343 2
                default:
344
                    break;
345 2
            }
346
        }
347
348 2
        // 会員検索フォーム
349 2
        $builder = $this->formFactory
350 2
            ->createBuilder(SearchCustomerType::class);
351 2
352 2
        $event = new EventArgs(
353 2
            [
354
                'builder' => $builder,
355
                'OriginOrder' => $OriginOrder,
356
                'TargetOrder' => $TargetOrder,
357
            ],
358 2
            $request
359 2
        );
360 2
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_INITIALIZE, $event);
361 2
362 2
        $searchCustomerModalForm = $builder->getForm();
363 2
364
        // 商品検索フォーム
365
        $builder = $this->formFactory
366
            ->createBuilder(SearchProductType::class);
367
368
        $event = new EventArgs(
369
            [
370
                'builder' => $builder,
371
                'OriginOrder' => $OriginOrder,
372
                'TargetOrder' => $TargetOrder,
373
            ],
374
            $request
375
        );
376
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_INITIALIZE, $event);
377
378
        $searchProductModalForm = $builder->getForm();
379 1
380
        // 配送業者のお届け時間
381 1
        $times = [];
382 1
        $deliveries = $this->deliveryRepository->findAll();
383 1 View Code Duplication
        foreach ($deliveries as $Delivery) {
384 1
            $deliveryTimes = $Delivery->getDeliveryTimes();
385
            foreach ($deliveryTimes as $DeliveryTime) {
386 1
                $times[$Delivery->getId()][$DeliveryTime->getId()] = $DeliveryTime->getDeliveryTime();
387 1
            }
388
        }
389
390 1
        return [
391
            'form' => $form->createView(),
392 1
            'searchCustomerModalForm' => $searchCustomerModalForm->createView(),
393
            'searchProductModalForm' => $searchProductModalForm->createView(),
394
            'Order' => $TargetOrder,
395
            'id' => $id,
396 1
            'shippingDeliveryTimes' => $this->serializer->serialize($times, 'json'),
397 1
        ];
398
    }
399
400
    /**
401
     * 顧客情報を検索する.
402
     *
403
     * @Route("/%eccube_admin_route%/order/search/customer/html", name="admin_order_search_customer_html")
404
     * @Route("/%eccube_admin_route%/order/search/customer/html/page/{page_no}", requirements={"page_No" = "\d+"}, name="admin_order_search_customer_html_page")
405
     * @Template("@admin/Order/search_customer.twig")
406
     *
407 1
     * @param Request $request
408
     * @param integer $page_no
409 1
     *
410
     * @return \Symfony\Component\HttpFoundation\JsonResponse
411 1
     */
412 1
    public function searchCustomerHtml(Request $request, $page_no = null, Paginator $paginator)
413
    {
414 1
        if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
415
            log_debug('search customer start.');
416 1
            $page_count = $this->eccubeConfig['eccube_default_page_count'];
417
            $session = $this->session;
418
419 1
            if ('POST' === $request->getMethod()) {
420 1
                $page_no = 1;
421 1
422 1
                $searchData = [
423 1
                    'multi' => $request->get('search_word'),
424
                    'customer_status' => [
425
                        CustomerStatus::REGULAR,
426
                    ],
427 1
                ];
428
429 1
                $session->set('eccube.admin.order.customer.search', $searchData);
430
                $session->set('eccube.admin.order.customer.search.page_no', $page_no);
431
            } else {
432
                $searchData = (array) $session->get('eccube.admin.order.customer.search');
433 1
                if (is_null($page_no)) {
434 1
                    $page_no = intval($session->get('eccube.admin.order.customer.search.page_no'));
435 1
                } else {
436 1
                    $session->set('eccube.admin.order.customer.search.page_no', $page_no);
437 1
                }
438 1
            }
439 1
440 1
            $qb = $this->customerRepository->getQueryBuilderBySearchData($searchData);
441 1
442 1
            $event = new EventArgs(
443
                [
444
                    'qb' => $qb,
445
                    'data' => $searchData,
446 1
                ],
447
                $request
448 1
            );
449 1
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event);
450
451 1
            /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
452
            $pagination = $paginator->paginate(
453 1
                $qb,
454 1
                $page_no,
455
                $page_count,
456
                ['wrap-queries' => true]
457 1
            );
458 1
459
            /** @var $Customers \Eccube\Entity\Customer[] */
460
            $Customers = $pagination->getItems();
461
462
            if (empty($Customers)) {
463
                log_debug('search customer not found.');
464
            }
465
466
            $data = [];
467
            $formatName = '%s%s(%s%s)';
468
            foreach ($Customers as $Customer) {
469
                $data[] = [
470
                    'id' => $Customer->getId(),
471
                    'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(),
472
                        $Customer->getKana01(),
473 1
                        $Customer->getKana02()),
474
                    'phone_number' => $Customer->getPhoneNumber(),
475 1
                    'email' => $Customer->getEmail(),
476 1
                ];
477
            }
478
479 1
            $event = new EventArgs(
480 1
                [
481
                    'data' => $data,
482 1
                    'Customers' => $pagination,
483
                ],
484 1
                $request
485
            );
486 1
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event);
487
            $data = $event->getArgument('data');
488 1
489
            return [
490 1
                'data' => $data,
491
                'pagination' => $pagination,
492
            ];
493
        }
494
    }
495
496 1
    /**
497
     * 顧客情報を検索する.
498
     *
499 1
     * @Route("/%eccube_admin_route%/order/search/customer/id", name="admin_order_search_customer_by_id", methods={"POST"})
500 1
     *
501 1
     * @param Request $request
502 1
     *
503 1
     * @return \Symfony\Component\HttpFoundation\JsonResponse
504 1
     */
505 1
    public function searchCustomerById(Request $request)
506 1
    {
507 1
        if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
508 1
            log_debug('search customer by id start.');
509 1
510 1
            /** @var $Customer \Eccube\Entity\Customer */
511
            $Customer = $this->customerRepository
512
                ->find($request->get('id'));
513 1
514
            $event = new EventArgs(
515 1
                [
516 1
                    'Customer' => $Customer,
517
                ],
518 1
                $request
519
            );
520 1
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_INITIALIZE, $event);
521 1
522
            if (is_null($Customer)) {
523 1
                log_debug('search customer by id not found.');
524
525
                return $this->json([], 404);
526
            }
527
528
            log_debug('search customer by id found.');
529
530
            $data = [
531
                'id' => $Customer->getId(),
532 1
                'name01' => $Customer->getName01(),
533
                'name02' => $Customer->getName02(),
534 1
                'kana01' => $Customer->getKana01(),
535 1
                'kana02' => $Customer->getKana02(),
536 1
                'postal_code' => $Customer->getPostalCode(),
537 1
                'pref' => is_null($Customer->getPref()) ? null : $Customer->getPref()->getId(),
538
                'addr01' => $Customer->getAddr01(),
539 1
                'addr02' => $Customer->getAddr02(),
540 1
                'email' => $Customer->getEmail(),
541
                'phone_number' => $Customer->getPhoneNumber(),
542
                'company_name' => $Customer->getCompanyName(),
543 1
            ];
544
545
            $event = new EventArgs(
546 1
                [
547
                    'data' => $data,
548
                    'Customer' => $Customer,
549
                ],
550
                $request
551 1
            );
552 1
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_COMPLETE, $event);
553
            $data = $event->getArgument('data');
554
555
            return $this->json($data);
556
        }
557
    }
558
559
    /**
560
     * @Route("/%eccube_admin_route%/order/search/product", name="admin_order_search_product")
561
     * @Route("/%eccube_admin_route%/order/search/product/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_order_search_product_page")
562 1
     * @Template("@admin/Order/search_product.twig")
563 1
     */
564
    public function searchProduct(Request $request, $page_no = null, Paginator $paginator)
565 1
    {
566
        if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
567 1
            log_debug('search product start.');
568 1
            $page_count = $this->eccubeConfig['eccube_default_page_count'];
569
            $session = $this->session;
570 1
571
            if ('POST' === $request->getMethod()) {
572 1
                $page_no = 1;
573
574
                $searchData = [
575 1
                    'id' => $request->get('id'),
576 1
                ];
577 1
578 1
                if ($categoryId = $request->get('category_id')) {
579 1
                    $Category = $this->categoryRepository->find($categoryId);
580
                    $searchData['category_id'] = $Category;
581
                }
582
583 1
                $session->set('eccube.admin.order.product.search', $searchData);
584
                $session->set('eccube.admin.order.product.search.page_no', $page_no);
585 1
            } else {
586
                $searchData = (array) $session->get('eccube.admin.order.product.search');
587
                if (is_null($page_no)) {
588
                    $page_no = intval($session->get('eccube.admin.order.product.search.page_no'));
589 1
                } else {
590 1
                    $session->set('eccube.admin.order.product.search.page_no', $page_no);
591
                }
592 1
            }
593 1
594
            $qb = $this->productRepository
595 1
                ->getQueryBuilderBySearchDataForAdmin($searchData);
596 1
597
            $event = new EventArgs(
598
                [
599 1
                    'qb' => $qb,
600
                    'searchData' => $searchData,
601 1
                ],
602 1
                $request
603 1
            );
604
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH, $event);
605 1
606
            /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
607 1
            $pagination = $paginator->paginate(
608
                $qb,
609
                $page_no,
610 1
                $page_count,
611 1
                ['wrap-queries' => true]
612 1
            );
613
614
            /** @var $Products \Eccube\Entity\Product[] */
615
            $Products = $pagination->getItems();
616
617
            if (empty($Products)) {
618
                log_debug('search product not found.');
619
            }
620
621
            $forms = [];
622 View Code Duplication
            foreach ($Products as $Product) {
623
                /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
624
                $builder = $this->formFactory->createNamedBuilder('', AddCartType::class, null, [
625
                    'product' => $this->productRepository->findWithSortedClassCategories($Product->getId()),
626
                ]);
627
                $addCartForm = $builder->getForm();
628
                $forms[$Product->getId()] = $addCartForm->createView();
629
            }
630
631
            $event = new EventArgs(
632
                [
633
                    'forms' => $forms,
634
                    'Products' => $Products,
635
                    'pagination' => $pagination,
636
                ],
637
                $request
638
            );
639
            $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE, $event);
640
641
            return [
642
                'forms' => $forms,
643
                'Products' => $Products,
644
                'pagination' => $pagination,
645
            ];
646
        }
647
    }
648
649
    /**
650
     * その他明細情報を取得
651
     *
652
     * @Route("/%eccube_admin_route%/order/search/order_item_type", name="admin_order_search_order_item_type")
653
     * @Template("@admin/Order/order_item_type.twig")
654
     *
655
     * @param Request $request
656
     *
657
     * @return array
658
     */
659
    public function searchOrderItemType(Request $request)
660
    {
661
        if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
662
            log_debug('search order item type start.');
663
664
            $criteria = Criteria::create();
665
            $criteria
666
                ->where($criteria->expr()->andX(
667
                    $criteria->expr()->neq('id', OrderItemType::PRODUCT),
668
                    $criteria->expr()->neq('id', OrderItemType::TAX),
669
                    $criteria->expr()->neq('id', OrderItemType::POINT)
670
                ))
671
                ->orderBy(['sort_no' => 'ASC']);
672
673
            $OrderItemTypes = $this->orderItemTypeRepository->matching($criteria);
674
675
            $forms = [];
676
            foreach ($OrderItemTypes as $OrderItemType) {
677
                /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
678
                $builder = $this->formFactory->createBuilder();
679
                $form = $builder->getForm();
680
                $forms[$OrderItemType->getId()] = $form->createView();
681
            }
682
683
            return [
684
                'forms' => $forms,
685
                'OrderItemTypes' => $OrderItemTypes,
686
            ];
687
        }
688
    }
689
}
690