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

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