<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Controller\Admin\Order;
use Doctrine\Common\Collections\ArrayCollection;
use Eccube\Controller\AbstractController;
use Eccube\Entity\Master\CustomerStatus;
use Eccube\Entity\Master\OrderItemType;
use Eccube\Entity\Master\OrderStatus;
use Eccube\Entity\Master\TaxType;
use Eccube\Entity\Order;
use Eccube\Entity\Shipping;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Exception\ShoppingException;
use Eccube\Form\Type\AddCartType;
use Eccube\Form\Type\Admin\OrderType;
use Eccube\Form\Type\Admin\SearchCustomerType;
use Eccube\Form\Type\Admin\SearchProductType;
use Eccube\Repository\CategoryRepository;
use Eccube\Repository\CustomerRepository;
use Eccube\Repository\DeliveryRepository;
use Eccube\Repository\Master\DeviceTypeRepository;
use Eccube\Repository\Master\OrderItemTypeRepository;
use Eccube\Repository\Master\OrderStatusRepository;
use Eccube\Repository\OrderRepository;
use Eccube\Repository\ProductRepository;
use Eccube\Service\OrderHelper;
use Eccube\Service\OrderStateMachine;
use Eccube\Service\PurchaseFlow\Processor\OrderNoProcessor;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\PurchaseFlow\PurchaseException;
use Eccube\Service\PurchaseFlow\PurchaseFlow;
use Eccube\Service\TaxRuleService;
use Knp\Component\Pager\PaginatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerInterface;
use Eccube\Controller\Admin\Order\EditController;
class EditControllerCustomizer extends EditController
{
/**
* @Route("/%eccube_admin_route%/order/search/product", name="admin_order_search_product", methods={"GET", "POST"})
* @Route("/%eccube_admin_route%/order/search/product/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_order_search_product_page", methods={"GET", "POST"})
* @Template("@admin/Order/search_product.twig")
*/
public function searchProduct(Request $request, PaginatorInterface $paginator, $page_no = null)
{
if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
log_debug('search product start.');
$page_count = $this->eccubeConfig['eccube_default_page_count'];
$session = $this->session;
if ('POST' === $request->getMethod()) {
$page_no = 1;
$searchData = [
'id' => $request->get('id'),
];
if ($categoryId = $request->get('category_id')) {
$Category = $this->categoryRepository->find($categoryId);
$searchData['category_id'] = $Category;
}
// この一行のみ追加
$searchData['word'] = $request->get('word');
$session->set('eccube.admin.order.product.search', $searchData);
$session->set('eccube.admin.order.product.search.page_no', $page_no);
} else {
$searchData = (array) $session->get('eccube.admin.order.product.search');
if (is_null($page_no)) {
$page_no = intval($session->get('eccube.admin.order.product.search.page_no'));
} else {
$session->set('eccube.admin.order.product.search.page_no', $page_no);
}
}
$qb = $this->productRepository
->getQueryBuilderBySearchDataForAdmin($searchData);
$event = new EventArgs(
[
'qb' => $qb,
'searchData' => $searchData,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH);
/** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
$pagination = $paginator->paginate(
$qb,
$page_no,
$page_count,
['wrap-queries' => true]
);
/** @var $Products \Eccube\Entity\Product[] */
$Products = $pagination->getItems();
if (empty($Products)) {
log_debug('search product not found.');
}
$forms = [];
foreach ($Products as $Product) {
/* @var $builder \Symfony\Component\Form\FormBuilderInterface */
$builder = $this->formFactory->createNamedBuilder('', AddCartType::class, null, [
'product' => $Product,
]);
$addCartForm = $builder->getForm();
$forms[$Product->getId()] = $addCartForm->createView();
}
$event = new EventArgs(
[
'forms' => $forms,
'Products' => $Products,
'pagination' => $pagination,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE);
return [
'forms' => $forms,
'Products' => $Products,
'pagination' => $pagination,
];
}
}
}