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.         if ($form->isSubmitted() && $form['OrderItems']->isValid()) {
  200.             $event = new EventArgs(
  201.                 [
  202.                     'builder' => $builder,
  203.                     'OriginOrder' => $OriginOrder,
  204.                     'TargetOrder' => $TargetOrder,
  205.                     'PurchaseContext' => $purchaseContext,
  206.                 ],
  207.                 $request
  208.             );
  209.             $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS);
  210.             $flowResult $this->purchaseFlow->validate($TargetOrder$purchaseContext);
  211.             if ($flowResult->hasWarning()) {
  212.                 foreach ($flowResult->getWarning() as $warning) {
  213.                     $this->addWarning($warning->getMessage(), 'admin');
  214.                 }
  215.             }
  216.             if ($flowResult->hasError()) {
  217.                 foreach ($flowResult->getErrors() as $error) {
  218.                     $this->addError($error->getMessage(), 'admin');
  219.                 }
  220.             }
  221.             // 登録ボタン押下
  222.             switch ($request->get('mode')) {
  223.                 case 'register':
  224.                     log_info('受注登録開始', [$TargetOrder->getId()]);
  225.                     if (!$flowResult->hasError() && $form->isValid()) {
  226.                         try {
  227.                             $this->purchaseFlow->prepare($TargetOrder$purchaseContext);
  228.                             $this->purchaseFlow->commit($TargetOrder$purchaseContext);
  229.                         } catch (PurchaseException $e) {
  230.                             $this->addError($e->getMessage(), 'admin');
  231.                             break;
  232.                         }
  233.                         $OldStatus $OriginOrder->getOrderStatus();
  234.                         $NewStatus $TargetOrder->getOrderStatus();
  235.                         // ステータスが変更されている場合はステートマシンを実行.
  236.                         if ($TargetOrder->getId() && $OldStatus->getId() != $NewStatus->getId()) {
  237.                             // 発送済に変更された場合は, 発送日をセットする.
  238.                             if ($NewStatus->getId() == OrderStatus::DELIVERED) {
  239.                                 $TargetOrder->getShippings()->map(function (Shipping $Shipping) {
  240.                                     if (!$Shipping->isShipped()) {
  241.                                         $Shipping->setShippingDate(new \DateTime());
  242.                                     }
  243.                                 });
  244.                             }
  245.                             // ステートマシンでステータスは更新されるので, 古いステータスに戻す.
  246.                             $TargetOrder->setOrderStatus($OldStatus);
  247.                             try {
  248.                                 // FormTypeでステータスの遷移チェックは行っているのでapplyのみ実行.
  249.                                 $this->orderStateMachine->apply($TargetOrder$NewStatus);
  250.                             } catch (ShoppingException $e) {
  251.                                 $this->addError($e->getMessage(), 'admin');
  252.                                 break;
  253.                             }
  254.                         }
  255.                         $this->entityManager->persist($TargetOrder);
  256.                         $this->entityManager->flush();
  257.                         foreach ($OriginItems as $Item) {
  258.                             if ($TargetOrder->getOrderItems()->contains($Item) === false) {
  259.                                 $this->entityManager->remove($Item);
  260.                             }
  261.                         }
  262.                         $this->entityManager->flush();
  263.                         // 新規登録時はMySQL対応のためflushしてから採番
  264.                         $this->orderNoProcessor->process($TargetOrder$purchaseContext);
  265.                         $this->entityManager->flush();
  266.                         // 会員の場合、購入回数、購入金額などを更新
  267.                         if ($Customer $TargetOrder->getCustomer()) {
  268.                             $this->orderRepository->updateOrderSummary($Customer);
  269.                             $this->entityManager->flush();
  270.                         }
  271.                         $event = new EventArgs(
  272.                             [
  273.                                 'form' => $form,
  274.                                 'OriginOrder' => $OriginOrder,
  275.                                 'TargetOrder' => $TargetOrder,
  276.                                 'Customer' => $Customer,
  277.                             ],
  278.                             $request
  279.                         );
  280.                         $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ORDER_EDIT_INDEX_COMPLETE);
  281.                         $this->addSuccess('admin.common.save_complete''admin');
  282.                         log_info('受注登録完了', [$TargetOrder->getId()]);
  283.                         if ($returnLink $form->get('return_link')->getData()) {
  284.                             try {
  285.                                 // $returnLinkはpathの形式で渡される. pathが存在するかをルータでチェックする.
  286.                                 $pattern '/^'.preg_quote($request->getBasePath(), '/').'/';
  287.                                 $returnLink preg_replace($pattern''$returnLink);
  288.                                 $result $router->match($returnLink);
  289.                                 // パラメータのみ抽出
  290.                                 $params array_filter($result, function ($key) {
  291.                                     return !== \strpos($key'_');
  292.                                 }, ARRAY_FILTER_USE_KEY);
  293.                                 // pathからurlを再構築してリダイレクト.
  294.                                 return $this->redirectToRoute($result['_route'], $params);
  295.                             } catch (\Exception $e) {
  296.                                 // マッチしない場合はログ出力してスキップ.
  297.                                 log_warning('URLの形式が不正です。');
  298.                             }
  299.                         }
  300.                         return $this->redirectToRoute('admin_order_edit', ['id' => $TargetOrder->getId()]);
  301.                     }
  302.                     break;
  303.                 default:
  304.                     break;
  305.             }
  306.         }
  307.         // 会員検索フォーム
  308.         $builder $this->formFactory
  309.             ->createBuilder(SearchCustomerType::class);
  310.         $event = new EventArgs(
  311.             [
  312.                 'builder' => $builder,
  313.                 'OriginOrder' => $OriginOrder,
  314.                 'TargetOrder' => $TargetOrder,
  315.             ],
  316.             $request
  317.         );
  318.         $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_INITIALIZE);
  319.         $searchCustomerModalForm $builder->getForm();
  320.         // 商品検索フォーム
  321.         $builder $this->formFactory
  322.             ->createBuilder(SearchProductType::class);
  323.         $event = new EventArgs(
  324.             [
  325.                 'builder' => $builder,
  326.                 'OriginOrder' => $OriginOrder,
  327.                 'TargetOrder' => $TargetOrder,
  328.             ],
  329.             $request
  330.         );
  331.         $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_INITIALIZE);
  332.         $searchProductModalForm $builder->getForm();
  333.         // 配送業者のお届け時間
  334.         $times = [];
  335.         $deliveries $this->deliveryRepository->findAll();
  336.         foreach ($deliveries as $Delivery) {
  337.             $deliveryTimes $Delivery->getDeliveryTimes();
  338.             foreach ($deliveryTimes as $DeliveryTime) {
  339.                 $times[$Delivery->getId()][$DeliveryTime->getId()] = $DeliveryTime->getDeliveryTime();
  340.             }
  341.         }
  342.         return [
  343.             'form' => $form->createView(),
  344.             'searchCustomerModalForm' => $searchCustomerModalForm->createView(),
  345.             'searchProductModalForm' => $searchProductModalForm->createView(),
  346.             'Order' => $TargetOrder,
  347.             'id' => $id,
  348.             'shippingDeliveryTimes' => $this->serializer->serialize($times'json'),
  349.         ];
  350.     }
  351.     /**
  352.      * 顧客情報を検索する.
  353.      *
  354.      * @Route("/%eccube_admin_route%/order/search/customer/html", name="admin_order_search_customer_html", methods={"GET", "POST"})
  355.      * @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"})
  356.      * @Template("@admin/Order/search_customer.twig")
  357.      *
  358.      * @param Request $request
  359.      * @param integer $page_no
  360.      *
  361.      * @return array
  362.      */
  363.     public function searchCustomerHtml(Request $requestPaginatorInterface $paginator$page_no null)
  364.     {
  365.         if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
  366.             log_debug('search customer start.');
  367.             $page_count $this->eccubeConfig['eccube_default_page_count'];
  368.             $session $this->session;
  369.             if ('POST' === $request->getMethod()) {
  370.                 $page_no 1;
  371.                 $searchData = [
  372.                     'multi' => $request->get('search_word'),
  373.                     'customer_status' => [
  374.                         CustomerStatus::REGULAR,
  375.                     ],
  376.                 ];
  377.                 $session->set('eccube.admin.order.customer.search'$searchData);
  378.                 $session->set('eccube.admin.order.customer.search.page_no'$page_no);
  379.             } else {
  380.                 $searchData = (array) $session->get('eccube.admin.order.customer.search');
  381.                 if (is_null($page_no)) {
  382.                     $page_no intval($session->get('eccube.admin.order.customer.search.page_no'));
  383.                 } else {
  384.                     $session->set('eccube.admin.order.customer.search.page_no'$page_no);
  385.                 }
  386.             }
  387.             $qb $this->customerRepository->getQueryBuilderBySearchData($searchData);
  388.             $event = new EventArgs(
  389.                 [
  390.                     'qb' => $qb,
  391.                     'data' => $searchData,
  392.                 ],
  393.                 $request
  394.             );
  395.             $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH);
  396.             /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
  397.             $pagination $paginator->paginate(
  398.                 $qb,
  399.                 $page_no,
  400.                 $page_count,
  401.                 ['wrap-queries' => true]
  402.             );
  403.             /** @var $Customers \Eccube\Entity\Customer[] */
  404.             $Customers $pagination->getItems();
  405.             if (empty($Customers)) {
  406.                 log_debug('search customer not found.');
  407.             }
  408.             $data = [];
  409.             $formatName '%s%s(%s%s)';
  410.             foreach ($Customers as $Customer) {
  411.                 $data[] = [
  412.                     'id' => $Customer->getId(),
  413.                     'name' => sprintf($formatName$Customer->getName01(), $Customer->getName02(),
  414.                         $Customer->getKana01(),
  415.                         $Customer->getKana02()),
  416.                     'phone_number' => $Customer->getPhoneNumber(),
  417.                     'email' => $Customer->getEmail(),
  418.                 ];
  419.             }
  420.             $event = new EventArgs(
  421.                 [
  422.                     'data' => $data,
  423.                     'Customers' => $pagination,
  424.                 ],
  425.                 $request
  426.             );
  427.             $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE);
  428.             $data $event->getArgument('data');
  429.             return [
  430.                 'data' => $data,
  431.                 'pagination' => $pagination,
  432.             ];
  433.         }
  434.         throw new BadRequestHttpException();
  435.     }
  436.     /**
  437.      * 顧客情報を検索する.
  438.      *
  439.      * @Route("/%eccube_admin_route%/order/search/customer/id", name="admin_order_search_customer_by_id", methods={"POST"})
  440.      *
  441.      * @param Request $request
  442.      *
  443.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  444.      */
  445.     public function searchCustomerById(Request $request)
  446.     {
  447.         if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
  448.             log_debug('search customer by id start.');
  449.             /** @var $Customer \Eccube\Entity\Customer */
  450.             $Customer $this->customerRepository
  451.                 ->find($request->get('id'));
  452.             $event = new EventArgs(
  453.                 [
  454.                     'Customer' => $Customer,
  455.                 ],
  456.                 $request
  457.             );
  458.             $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_INITIALIZE);
  459.             if (is_null($Customer)) {
  460.                 log_debug('search customer by id not found.');
  461.                 return $this->json([], 404);
  462.             }
  463.             log_debug('search customer by id found.');
  464.             $data = [
  465.                 'id' => $Customer->getId(),
  466.                 'name01' => $Customer->getName01(),
  467.                 'name02' => $Customer->getName02(),
  468.                 'kana01' => $Customer->getKana01(),
  469.                 'kana02' => $Customer->getKana02(),
  470.                 'postal_code' => $Customer->getPostalCode(),
  471.                 'pref' => is_null($Customer->getPref()) ? null $Customer->getPref()->getId(),
  472.                 'addr01' => $Customer->getAddr01(),
  473.                 'addr02' => $Customer->getAddr02(),
  474.                 'email' => $Customer->getEmail(),
  475.                 'phone_number' => $Customer->getPhoneNumber(),
  476.                 'company_name' => $Customer->getCompanyName(),
  477.             ];
  478.             $event = new EventArgs(
  479.                 [
  480.                     'data' => $data,
  481.                     'Customer' => $Customer,
  482.                 ],
  483.                 $request
  484.             );
  485.             $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_COMPLETE);
  486.             $data $event->getArgument('data');
  487.             return $this->json($data);
  488.         }
  489.         throw new BadRequestHttpException();
  490.     }
  491.     /**
  492.      * @Route("/%eccube_admin_route%/order/search/product", name="admin_order_search_product", methods={"GET", "POST"})
  493.      * @Route("/%eccube_admin_route%/order/search/product/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_order_search_product_page", methods={"GET", "POST"})
  494.      * @Template("@admin/Order/search_product.twig")
  495.      */
  496.     public function searchProduct(Request $requestPaginatorInterface $paginator$page_no null)
  497.     {
  498.         if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
  499.             log_debug('search product start.');
  500.             $page_count $this->eccubeConfig['eccube_default_page_count'];
  501.             $session $this->session;
  502.             if ('POST' === $request->getMethod()) {
  503.                 $page_no 1;
  504.                 $searchData = [
  505.                     'id' => $request->get('id'),
  506.                 ];
  507.                 if ($categoryId $request->get('category_id')) {
  508.                     $Category $this->categoryRepository->find($categoryId);
  509.                     $searchData['category_id'] = $Category;
  510.                 }
  511.                 $session->set('eccube.admin.order.product.search'$searchData);
  512.                 $session->set('eccube.admin.order.product.search.page_no'$page_no);
  513.             } else {
  514.                 $searchData = (array) $session->get('eccube.admin.order.product.search');
  515.                 if (is_null($page_no)) {
  516.                     $page_no intval($session->get('eccube.admin.order.product.search.page_no'));
  517.                 } else {
  518.                     $session->set('eccube.admin.order.product.search.page_no'$page_no);
  519.                 }
  520.             }
  521.             $qb $this->productRepository
  522.                 ->getQueryBuilderBySearchDataForAdmin($searchData);
  523.             $event = new EventArgs(
  524.                 [
  525.                     'qb' => $qb,
  526.                     'searchData' => $searchData,
  527.                 ],
  528.                 $request
  529.             );
  530.             $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH);
  531.             /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
  532.             $pagination $paginator->paginate(
  533.                 $qb,
  534.                 $page_no,
  535.                 $page_count,
  536.                 ['wrap-queries' => true]
  537.             );
  538.             /** @var $Products \Eccube\Entity\Product[] */
  539.             $Products $pagination->getItems();
  540.             if (empty($Products)) {
  541.                 log_debug('search product not found.');
  542.             }
  543.             $forms = [];
  544.             foreach ($Products as $Product) {
  545.                 /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  546.                 $builder $this->formFactory->createNamedBuilder(''AddCartType::class, null, [
  547.                     'product' => $Product,
  548.                 ]);
  549.                 $addCartForm $builder->getForm();
  550.                 $forms[$Product->getId()] = $addCartForm->createView();
  551.             }
  552.             $event = new EventArgs(
  553.                 [
  554.                     'forms' => $forms,
  555.                     'Products' => $Products,
  556.                     'pagination' => $pagination,
  557.                 ],
  558.                 $request
  559.             );
  560.             $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE);
  561.             return [
  562.                 'forms' => $forms,
  563.                 'Products' => $Products,
  564.                 'pagination' => $pagination,
  565.             ];
  566.         }
  567.     }
  568.     /**
  569.      * その他明細情報を取得
  570.      *
  571.      * @Route("/%eccube_admin_route%/order/search/order_item_type", name="admin_order_search_order_item_type", methods={"POST"})
  572.      * @Template("@admin/Order/order_item_type.twig")
  573.      *
  574.      * @param Request $request
  575.      *
  576.      * @return array
  577.      */
  578.     public function searchOrderItemType(Request $request)
  579.     {
  580.         if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
  581.             log_debug('search order item type start.');
  582.             $Charge $this->entityManager->find(OrderItemType::class, OrderItemType::CHARGE);
  583.             $DeliveryFee $this->entityManager->find(OrderItemType::class, OrderItemType::DELIVERY_FEE);
  584.             $Discount $this->entityManager->find(OrderItemType::class, OrderItemType::DISCOUNT);
  585.             $NonTaxable $this->entityManager->find(TaxType::class, TaxType::NON_TAXABLE);
  586.             $Taxation $this->entityManager->find(TaxType::class, TaxType::TAXATION);
  587.             $OrderItemTypes = [
  588.                 ['OrderItemType' => $Charge'TaxType' => $Taxation],
  589.                 ['OrderItemType' => $DeliveryFee'TaxType' => $Taxation],
  590.                 ['OrderItemType' => $Discount'TaxType' => $Taxation],
  591.                 ['OrderItemType' => $Discount'TaxType' => $NonTaxable],
  592.             ];
  593.             return [
  594.                 'OrderItemTypes' => $OrderItemTypes,
  595.             ];
  596.         }
  597.         throw new BadRequestHttpException();
  598.     }
  599. }