src/Eccube/Controller/Admin/Order/EditController.php line 186

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