app/Customize/Controller/Admin/Order/EditControllerCustomizer.php line 86

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 Customize\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 Eccube\Controller\Admin\Order\EditController;
  53. class EditControllerCustomizer extends EditController
  54. {
  55.     /**
  56.      * @Route("/%eccube_admin_route%/order/search/product", name="admin_order_search_product", methods={"GET", "POST"})
  57.      * @Route("/%eccube_admin_route%/order/search/product/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_order_search_product_page", methods={"GET", "POST"})
  58.      * @Template("@admin/Order/search_product.twig")
  59.      */
  60.     public function searchProduct(Request $requestPaginatorInterface $paginator$page_no null)
  61.     {
  62.         if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
  63.             log_debug('search product start.');
  64.             $page_count $this->eccubeConfig['eccube_default_page_count'];
  65.             $session $this->session;
  66.             if ('POST' === $request->getMethod()) {
  67.                 $page_no 1;
  68.                 $searchData = [
  69.                     'id' => $request->get('id'),
  70.                 ];
  71.                 if ($categoryId $request->get('category_id')) {
  72.                     $Category $this->categoryRepository->find($categoryId);
  73.                     $searchData['category_id'] = $Category;
  74.                 }
  75.                 
  76.                 // この一行のみ追加
  77.                 $searchData['word'] = $request->get('word');
  78.                 $session->set('eccube.admin.order.product.search'$searchData);
  79.                 $session->set('eccube.admin.order.product.search.page_no'$page_no);
  80.             } else {
  81.                 $searchData = (array) $session->get('eccube.admin.order.product.search');
  82.                 if (is_null($page_no)) {
  83.                     $page_no intval($session->get('eccube.admin.order.product.search.page_no'));
  84.                 } else {
  85.                     $session->set('eccube.admin.order.product.search.page_no'$page_no);
  86.                 }
  87.             }
  88.             $qb $this->productRepository
  89.                 ->getQueryBuilderBySearchDataForAdmin($searchData);
  90.             $event = new EventArgs(
  91.                 [
  92.                     'qb' => $qb,
  93.                     'searchData' => $searchData,
  94.                 ],
  95.                 $request
  96.             );
  97.             $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH);
  98.             /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
  99.             $pagination $paginator->paginate(
  100.                 $qb,
  101.                 $page_no,
  102.                 $page_count,
  103.                 ['wrap-queries' => true]
  104.             );
  105.             /** @var $Products \Eccube\Entity\Product[] */
  106.             $Products $pagination->getItems();
  107.             if (empty($Products)) {
  108.                 log_debug('search product not found.');
  109.             }
  110.             $forms = [];
  111.             foreach ($Products as $Product) {
  112.                 /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  113.                 $builder $this->formFactory->createNamedBuilder(''AddCartType::class, null, [
  114.                     'product' => $Product,
  115.                 ]);
  116.                 $addCartForm $builder->getForm();
  117.                 $forms[$Product->getId()] = $addCartForm->createView();
  118.             }
  119.             $event = new EventArgs(
  120.                 [
  121.                     'forms' => $forms,
  122.                     'Products' => $Products,
  123.                     'pagination' => $pagination,
  124.                 ],
  125.                 $request
  126.             );
  127.             $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE);
  128.             return [
  129.                 'forms' => $forms,
  130.                 'Products' => $Products,
  131.                 'pagination' => $pagination,
  132.             ];
  133.         }
  134.     }
  135. }