EC-CUBE /
ec-cube
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of EC-CUBE |
||
| 5 | * |
||
| 6 | * Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
||
| 7 | * |
||
| 8 | * http://www.lockon.co.jp/ |
||
| 9 | * |
||
| 10 | * For the full copyright and license information, please view the LICENSE |
||
| 11 | * file that was distributed with this source code. |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace Eccube\Controller\Admin\Order; |
||
| 15 | |||
| 16 | use Doctrine\Common\Collections\ArrayCollection; |
||
| 17 | use Doctrine\Common\Collections\Criteria; |
||
| 18 | use Eccube\Controller\AbstractController; |
||
| 19 | use Eccube\Entity\Customer; |
||
| 20 | use Eccube\Entity\Master\CustomerStatus; |
||
| 21 | use Eccube\Entity\Master\DeviceType; |
||
| 22 | use Eccube\Entity\Master\OrderItemType; |
||
| 23 | use Eccube\Entity\Master\OrderStatus; |
||
| 24 | use Eccube\Entity\Order; |
||
| 25 | use Eccube\Entity\Shipping; |
||
| 26 | use Eccube\Event\EccubeEvents; |
||
| 27 | use Eccube\Event\EventArgs; |
||
| 28 | use Eccube\Form\Type\AddCartType; |
||
| 29 | use Eccube\Form\Type\Admin\OrderType; |
||
| 30 | use Eccube\Form\Type\Admin\SearchCustomerType; |
||
| 31 | use Eccube\Form\Type\Admin\SearchProductType; |
||
| 32 | use Eccube\Repository\CategoryRepository; |
||
| 33 | use Eccube\Repository\CustomerRepository; |
||
| 34 | use Eccube\Repository\DeliveryRepository; |
||
| 35 | use Eccube\Repository\Master\DeviceTypeRepository; |
||
| 36 | use Eccube\Repository\Master\OrderItemTypeRepository; |
||
| 37 | use Eccube\Repository\OrderRepository; |
||
| 38 | use Eccube\Repository\ProductRepository; |
||
| 39 | use Eccube\Service\PurchaseFlow\Processor\OrderNoProcessor; |
||
| 40 | use Eccube\Service\PurchaseFlow\PurchaseContext; |
||
| 41 | use Eccube\Service\PurchaseFlow\PurchaseException; |
||
| 42 | use Eccube\Service\PurchaseFlow\PurchaseFlow; |
||
| 43 | use Eccube\Service\TaxRuleService; |
||
| 44 | use Knp\Component\Pager\Paginator; |
||
| 45 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
||
| 46 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
||
| 47 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
||
| 48 | use Symfony\Component\HttpFoundation\Request; |
||
| 49 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
||
| 50 | use Symfony\Component\Serializer\Serializer; |
||
| 51 | use Symfony\Component\Serializer\SerializerInterface; |
||
| 52 | |||
| 53 | class EditController extends AbstractController |
||
| 54 | { |
||
| 55 | /** |
||
| 56 | * @var TaxRuleService |
||
| 57 | */ |
||
| 58 | protected $taxRuleService; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var DeviceTypeRepository |
||
| 62 | */ |
||
| 63 | protected $deviceTypeRepository; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var ProductRepository |
||
| 67 | */ |
||
| 68 | protected $productRepository; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var CategoryRepository |
||
| 72 | */ |
||
| 73 | protected $categoryRepository; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var CustomerRepository |
||
| 77 | */ |
||
| 78 | protected $customerRepository; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var Serializer |
||
| 82 | */ |
||
| 83 | protected $serializer; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var DeliveryRepository |
||
| 87 | */ |
||
| 88 | protected $deliveryRepository; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var PurchaseFlow |
||
| 92 | */ |
||
| 93 | protected $purchaseFlow; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var OrderRepository |
||
| 97 | */ |
||
| 98 | protected $orderRepository; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @var OrderNoProcessor |
||
| 102 | */ |
||
| 103 | protected $orderNoProcessor; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @var OrderItemTypeRepository |
||
| 107 | */ |
||
| 108 | protected $orderItemTypeRepository; |
||
| 109 | |||
| 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 | */ |
||
| 124 | 11 | public function __construct( |
|
| 125 | TaxRuleService $taxRuleService, |
||
| 126 | DeviceTypeRepository $deviceTypeRepository, |
||
| 127 | ProductRepository $productRepository, |
||
| 128 | CategoryRepository $categoryRepository, |
||
| 129 | CustomerRepository $customerRepository, |
||
| 130 | SerializerInterface $serializer, |
||
| 131 | DeliveryRepository $deliveryRepository, |
||
| 132 | PurchaseFlow $orderPurchaseFlow, |
||
| 133 | OrderRepository $orderRepository, |
||
| 134 | OrderNoProcessor $orderNoProcessor, |
||
| 135 | OrderItemTypeRepository $orderItemTypeRepository |
||
| 136 | ) { |
||
| 137 | 11 | $this->taxRuleService = $taxRuleService; |
|
| 138 | 11 | $this->deviceTypeRepository = $deviceTypeRepository; |
|
| 139 | 11 | $this->productRepository = $productRepository; |
|
| 140 | 11 | $this->categoryRepository = $categoryRepository; |
|
| 141 | 11 | $this->customerRepository = $customerRepository; |
|
| 142 | 11 | $this->serializer = $serializer; |
|
| 143 | 11 | $this->deliveryRepository = $deliveryRepository; |
|
| 144 | 11 | $this->purchaseFlow = $orderPurchaseFlow; |
|
| 145 | 11 | $this->orderRepository = $orderRepository; |
|
| 146 | 11 | $this->orderNoProcessor = $orderNoProcessor; |
|
| 147 | 11 | $this->orderItemTypeRepository = $orderItemTypeRepository; |
|
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * 受注登録/編集画面. |
||
| 152 | * |
||
| 153 | * @Route("/%eccube_admin_route%/order/new", name="admin_order_new") |
||
| 154 | * @Route("/%eccube_admin_route%/order/{id}/edit", requirements={"id" = "\d+"}, name="admin_order_edit") |
||
| 155 | * @Template("@admin/Order/edit.twig") |
||
| 156 | */ |
||
| 157 | 7 | public function index(Request $request, $id = null) |
|
| 158 | { |
||
| 159 | 7 | $TargetOrder = null; |
|
| 160 | 7 | $OriginOrder = null; |
|
| 161 | 7 | $isNewOrder = false; |
|
|
0 ignored issues
–
show
|
|||
| 162 | |||
| 163 | 7 | if (is_null($id)) { |
|
| 164 | // 空のエンティティを作成. |
||
| 165 | 3 | $TargetOrder = $this->newOrder(); |
|
| 166 | 3 | $isNewOrder = true; |
|
|
0 ignored issues
–
show
$isNewOrder is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 167 | } else { |
||
| 168 | 4 | $TargetOrder = $this->orderRepository->find($id); |
|
| 169 | 4 | if (is_null($TargetOrder)) { |
|
| 170 | throw new NotFoundHttpException(); |
||
| 171 | } |
||
| 172 | } |
||
| 173 | |||
| 174 | // 編集前の受注情報を保持 |
||
| 175 | 7 | $OriginOrder = clone $TargetOrder; |
|
| 176 | 7 | $OriginItems = new ArrayCollection(); |
|
| 177 | 7 | foreach ($TargetOrder->getOrderItems() as $Item) { |
|
| 178 | 4 | $OriginItems->add($Item); |
|
| 179 | } |
||
| 180 | |||
| 181 | 7 | $builder = $this->formFactory |
|
| 182 | 7 | ->createBuilder(OrderType::class, $TargetOrder, |
|
| 183 | [ |
||
| 184 | 7 | 'SortedItems' => $TargetOrder->getItems(), |
|
| 185 | ] |
||
| 186 | ); |
||
| 187 | |||
| 188 | // 複数配送の場合は配送先の編集ができない |
||
| 189 | 7 | if ($TargetOrder->isMultiple()) { |
|
| 190 | $builder->remove('Shipping'); |
||
| 191 | } |
||
| 192 | |||
| 193 | 7 | $event = new EventArgs( |
|
| 194 | [ |
||
| 195 | 7 | 'builder' => $builder, |
|
| 196 | 7 | 'OriginOrder' => $OriginOrder, |
|
| 197 | 7 | 'TargetOrder' => $TargetOrder, |
|
| 198 | ], |
||
| 199 | 7 | $request |
|
| 200 | ); |
||
| 201 | 7 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_INITIALIZE, $event); |
|
| 202 | |||
| 203 | 7 | $form = $builder->getForm(); |
|
| 204 | |||
| 205 | // 単数配送の場合は配送先の編集ができる |
||
| 206 | 7 | if ($TargetOrder->isMultiple() == false) { |
|
| 207 | 7 | $form['Shipping']->setData($TargetOrder->getShippings()[0]); |
|
| 208 | } |
||
| 209 | |||
| 210 | 7 | $form->handleRequest($request); |
|
| 211 | 7 | $purchaseContext = new PurchaseContext($OriginOrder, $OriginOrder->getCustomer()); |
|
| 212 | |||
| 213 | 7 | if ($form->isSubmitted()) { |
|
| 214 | 5 | $event = new EventArgs( |
|
| 215 | [ |
||
| 216 | 5 | 'builder' => $builder, |
|
| 217 | 5 | 'OriginOrder' => $OriginOrder, |
|
| 218 | 5 | 'TargetOrder' => $TargetOrder, |
|
| 219 | 5 | 'PurchaseContext' => $purchaseContext, |
|
| 220 | ], |
||
| 221 | 5 | $request |
|
| 222 | ); |
||
| 223 | 5 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event); |
|
| 224 | |||
| 225 | 5 | $flowResult = $this->purchaseFlow->validate($TargetOrder, $purchaseContext); |
|
| 226 | 5 | if ($flowResult->hasWarning()) { |
|
| 227 | 3 | foreach ($flowResult->getWarning() as $warning) { |
|
| 228 | // TODO Warning の場合の処理 |
||
| 229 | 3 | $this->addWarning($warning->getMessage(), 'admin'); |
|
| 230 | } |
||
| 231 | } |
||
| 232 | |||
| 233 | 5 | if ($flowResult->hasError()) { |
|
| 234 | foreach ($flowResult->getErrors() as $error) { |
||
| 235 | $this->addError($error->getMessage(), 'admin'); |
||
| 236 | } |
||
| 237 | } |
||
| 238 | |||
| 239 | // 登録ボタン押下 |
||
| 240 | 5 | switch ($request->get('mode')) { |
|
| 241 | case 'register': |
||
| 242 | 5 | log_info('受注登録開始', [$TargetOrder->getId()]); |
|
| 243 | |||
| 244 | 5 | if ($flowResult->hasError() === false && $form->isValid()) { |
|
| 245 | try { |
||
| 246 | 5 | $this->purchaseFlow->prepare($TargetOrder, $purchaseContext); |
|
| 247 | 5 | $this->purchaseFlow->commit($TargetOrder, $purchaseContext); |
|
| 248 | } catch (PurchaseException $e) { |
||
| 249 | $this->addError($e->getMessage(), 'admin'); |
||
| 250 | break; |
||
| 251 | } |
||
| 252 | |||
| 253 | 5 | $this->entityManager->persist($TargetOrder); |
|
| 254 | 5 | $this->entityManager->flush(); |
|
| 255 | |||
| 256 | 5 | foreach ($OriginItems as $Item) { |
|
| 257 | 3 | if ($TargetOrder->getOrderItems()->contains($Item) === false) { |
|
| 258 | 3 | $this->entityManager->remove($Item); |
|
| 259 | } |
||
| 260 | } |
||
| 261 | 5 | $this->entityManager->flush(); |
|
| 262 | |||
| 263 | // 新規登録時はMySQL対応のためflushしてから採番 |
||
| 264 | 5 | $this->orderNoProcessor->process($TargetOrder, $purchaseContext); |
|
| 265 | 5 | $this->entityManager->flush(); |
|
| 266 | |||
| 267 | // 会員の場合、購入回数、購入金額などを更新 |
||
| 268 | 5 | if ($Customer = $TargetOrder->getCustomer()) { |
|
| 269 | 5 | $this->orderRepository->updateOrderSummary($Customer); |
|
| 270 | 5 | $this->entityManager->flush($Customer); |
|
|
0 ignored issues
–
show
The call to
EntityManagerInterface::flush() has too many arguments starting with $Customer.
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the Loading history...
|
|||
| 271 | } |
||
| 272 | |||
| 273 | 5 | $event = new EventArgs( |
|
| 274 | [ |
||
| 275 | 5 | 'form' => $form, |
|
| 276 | 5 | 'OriginOrder' => $OriginOrder, |
|
| 277 | 5 | 'TargetOrder' => $TargetOrder, |
|
| 278 | 5 | 'Customer' => $Customer, |
|
| 279 | ], |
||
| 280 | 5 | $request |
|
| 281 | ); |
||
| 282 | 5 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_COMPLETE, $event); |
|
| 283 | |||
| 284 | 5 | $this->addSuccess('admin.order.save.complete', 'admin'); |
|
| 285 | |||
| 286 | 5 | log_info('受注登録完了', [$TargetOrder->getId()]); |
|
| 287 | |||
| 288 | 5 | return $this->redirectToRoute('admin_order_edit', ['id' => $TargetOrder->getId()]); |
|
| 289 | } |
||
| 290 | |||
| 291 | break; |
||
| 292 | |||
| 293 | case 'add_delivery': |
||
| 294 | // お届け先情報の新規追加 |
||
| 295 | |||
| 296 | $form = $builder->getForm(); |
||
| 297 | |||
| 298 | $Shipping = new Shipping(); |
||
| 299 | $TargetOrder->addShipping($Shipping); |
||
| 300 | |||
| 301 | $Shipping->setOrder($TargetOrder); |
||
| 302 | |||
| 303 | $form->setData($TargetOrder); |
||
| 304 | |||
| 305 | break; |
||
| 306 | |||
| 307 | default: |
||
| 308 | break; |
||
| 309 | } |
||
| 310 | } |
||
| 311 | |||
| 312 | // 会員検索フォーム |
||
| 313 | 2 | $builder = $this->formFactory |
|
| 314 | 2 | ->createBuilder(SearchCustomerType::class); |
|
| 315 | |||
| 316 | 2 | $event = new EventArgs( |
|
| 317 | [ |
||
| 318 | 2 | 'builder' => $builder, |
|
| 319 | 2 | 'OriginOrder' => $OriginOrder, |
|
| 320 | 2 | 'TargetOrder' => $TargetOrder, |
|
| 321 | ], |
||
| 322 | 2 | $request |
|
| 323 | ); |
||
| 324 | 2 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_INITIALIZE, $event); |
|
| 325 | |||
| 326 | 2 | $searchCustomerModalForm = $builder->getForm(); |
|
| 327 | |||
| 328 | // 商品検索フォーム |
||
| 329 | 2 | $builder = $this->formFactory |
|
| 330 | 2 | ->createBuilder(SearchProductType::class); |
|
| 331 | |||
| 332 | 2 | $event = new EventArgs( |
|
| 333 | [ |
||
| 334 | 2 | 'builder' => $builder, |
|
| 335 | 2 | 'OriginOrder' => $OriginOrder, |
|
| 336 | 2 | 'TargetOrder' => $TargetOrder, |
|
| 337 | ], |
||
| 338 | 2 | $request |
|
| 339 | ); |
||
| 340 | 2 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_INITIALIZE, $event); |
|
| 341 | |||
| 342 | 2 | $searchProductModalForm = $builder->getForm(); |
|
| 343 | |||
| 344 | // 配送業者のお届け時間 |
||
| 345 | 2 | $times = []; |
|
| 346 | 2 | $deliveries = $this->deliveryRepository->findAll(); |
|
| 347 | 2 | View Code Duplication | foreach ($deliveries as $Delivery) { |
| 348 | 2 | $deliveryTiems = $Delivery->getDeliveryTimes(); |
|
| 349 | 2 | foreach ($deliveryTiems as $DeliveryTime) { |
|
| 350 | 2 | $times[$Delivery->getId()][$DeliveryTime->getId()] = $DeliveryTime->getDeliveryTime(); |
|
| 351 | } |
||
| 352 | } |
||
| 353 | |||
| 354 | return [ |
||
| 355 | 2 | 'form' => $form->createView(), |
|
| 356 | 2 | 'searchCustomerModalForm' => $searchCustomerModalForm->createView(), |
|
| 357 | 2 | 'searchProductModalForm' => $searchProductModalForm->createView(), |
|
| 358 | 2 | 'Order' => $TargetOrder, |
|
| 359 | 2 | 'id' => $id, |
|
| 360 | 2 | 'shippingDeliveryTimes' => $this->serializer->serialize($times, 'json'), |
|
| 361 | ]; |
||
| 362 | } |
||
| 363 | |||
| 364 | /** |
||
| 365 | * 顧客情報を検索する. |
||
| 366 | * |
||
| 367 | * @Route("/%eccube_admin_route%/order/search/customer", name="admin_order_search_customer") |
||
| 368 | * |
||
| 369 | * @param Request $request |
||
| 370 | * |
||
| 371 | * @return \Symfony\Component\HttpFoundation\JsonResponse |
||
| 372 | */ |
||
| 373 | 2 | public function searchCustomer(Request $request) |
|
| 374 | { |
||
| 375 | 2 | if ($request->isXmlHttpRequest()) { |
|
| 376 | 2 | log_debug('search customer start.'); |
|
| 377 | |||
| 378 | $searchData = [ |
||
| 379 | 2 | 'multi' => $request->get('search_word'), |
|
| 380 | ]; |
||
| 381 | |||
| 382 | 2 | $qb = $this->customerRepository->getQueryBuilderBySearchData($searchData); |
|
| 383 | |||
| 384 | 2 | $event = new EventArgs( |
|
| 385 | [ |
||
| 386 | 2 | 'qb' => $qb, |
|
| 387 | 2 | 'data' => $searchData, |
|
| 388 | ], |
||
| 389 | 2 | $request |
|
| 390 | ); |
||
| 391 | 2 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event); |
|
| 392 | |||
| 393 | /** @var Customer[] $Customers */ |
||
| 394 | 2 | $Customers = $qb->getQuery()->getResult(); |
|
| 395 | |||
| 396 | 2 | if (empty($Customers)) { |
|
| 397 | log_debug('search customer not found.'); |
||
| 398 | } |
||
| 399 | |||
| 400 | 2 | $data = []; |
|
| 401 | 2 | $formatName = '%s%s(%s%s)'; |
|
| 402 | 2 | View Code Duplication | foreach ($Customers as $Customer) { |
| 403 | 2 | $data[] = [ |
|
| 404 | 2 | 'id' => $Customer->getId(), |
|
| 405 | 2 | 'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(), |
|
| 406 | 2 | $Customer->getKana01(), |
|
| 407 | 2 | $Customer->getKana02()), |
|
| 408 | 2 | 'phone_number' => $Customer->getPhoneNumber(), |
|
| 409 | 2 | 'email' => $Customer->getEmail(), |
|
| 410 | ]; |
||
| 411 | } |
||
| 412 | |||
| 413 | 2 | $event = new EventArgs( |
|
| 414 | [ |
||
| 415 | 2 | 'data' => $data, |
|
| 416 | 2 | 'Customers' => $Customers, |
|
| 417 | ], |
||
| 418 | 2 | $request |
|
| 419 | ); |
||
| 420 | 2 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event); |
|
| 421 | 2 | $data = $event->getArgument('data'); |
|
| 422 | |||
| 423 | 2 | return $this->json($data); |
|
| 424 | } |
||
| 425 | } |
||
| 426 | |||
| 427 | /** |
||
| 428 | * 顧客情報を検索する. |
||
| 429 | * |
||
| 430 | * @Route("/%eccube_admin_route%/order/search/customer/html", name="admin_order_search_customer_html") |
||
| 431 | * @Route("/%eccube_admin_route%/order/search/customer/html/page/{page_no}", requirements={"page_No" = "\d+"}, name="admin_order_search_customer_html_page") |
||
| 432 | * @Template("@admin/Order/search_customer.twig") |
||
| 433 | * |
||
| 434 | * @param Request $request |
||
| 435 | * @param integer $page_no |
||
| 436 | * |
||
| 437 | * @return \Symfony\Component\HttpFoundation\JsonResponse |
||
| 438 | */ |
||
| 439 | public function searchCustomerHtml(Request $request, $page_no = null, Paginator $paginator) |
||
| 440 | { |
||
| 441 | if ($request->isXmlHttpRequest()) { |
||
| 442 | log_debug('search customer start.'); |
||
| 443 | $page_count = $this->eccubeConfig['eccube_default_page_count']; |
||
| 444 | $session = $this->session; |
||
| 445 | |||
| 446 | if ('POST' === $request->getMethod()) { |
||
| 447 | $page_no = 1; |
||
| 448 | |||
| 449 | $searchData = [ |
||
| 450 | 'multi' => $request->get('search_word'), |
||
| 451 | 'customer_status' => [ |
||
| 452 | CustomerStatus::REGULAR, |
||
| 453 | ], |
||
| 454 | ]; |
||
| 455 | |||
| 456 | $session->set('eccube.admin.order.customer.search', $searchData); |
||
| 457 | $session->set('eccube.admin.order.customer.search.page_no', $page_no); |
||
| 458 | } else { |
||
| 459 | $searchData = (array) $session->get('eccube.admin.order.customer.search'); |
||
| 460 | if (is_null($page_no)) { |
||
| 461 | $page_no = intval($session->get('eccube.admin.order.customer.search.page_no')); |
||
| 462 | } else { |
||
| 463 | $session->set('eccube.admin.order.customer.search.page_no', $page_no); |
||
| 464 | } |
||
| 465 | } |
||
| 466 | |||
| 467 | $qb = $this->customerRepository->getQueryBuilderBySearchData($searchData); |
||
| 468 | |||
| 469 | $event = new EventArgs( |
||
| 470 | [ |
||
| 471 | 'qb' => $qb, |
||
| 472 | 'data' => $searchData, |
||
| 473 | ], |
||
| 474 | $request |
||
| 475 | ); |
||
| 476 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event); |
||
| 477 | |||
| 478 | /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */ |
||
| 479 | $pagination = $paginator->paginate( |
||
| 480 | $qb, |
||
| 481 | $page_no, |
||
| 482 | $page_count, |
||
| 483 | ['wrap-queries' => true] |
||
| 484 | ); |
||
| 485 | |||
| 486 | /** @var $Customers \Eccube\Entity\Customer[] */ |
||
| 487 | $Customers = $pagination->getItems(); |
||
| 488 | |||
| 489 | if (empty($Customers)) { |
||
| 490 | log_debug('search customer not found.'); |
||
| 491 | } |
||
| 492 | |||
| 493 | $data = []; |
||
| 494 | $formatName = '%s%s(%s%s)'; |
||
| 495 | View Code Duplication | foreach ($Customers as $Customer) { |
|
| 496 | $data[] = [ |
||
| 497 | 'id' => $Customer->getId(), |
||
| 498 | 'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(), |
||
| 499 | $Customer->getKana01(), |
||
| 500 | $Customer->getKana02()), |
||
| 501 | 'phone_number' => $Customer->getPhoneNumber(), |
||
| 502 | 'email' => $Customer->getEmail(), |
||
| 503 | ]; |
||
| 504 | } |
||
| 505 | |||
| 506 | $event = new EventArgs( |
||
| 507 | [ |
||
| 508 | 'data' => $data, |
||
| 509 | 'Customers' => $pagination, |
||
| 510 | ], |
||
| 511 | $request |
||
| 512 | ); |
||
| 513 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event); |
||
| 514 | $data = $event->getArgument('data'); |
||
| 515 | |||
| 516 | return [ |
||
| 517 | 'data' => $data, |
||
| 518 | 'pagination' => $pagination, |
||
| 519 | ]; |
||
| 520 | } |
||
| 521 | } |
||
| 522 | |||
| 523 | /** |
||
| 524 | * 顧客情報を検索する. |
||
| 525 | * |
||
| 526 | * @Method("POST") |
||
| 527 | * @Route("/%eccube_admin_route%/order/search/customer/id", name="admin_order_search_customer_by_id") |
||
| 528 | * |
||
| 529 | * @param Request $request |
||
| 530 | * |
||
| 531 | * @return \Symfony\Component\HttpFoundation\JsonResponse |
||
| 532 | */ |
||
| 533 | 1 | public function searchCustomerById(Request $request) |
|
| 534 | { |
||
| 535 | 1 | if ($request->isXmlHttpRequest()) { |
|
| 536 | 1 | log_debug('search customer by id start.'); |
|
| 537 | |||
| 538 | /** @var $Customer \Eccube\Entity\Customer */ |
||
| 539 | 1 | $Customer = $this->customerRepository |
|
| 540 | 1 | ->find($request->get('id')); |
|
| 541 | |||
| 542 | 1 | $event = new EventArgs( |
|
| 543 | [ |
||
| 544 | 1 | 'Customer' => $Customer, |
|
| 545 | ], |
||
| 546 | 1 | $request |
|
| 547 | ); |
||
| 548 | 1 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_INITIALIZE, $event); |
|
| 549 | |||
| 550 | 1 | if (is_null($Customer)) { |
|
| 551 | log_debug('search customer by id not found.'); |
||
| 552 | |||
| 553 | return $this->json([], 404); |
||
| 554 | } |
||
| 555 | |||
| 556 | 1 | log_debug('search customer by id found.'); |
|
| 557 | |||
| 558 | $data = [ |
||
| 559 | 1 | 'id' => $Customer->getId(), |
|
| 560 | 1 | 'name01' => $Customer->getName01(), |
|
| 561 | 1 | 'name02' => $Customer->getName02(), |
|
| 562 | 1 | 'kana01' => $Customer->getKana01(), |
|
| 563 | 1 | 'kana02' => $Customer->getKana02(), |
|
| 564 | 1 | 'postal_code' => $Customer->getPostalCode(), |
|
| 565 | 1 | 'pref' => is_null($Customer->getPref()) ? null : $Customer->getPref()->getId(), |
|
| 566 | 1 | 'addr01' => $Customer->getAddr01(), |
|
| 567 | 1 | 'addr02' => $Customer->getAddr02(), |
|
| 568 | 1 | 'email' => $Customer->getEmail(), |
|
| 569 | 1 | 'phone_number' => $Customer->getPhoneNumber(), |
|
| 570 | 1 | 'company_name' => $Customer->getCompanyName(), |
|
| 571 | ]; |
||
| 572 | |||
| 573 | 1 | $event = new EventArgs( |
|
| 574 | [ |
||
| 575 | 1 | 'data' => $data, |
|
| 576 | 1 | 'Customer' => $Customer, |
|
| 577 | ], |
||
| 578 | 1 | $request |
|
| 579 | ); |
||
| 580 | 1 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_COMPLETE, $event); |
|
| 581 | 1 | $data = $event->getArgument('data'); |
|
| 582 | |||
| 583 | 1 | return $this->json($data); |
|
| 584 | } |
||
| 585 | } |
||
| 586 | |||
| 587 | /** |
||
| 588 | * @Route("/%eccube_admin_route%/order/search/product", name="admin_order_search_product") |
||
| 589 | * @Route("/%eccube_admin_route%/order/search/product/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_order_search_product_page") |
||
| 590 | * @Template("@admin/Order/search_product.twig") |
||
| 591 | */ |
||
| 592 | 1 | public function searchProduct(Request $request, $page_no = null, Paginator $paginator) |
|
| 593 | { |
||
| 594 | 1 | if ($request->isXmlHttpRequest()) { |
|
| 595 | 1 | log_debug('search product start.'); |
|
| 596 | 1 | $page_count = $this->eccubeConfig['eccube_default_page_count']; |
|
| 597 | 1 | $session = $this->session; |
|
| 598 | |||
| 599 | 1 | if ('POST' === $request->getMethod()) { |
|
| 600 | 1 | $page_no = 1; |
|
| 601 | |||
| 602 | $searchData = [ |
||
| 603 | 1 | 'id' => $request->get('id'), |
|
| 604 | ]; |
||
| 605 | |||
| 606 | 1 | if ($categoryId = $request->get('category_id')) { |
|
| 607 | $Category = $this->categoryRepository->find($categoryId); |
||
| 608 | $searchData['category_id'] = $Category; |
||
| 609 | } |
||
| 610 | |||
| 611 | 1 | $session->set('eccube.admin.order.product.search', $searchData); |
|
| 612 | 1 | $session->set('eccube.admin.order.product.search.page_no', $page_no); |
|
| 613 | } else { |
||
| 614 | $searchData = (array) $session->get('eccube.admin.order.product.search'); |
||
| 615 | if (is_null($page_no)) { |
||
| 616 | $page_no = intval($session->get('eccube.admin.order.product.search.page_no')); |
||
| 617 | } else { |
||
| 618 | $session->set('eccube.admin.order.product.search.page_no', $page_no); |
||
| 619 | } |
||
| 620 | } |
||
| 621 | |||
| 622 | 1 | $qb = $this->productRepository |
|
| 623 | 1 | ->getQueryBuilderBySearchDataForAdmin($searchData); |
|
| 624 | |||
| 625 | 1 | $event = new EventArgs( |
|
| 626 | [ |
||
| 627 | 1 | 'qb' => $qb, |
|
| 628 | 1 | 'searchData' => $searchData, |
|
| 629 | ], |
||
| 630 | 1 | $request |
|
| 631 | ); |
||
| 632 | 1 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH, $event); |
|
| 633 | |||
| 634 | /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */ |
||
| 635 | 1 | $pagination = $paginator->paginate( |
|
| 636 | 1 | $qb, |
|
| 637 | 1 | $page_no, |
|
| 638 | 1 | $page_count, |
|
| 639 | 1 | ['wrap-queries' => true] |
|
| 640 | ); |
||
| 641 | |||
| 642 | /** @var $Products \Eccube\Entity\Product[] */ |
||
| 643 | 1 | $Products = $pagination->getItems(); |
|
| 644 | |||
| 645 | 1 | if (empty($Products)) { |
|
| 646 | log_debug('search product not found.'); |
||
| 647 | } |
||
| 648 | |||
| 649 | 1 | $forms = []; |
|
| 650 | 1 | View Code Duplication | foreach ($Products as $Product) { |
| 651 | /* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
||
| 652 | 1 | $builder = $this->formFactory->createNamedBuilder('', AddCartType::class, null, [ |
|
| 653 | 1 | 'product' => $Product, |
|
| 654 | ]); |
||
| 655 | 1 | $addCartForm = $builder->getForm(); |
|
| 656 | 1 | $forms[$Product->getId()] = $addCartForm->createView(); |
|
| 657 | } |
||
| 658 | |||
| 659 | 1 | $event = new EventArgs( |
|
| 660 | [ |
||
| 661 | 1 | 'forms' => $forms, |
|
| 662 | 1 | 'Products' => $Products, |
|
| 663 | 1 | 'pagination' => $pagination, |
|
| 664 | ], |
||
| 665 | 1 | $request |
|
| 666 | ); |
||
| 667 | 1 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE, $event); |
|
| 668 | |||
| 669 | return [ |
||
| 670 | 1 | 'forms' => $forms, |
|
| 671 | 1 | 'Products' => $Products, |
|
| 672 | 1 | 'pagination' => $pagination, |
|
| 673 | ]; |
||
| 674 | } |
||
| 675 | } |
||
| 676 | |||
| 677 | /** |
||
| 678 | * その他明細情報を取得 |
||
| 679 | * |
||
| 680 | * @Route("/%eccube_admin_route%/order/search/order_item_type", name="admin_order_search_order_item_type") |
||
| 681 | * @Template("@admin/Order/order_item_type.twig") |
||
| 682 | * |
||
| 683 | * @param Request $request |
||
| 684 | * |
||
| 685 | * @return array |
||
| 686 | */ |
||
| 687 | public function searchOrderItemType(Request $request) |
||
| 688 | { |
||
| 689 | if ($request->isXmlHttpRequest()) { |
||
| 690 | log_debug('search order item type start.'); |
||
| 691 | |||
| 692 | $criteria = Criteria::create(); |
||
| 693 | $criteria |
||
| 694 | ->where($criteria->expr()->andX( |
||
| 695 | $criteria->expr()->neq('id', OrderItemType::PRODUCT), |
||
| 696 | $criteria->expr()->neq('id', OrderItemType::TAX) |
||
| 697 | )) |
||
| 698 | ->orderBy(['sort_no' => 'ASC']); |
||
| 699 | |||
| 700 | $OrderItemTypes = $this->orderItemTypeRepository->matching($criteria); |
||
| 701 | |||
| 702 | $forms = []; |
||
| 703 | foreach ($OrderItemTypes as $OrderItemType) { |
||
| 704 | /* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
||
| 705 | $builder = $this->formFactory->createBuilder(); |
||
| 706 | $form = $builder->getForm(); |
||
| 707 | $forms[$OrderItemType->getId()] = $form->createView(); |
||
| 708 | } |
||
| 709 | |||
| 710 | return [ |
||
| 711 | 'forms' => $forms, |
||
| 712 | 'OrderItemTypes' => $OrderItemTypes, |
||
| 713 | ]; |
||
| 714 | } |
||
| 715 | } |
||
| 716 | |||
| 717 | 3 | protected function newOrder() |
|
| 718 | { |
||
| 719 | 3 | $Order = new Order(); |
|
| 720 | // device type |
||
| 721 | 3 | $DeviceType = $this->deviceTypeRepository->find(DeviceType::DEVICE_TYPE_ADMIN); |
|
| 722 | 3 | $Order->setDeviceType($DeviceType); |
|
| 723 | |||
| 724 | 3 | $Shipping = new Shipping(); |
|
| 725 | 3 | $Order->addShipping($Shipping); |
|
| 726 | 3 | $Shipping->setOrder($Order); |
|
| 727 | |||
| 728 | 3 | return $Order; |
|
| 729 | } |
||
| 730 | |||
| 731 | /** |
||
| 732 | * 受注ステータスに応じて, 受注日/入金日/発送日を更新する, |
||
| 733 | * 発送済ステータスが設定された場合は, お届け先情報の発送日も更新を行う. |
||
| 734 | * |
||
| 735 | * 編集の場合 |
||
| 736 | * - 受注ステータスが他のステータスから発送済へ変更された場合に発送日を更新 |
||
| 737 | * - 受注ステータスが他のステータスから入金済へ変更された場合に入金日を更新 |
||
| 738 | * |
||
| 739 | * 新規登録の場合 |
||
| 740 | * - 受注日を更新 |
||
| 741 | * - 受注ステータスが発送済に設定された場合に発送日を更新 |
||
| 742 | * - 受注ステータスが入金済に設定された場合に入金日を更新 |
||
| 743 | * |
||
| 744 | * @param $app |
||
| 745 | * @param $TargetOrder |
||
| 746 | * @param $OriginOrder |
||
| 747 | * |
||
| 748 | * TODO Service へ移動する |
||
| 749 | */ |
||
| 750 | protected function updateDate($app, $TargetOrder, $OriginOrder) |
||
| 751 | { |
||
| 752 | $dateTime = new \DateTime(); |
||
| 753 | |||
| 754 | // 編集 |
||
| 755 | if ($TargetOrder->getId()) { |
||
| 756 | // 発送済 |
||
| 757 | if ($TargetOrder->getOrderStatus()->getId() == OrderStatus::DELIVERED) { |
||
| 758 | // 編集前と異なる場合のみ更新 |
||
| 759 | if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) { |
||
| 760 | // お届け先情報の発送日も更新する. |
||
| 761 | $Shippings = $TargetOrder->getShippings(); |
||
| 762 | foreach ($Shippings as $Shipping) { |
||
| 763 | $Shipping->setShippingDate($dateTime); |
||
| 764 | } |
||
| 765 | } |
||
| 766 | // 入金済 |
||
| 767 | } elseif ($TargetOrder->getOrderStatus()->getId() == OrderStatus::PAID) { |
||
| 768 | // 編集前と異なる場合のみ更新 |
||
| 769 | if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) { |
||
| 770 | $TargetOrder->setPaymentDate($dateTime); |
||
| 771 | } |
||
| 772 | } |
||
| 773 | // 新規 |
||
| 774 | } else { |
||
| 775 | // 発送済 |
||
| 776 | if ($TargetOrder->getOrderStatus()->getId() == OrderStatus::DELIVERED) { |
||
| 777 | // お届け先情報の発送日も更新する. |
||
| 778 | $Shippings = $TargetOrder->getShippings(); |
||
| 779 | foreach ($Shippings as $Shipping) { |
||
| 780 | $Shipping->setShippingDate($dateTime); |
||
| 781 | } |
||
| 782 | // 入金済 |
||
| 783 | } elseif ($TargetOrder->getOrderStatus()->getId() == OrderStatus::PAID) { |
||
| 784 | $TargetOrder->setPaymentDate($dateTime); |
||
| 785 | } |
||
| 786 | // 受注日時 |
||
| 787 | $TargetOrder->setOrderDate($dateTime); |
||
| 788 | } |
||
| 789 | } |
||
| 790 | } |
||
| 791 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.