app/Customize/Controller/CustomCartController.php line 318

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller;
  3. use Customize\Entity\TextWarning;
  4. use Customize\Enum\DataStatus;
  5. use Customize\Enum\SeasonCode;
  6. use Customize\Enum\SendDataMethod;
  7. use Customize\Repository\ProductRepository;
  8. use Customize\Service\CustomCartService;
  9. use Customize\Service\CustomPurchaseFlow;
  10. use Eccube\Controller\AbstractController;
  11. use Customize\Repository\PriceRepository;
  12. use Customize\Repository\SeasonRepository;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Eccube\Entity\Product;
  15. use Eccube\Event\EccubeEvents;
  16. use Eccube\Event\EventArgs;
  17. use Eccube\Form\Type\AddCartType;
  18. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  19. use Eccube\Service\CartService;
  20. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  21. use Eccube\Service\PurchaseFlow\PurchaseContext;
  22. use Eccube\Entity\Master\ProductStatus;
  23. use Eccube\Repository\BaseInfoRepository;
  24. use Eccube\Repository\CartItemRepository;
  25. use Eccube\Service\OrderHelper;
  26. use Eccube\Util\CacheUtil;
  27. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  28. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  29. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  30. use Customize\Repository\OrderOptionRepository;
  31. use Customize\Repository\SendDataMethodCategoryRepository;
  32. use Customize\Repository\StepOptionRepository;
  33. use Customize\Repository\TextWarningRepository;
  34. use Customize\Service\CustomOrderHelper;
  35. use Eccube\Entity\CustomerAddress;
  36. use Eccube\Entity\Master\OrderStatus;
  37. use Eccube\Entity\Shipping;
  38. use Eccube\Repository\OrderItemRepository;
  39. use Eccube\Repository\OrderRepository;
  40. use Eccube\Repository\CartRepository;
  41. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  42. use Eccube\Form\Type\Shopping\CustomerAddressType;
  43. use Customize\Repository\SimulatorLinkRepository;
  44. use Customize\Repository\WorkingTimeRepository;
  45. class CustomCartController extends AbstractController
  46. {
  47. /**
  48. * @var PurchaseFlow
  49. */
  50. protected $purchaseFlow;
  51. /**
  52. * @var CustomCartService
  53. */
  54. protected $cartService;
  55. /**
  56. * @var ProductRepository
  57. */
  58. protected $productRepository;
  59. protected $customPurchaseFlow;
  60. protected $baseInfo;
  61. protected $cartItemRepo;
  62. protected $orderItemRepo;
  63. protected $orderRepo;
  64. protected $cartRepo;
  65. protected $orderOptionRepository;
  66. protected $sendDataMethodCategoryRepository;
  67. /**
  68. * @var StepOptionRepository
  69. */
  70. protected $stepOptionRepository;
  71. protected $priceRepository;
  72. protected $seasonRepository;
  73. protected $textWarningRepository;
  74. protected $orderHelper;
  75. private $customOrderHelper;
  76. protected $simulatorLinkRepository;
  77. protected $workingTimeRepository;
  78. public function __construct(
  79. PurchaseFlow $cartPurchaseFlow,
  80. CustomCartService $cartService,
  81. ProductRepository $productRepository,
  82. CustomPurchaseFlow $customCartPurchaseFlow,
  83. BaseInfoRepository $baseInfoRepository,
  84. CartItemRepository $cartItemRepository,
  85. StepOptionRepository $stepOptionRepository,
  86. OrderItemRepository $orderItemRepository,
  87. SendDataMethodCategoryRepository $sendDataMethodCategoryRepository,
  88. PriceRepository $priceRepository,
  89. SeasonRepository $seasonRepository,
  90. OrderOptionRepository $orderOptionRepository,
  91. OrderRepository $orderRepository,
  92. CartRepository $cartRepository,
  93. TextWarningRepository $textWarningRepository,
  94. OrderHelper $orderHelper,
  95. CustomOrderHelper $customOrderHelper,
  96. SimulatorLinkRepository $simulatorLinkRepository,
  97. WorkingTimeRepository $workingTimeRepository
  98. ) {
  99. $this->purchaseFlow = $cartPurchaseFlow;
  100. $this->cartService = $cartService;
  101. $this->productRepository = $productRepository;
  102. $this->customPurchaseFlow = $customCartPurchaseFlow;
  103. $this->baseInfo = $baseInfoRepository->get();
  104. $this->cartItemRepo = $cartItemRepository;
  105. $this->orderItemRepo = $orderItemRepository;
  106. $this->orderOptionRepository = $orderOptionRepository;
  107. $this->sendDataMethodCategoryRepository = $sendDataMethodCategoryRepository;
  108. $this->stepOptionRepository = $stepOptionRepository;
  109. $this->seasonRepository = $seasonRepository;
  110. $this->priceRepository = $priceRepository;
  111. $this->orderRepo = $orderRepository;
  112. $this->cartRepo = $cartRepository;
  113. $this->textWarningRepository = $textWarningRepository;
  114. $this->orderHelper = $orderHelper;
  115. $this->customOrderHelper = $customOrderHelper;
  116. $this->simulatorLinkRepository = $simulatorLinkRepository;
  117. $this->workingTimeRepository = $workingTimeRepository;
  118. }
  119. /**
  120. * カートに追加.
  121. *
  122. * @Route("/custom/products/add_cart/{id}", name="custom_add_cart", methods={"POST"}, requirements={"id" = "\d+"})
  123. * @return JsonResponse
  124. */
  125. public function addCart(Request $request, $id)
  126. {
  127. $quantity = $request->get('total_item');
  128. $send_data_method_id = $request->get('send_data_method_id');
  129. $file_quantity = $request->get('file_quantity');
  130. $designs_new = $request->get('designs_new');
  131. $files = SendDataMethod::SimulationID == $send_data_method_id ? $request->get('files') : $request->files->get('files');
  132. $design_files = [];
  133. if ($designs_new) {
  134. if ($files) {
  135. $paths_new = $this->uploadImage($files);
  136. if (!$paths_new || count($paths_new) == 0) {
  137. return $this->json([], 500);
  138. }
  139. foreach ($designs_new as $key => $design_json) {
  140. $design_data = json_decode($design_json, true);
  141. if ($design_data) {
  142. $design_files[] = [
  143. 'quantity' => $design_data['quantity'],
  144. 'path' => $paths_new[$key] ?? $design_data['path'],
  145. 'design_id' => $design_data['design_id'] ?? null,
  146. 'id' => uniqid('', true),
  147. 'admin_design' => null,
  148. ];
  149. }
  150. }
  151. } else {
  152. foreach ($designs_new as $design_json) {
  153. $design_data = json_decode($design_json, true);
  154. if ($design_data) {
  155. $design_files[] = [
  156. 'quantity' => $design_data['quantity'],
  157. 'path' => $design_data['path'],
  158. 'design_id' => $design_data['design_id'] ?? null,
  159. 'id' => uniqid('', true),
  160. 'admin_design' => null,
  161. ];
  162. }
  163. }
  164. }
  165. }
  166. if($files && !$designs_new) {
  167. if (SendDataMethod::SimulationID == $send_data_method_id) {
  168. foreach ($files as $key => $item) {
  169. $design_files[] = ['quantity' => $file_quantity[$key], 'path' => null, 'design_id' => $item];
  170. }
  171. } else {
  172. $paths = $this->uploadImage($files);
  173. if (!$file_quantity || !$paths || count($paths) == 0 || count($file_quantity) == 0) {
  174. return $this->json([], 500);
  175. }
  176. foreach ($paths as $key => $path) {
  177. $design_files[] = ['quantity' => $file_quantity[$key], 'path' => $path, 'design_id' => null, 'id' => uniqid('', true), 'admin_design' => null];
  178. }
  179. }
  180. }
  181. $total_delivery_item = $request->get('total_delivery_item');
  182. $add_day = $request->get('add_day');
  183. $item_price_option = $request->get('item_price_option');
  184. $plan = $request->get('plan');
  185. $product_options = $request->get('product_options');
  186. $order_options = $request->get('order_options');
  187. $item_price = $request->get('item_price');
  188. $data = [
  189. 'quantity' => (int) $quantity,
  190. 'total_delivery_item' => (int) $total_delivery_item,
  191. 'add_day' => (int) $add_day,
  192. 'item_price_option' => (int) $item_price_option,
  193. 'plan' => $plan,
  194. 'product_options' => $product_options,
  195. 'quantity_designs' => $file_quantity ? count($file_quantity) : 0,
  196. 'send_data_method_id' => (int) $send_data_method_id,
  197. 'order_options' => $order_options,
  198. 'item_price' => (int) $item_price,
  199. 'design_files' => $design_files,
  200. 'price_send_data' => (int) $request->get('price_send_data')
  201. ];
  202. $Product = $this->productRepository->findWithSortedClassCategories($id);
  203. if ($Product->getIsSample()) {
  204. return $this->json(['error' => 'Can not add simple product'], 500);
  205. }
  206. $product_class_id1 = $Product->getProductClasses()[0]->getId();
  207. $this->cartService->customAddProduct($product_class_id1, $data);
  208. $Carts = $this->cartService->getCarts();
  209. $errorMessages = [];
  210. $this->cartService->save();
  211. return $this->json(['error' => $errorMessages]);
  212. }
  213. /**
  214. * カートに追加.
  215. *
  216. * @Route("/custom/products/add_cart_sample_product/{id}", name="custom_add_cart_sample", methods={"POST"}, requirements={"id" = "\d+"})
  217. * @return JsonResponse
  218. */
  219. public function addCartSampleProduct($id)
  220. {
  221. $Product = $this->productRepository->findWithSortedClassCategories($id);
  222. if (!$Product->getIsSample()) {
  223. return $this->json(['error' => 'Only for add simple product'], 500);
  224. }
  225. if ($Product->getStatus()->getId() !== ProductStatus::DISPLAY_SHOW) {
  226. return $this->json(['error' => 'Product is not visiable'], 500);
  227. ;
  228. }
  229. $product_class = $Product->getProductClasses()[0];
  230. $this->cartService->addSampleProduct($product_class, 1);
  231. $this->cartService->save();
  232. return $this->json([]);
  233. }
  234. /**
  235. * 閲覧可能な商品かどうかを判定
  236. *
  237. * @param Product $Product
  238. *
  239. * @return boolean 閲覧可能な場合はtrue
  240. */
  241. protected function checkVisibility(Product $Product)
  242. {
  243. $is_admin = $this->session->has('_security_admin');
  244. if (!$is_admin) {
  245. if ($Product->getStatus()->getId() !== ProductStatus::DISPLAY_SHOW) {
  246. return false;
  247. }
  248. }
  249. return true;
  250. }
  251. public function uploadImage(array $files)
  252. {
  253. if (!$files || count($files) == 0) {
  254. return false;
  255. }
  256. $allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'application/octet-stream'];
  257. $maxFileSize = 200 * 1024 * 1024;
  258. $paths = [];
  259. foreach ($files as $file) {
  260. if (!$file || $file->getSize() == 0) {
  261. $paths[] = null;
  262. } else {
  263. // if (!in_array($file->getClientMimeType(), $allowedTypes)) {
  264. // return false;
  265. // }
  266. if ($file->getSize() && $file->getSize() > $maxFileSize) {
  267. return false;
  268. }
  269. $name = $file->getClientOriginalName();
  270. $fileName = uniqid() . '-' . $name;
  271. $uploadDir = $this->getParameter('kernel.project_dir') . '/html/upload/design';
  272. $file->move($uploadDir, $fileName);
  273. $path = '/html/upload/design/' . $fileName;
  274. $paths[] = $path;
  275. }
  276. }
  277. return $paths;
  278. }
  279. /**
  280. * @Method("GET")
  281. * @Route("/cart_index", name="cart_index")
  282. * @Template("@user_data/cart_index.twig")
  283. */
  284. public function cart_index(Request $request)
  285. {
  286. // カートを取得して明細の正規化を実行
  287. $Carts = $this->cartService->getCarts();
  288. // $this->execPurchaseFlow($Carts);
  289. // TODO itemHolderから取得できるように
  290. $least = [];
  291. $quantity = [];
  292. $isDeliveryFree = [];
  293. $totalPrice = 0;
  294. $totalQuantity = 0;
  295. foreach ($Carts as $Cart) {
  296. $quantity[$Cart->getCartKey()] = 0;
  297. $isDeliveryFree[$Cart->getCartKey()] = false;
  298. if ($this->baseInfo->getDeliveryFreeQuantity()) {
  299. if ($this->baseInfo->getDeliveryFreeQuantity() > $Cart->getQuantity()) {
  300. $quantity[$Cart->getCartKey()] = $this->baseInfo->getDeliveryFreeQuantity() - $Cart->getQuantity();
  301. } else {
  302. $isDeliveryFree[$Cart->getCartKey()] = true;
  303. }
  304. }
  305. if ($this->baseInfo->getDeliveryFreeAmount()) {
  306. if (!$isDeliveryFree[$Cart->getCartKey()] && $this->baseInfo->getDeliveryFreeAmount() <= $Cart->getTotalPrice()) {
  307. $isDeliveryFree[$Cart->getCartKey()] = true;
  308. } else {
  309. $least[$Cart->getCartKey()] = $this->baseInfo->getDeliveryFreeAmount() - $Cart->getTotalPrice();
  310. }
  311. }
  312. $totalPrice += $Cart->getTotalPrice();
  313. $totalQuantity += $Cart->getQuantity();
  314. }
  315. // カートが分割された時のセッション情報を削除
  316. $request->getSession()->remove(OrderHelper::SESSION_CART_DIVIDE_FLAG);
  317. $workingTime = $this->workingTimeRepository->getTopWorkingTime();
  318. return [
  319. 'totalPrice' => $totalPrice,
  320. 'totalQuantity' => $totalQuantity,
  321. // 空のカートを削除し取得し直す
  322. 'Carts' => $this->cartService->getCarts(true),
  323. 'least' => $least,
  324. 'quantity' => $quantity,
  325. 'is_delivery_free' => $isDeliveryFree,
  326. 'working_time' => $workingTime,
  327. ];
  328. }
  329. /**
  330. * @Method("GET")
  331. * @Route("/cart_login_amazon", name="cart_login_amazon")
  332. * @return JsonResponse
  333. */
  334. public function cart_login_amazon(Request $request)
  335. {
  336. $this->setLoginTargetPath($this->generateUrl('cart_index', [], UrlGeneratorInterface::ABSOLUTE_URL));
  337. return $this->redirectToRoute('mypage-login');
  338. }
  339. /**
  340. *
  341. * @Route(
  342. * path="/cart_index/{cartItemId}/delete",
  343. * name="cart_remove_item",
  344. * methods={"DELETE"},
  345. * requirements={
  346. * "cartItemId": "\d+"
  347. * }
  348. * )
  349. * @return JsonResponse
  350. */
  351. public function removeCartItem($cartItemId)
  352. {
  353. $this->isTokenValid();
  354. $cartItem = $this->cartItemRepo->find($cartItemId);
  355. if (is_null($cartItem)) {
  356. return $this->redirectToRoute('cart_index');
  357. }
  358. $Cart = $cartItem->getCart();
  359. $Customer = $this->getUser() ? $this->getUser() : $this->orderHelper->getNonMember();
  360. $Order = $Customer ? $this->customOrderHelper->customInitializeOrder($Cart, $Customer) : null;
  361. if($Order){
  362. $this->orderRepo->delete($Order);
  363. }
  364. $this->cartItemRepo->delete($cartItem);
  365. $this->entityManager->flush();
  366. $this->cartService->handleDeleteCart();
  367. return $this->json([]);
  368. }
  369. /**
  370. * @param $Carts
  371. *
  372. * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
  373. */
  374. protected function execPurchaseFlow($Carts, $custom = false)
  375. {
  376. /** @var PurchaseFlowResult[] $flowResults */
  377. if ($custom) {
  378. $flowResults = array_map(function ($Cart) {
  379. $purchaseContext = new PurchaseContext($Cart, $this->getUser());
  380. return $this->customPurchaseFlow->customValidate($Cart, $purchaseContext);
  381. }, $Carts);
  382. } else {
  383. $flowResults = array_map(function ($Cart) {
  384. $purchaseContext = new PurchaseContext($Cart, $this->getUser());
  385. return $this->purchaseFlow->validate($Cart, $purchaseContext);
  386. }, $Carts);
  387. }
  388. // 復旧不可のエラーが発生した場合はカートをクリアして再描画
  389. $hasError = false;
  390. foreach ($flowResults as $result) {
  391. if ($result->hasError()) {
  392. $hasError = true;
  393. foreach ($result->getErrors() as $error) {
  394. $this->addRequestError($error->getMessage());
  395. }
  396. }
  397. }
  398. if ($hasError) {
  399. $this->cartService->clear();
  400. return $this->redirectToRoute('cart_index');
  401. }
  402. $this->cartService->save();
  403. foreach ($flowResults as $index => $result) {
  404. foreach ($result->getWarning() as $warning) {
  405. if ($Carts[$index]->getItems()->count() > 0) {
  406. $cart_key = $Carts[$index]->getCartKey();
  407. $this->addRequestError($warning->getMessage(), "front.cart.${cart_key}");
  408. } else {
  409. // キーが存在しない場合はグローバルにエラーを表示する
  410. $this->addRequestError($warning->getMessage());
  411. }
  412. }
  413. }
  414. return null;
  415. }
  416. /**
  417. * @Method("GET")
  418. * @Route("/detail/{id}/{type}", name="detail")
  419. * @Template("@user_data/detail.twig")
  420. */
  421. public function detail($id, $type)
  422. {
  423. $item = null;
  424. $Product = null;
  425. $current_user = $this->getUser();
  426. $order_date = null;
  427. if ($type == 'cart') {
  428. $item = $this->cartItemRepo->find($id);
  429. if (!$item) {
  430. throw new NotFoundHttpException();
  431. }
  432. $Product = $this->productRepository->findWithSortedClassCategories($item['ProductClass']['Product']['id']);
  433. } else if ($type == 'order') {
  434. if (!$current_user) {
  435. throw new NotFoundHttpException();
  436. }
  437. $item = $this->orderItemRepo->find($id);
  438. if (!$item || $item['Order']['Customer']['id'] != $current_user['id']) {
  439. throw new NotFoundHttpException();
  440. }
  441. $order_date = $item->getOrder()->getCreateDate() ?? null;
  442. $Product = $this->productRepository->findWithSortedClassCategories($item['Product']['id']);
  443. } else {
  444. throw new NotFoundHttpException();
  445. }
  446. if($Product->getIsSample()){
  447. return $this->redirect('/sample');
  448. }
  449. if (!$this->checkVisibility($Product)) {
  450. throw new NotFoundHttpException();
  451. }
  452. $Category = $Product->getProductCategories()[0];
  453. if (!$Category) {
  454. throw new NotFoundHttpException();
  455. }
  456. $season = $this->seasonRepository->findActiveSeason()->getCode() ?? SeasonCode::Normal;
  457. $orderOptions = $this->orderOptionRepository->getOrderOptionCategory($Category->getCateGoryId(), $Product->getId());
  458. $sendDataMethods = $this->sendDataMethodCategoryRepository->getSendDataMethodsProduct($Category->getCateGoryId(), $Product->getId());
  459. $warningText = $this->textWarningRepository->getOrderText($Product->getId(), $item['send_data_method_id']);
  460. $option_ids_arr = str_replace(',', '-', $item['option_ids']);
  461. $option_ids_arr = $option_ids_arr ? explode("-",$option_ids_arr) : [];
  462. $resultNewPrice = $this->priceRepository->getLatestPrice($Product->getId(), $option_ids_arr, $item['plan_delivery'], $item['order_options']['quantity_view'], $season);
  463. $newPrice = null;
  464. $fromQuantity = null;
  465. $toQuantity = null;
  466. $price_id = null;
  467. if ($resultNewPrice !== null) {
  468. $price_id = $resultNewPrice['id'];
  469. $newPrice = $resultNewPrice['price'];
  470. $fromQuantity = $resultNewPrice['from_quantity'];
  471. $toQuantity = $resultNewPrice['to_quantity'];
  472. }
  473. if (!$price_id && isset($item['price'])) {
  474. $price_id = $item['price'];
  475. }
  476. $workingTime = $this->workingTimeRepository->getTopWorkingTime();
  477. $option_ids= $item['option_ids'];
  478. $product_id= $Product->getId();
  479. $requestArray = [
  480. 'options' => $option_ids,
  481. 'price_id' => $price_id,
  482. 'product_id' => $product_id,
  483. ];
  484. $order_code = $requestArray;
  485. $options = $this->handleOptionCode($order_code, $product_id);
  486. return [
  487. 'OrderOptions' => $orderOptions,
  488. 'SendDataMethods' => $sendDataMethods,
  489. "Product" => $Product,
  490. "Category" => $Category,
  491. "item" => $item,
  492. 'new_price' => $newPrice,
  493. 'fromQuantity' => $fromQuantity,
  494. 'toQuantity' => $toQuantity,
  495. "Options" => $options,
  496. 'WorkingTime' => $workingTime,
  497. 'add_day_delivery' => $item->getAddDayDelivery(),
  498. 'type' => $type,
  499. 'id' => $id,
  500. 'inprogress' => OrderStatus::IN_PROGRESS,
  501. 'SIMULATION' => SendDataMethod::SimulationID,
  502. 'warningText' => $warningText,
  503. 'order_date' => $order_date
  504. ];
  505. }
  506. /**
  507. * @Method("POST")
  508. * @Route("/detail/{id}/{type}", name="change_design")
  509. * @return JsonResponse
  510. */
  511. public function changeDesign(Request $request, CacheUtil $cacheUtil, $id, $type)
  512. {
  513. $current_user = $this->getUser();
  514. $this->isTokenValid();
  515. $item = null;
  516. if ($type == 'cart') {
  517. $item = $this->cartItemRepo->find($id);
  518. if (!$item) {
  519. throw new NotFoundHttpException();
  520. }
  521. } else if ($type == 'order') {
  522. if (!$current_user) {
  523. throw new NotFoundHttpException();
  524. }
  525. $item = $this->orderItemRepo->find($id);
  526. if (!$item || $item['Order']['Customer']['id'] != $current_user['id']) {
  527. throw new NotFoundHttpException();
  528. }
  529. if ($item['Order']['OrderStatus']['id'] == OrderStatus::IN_PROGRESS) {
  530. throw new NotFoundHttpException();
  531. }
  532. } else {
  533. throw new NotFoundHttpException();
  534. }
  535. $index = $request->get('index');
  536. $designs = $item['designs'];
  537. if ($item['designs'][$index]['design_id']) {
  538. $design_id = $request->get('design_id' . $index);
  539. $designs[$index]['design_id'] = $design_id;
  540. $item->setDesigns($designs);
  541. } else {
  542. $files = $request->files->get('path' . $index);
  543. $paths = $this->uploadImage([$files]);
  544. $designs[$index]['path'] = $paths[0];
  545. $item->setDesigns($designs);
  546. }
  547. $this->cartItemRepo->save($item);
  548. $data_status = DataStatus::CONFIRMING_DATA;
  549. foreach ($item['designs'] as $design) {
  550. if (!$design['design_id'] && !$design['path']) {
  551. $data_status = DataStatus::WAITING_DATA;
  552. break;
  553. }
  554. }
  555. if ($type == 'cart') {
  556. $cart = $item->getCart();
  557. $this->orderRepo->save($cart);
  558. } else if($type == 'order') {
  559. $order = $item->getOrder();
  560. $order->setDataStatusId($data_status);
  561. $this->orderRepo->save($order);
  562. }
  563. $this->entityManager->flush();
  564. return $this->json([]);
  565. }
  566. /**
  567. * @Method("GET")
  568. * @Route("/text-warning-order/{product_id}/{send_data_method_id}")
  569. * @return JsonResponse
  570. */
  571. public function getTextWarningOrder(int $product_id, int $send_data_method_id){
  572. $data = $this->textWarningRepository->getOrderText($product_id, $send_data_method_id);
  573. return $this->json(['data' => $data ? $data->getWarning() : null]);
  574. }
  575. /**
  576. * お届け先選択画面.
  577. *
  578. * 会員ログイン時, お届け先を選択する画面を表示する
  579. * 非会員の場合はこの画面は使用しない。
  580. *
  581. * @Route("/order/shipping/{id}", name="order_shipping", requirements={"id" = "\d+"}, methods={"GET", "POST"})
  582. * @Template("@user_data/change_shipping.twig")
  583. */
  584. public function shipping(Request $request, Shipping $Shipping)
  585. {
  586. if ($this->orderHelper->isLoginRequired()) {
  587. $this->setLoginTargetPath($this->generateUrl('cart_input', [], UrlGeneratorInterface::ABSOLUTE_URL));
  588. return $this->redirectToRoute('mypage-login');
  589. }
  590. // 受注の存在チェック
  591. $preOrderId = $this->cartService->getPreOrderId();
  592. $Order = $this->orderHelper->getPurchaseProcessingOrder($preOrderId);
  593. if (!$Order) {
  594. throw new NotFoundHttpException();
  595. }
  596. // 受注に紐づくShippingかどうかのチェック.
  597. if (!$Order->findShipping($Shipping->getId())) {
  598. throw new NotFoundHttpException();
  599. }
  600. $builder = $this->formFactory->createBuilder(CustomerAddressType::class, null, [
  601. 'customer' => $this->getUser(),
  602. 'shipping' => $Shipping,
  603. ]);
  604. $form = $builder->getForm();
  605. $form->handleRequest($request);
  606. if ($form->isSubmitted() && $form->isValid()) {
  607. log_info('お届先情報更新開始', [$Shipping->getId()]);
  608. /** @var CustomerAddress $CustomerAddress */
  609. $CustomerAddress = $form['addresses']->getData();
  610. // お届け先情報を更新
  611. $Shipping->setFromCustomerAddress($CustomerAddress);
  612. // 合計金額の再計算
  613. // $response = $this->executePurchaseFlow($Order);
  614. $this->entityManager->flush();
  615. // if ($response) {
  616. // return $response;
  617. // }
  618. $event = new EventArgs(
  619. [
  620. 'Order' => $Order,
  621. 'Shipping' => $Shipping,
  622. ],
  623. $request
  624. );
  625. $this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_SHOPPING_SHIPPING_COMPLETE);
  626. log_info('お届先情報更新完了', [$Shipping->getId()]);
  627. return $this->redirectToRoute('cart_input');
  628. }
  629. return [
  630. 'form' => $form->createView(),
  631. 'Customer' => $this->getUser(),
  632. 'shippingId' => $Shipping->getId(),
  633. ];
  634. }
  635. private function handleOptionCode($optionCode, $productID)
  636. {
  637. $options = $optionCode;
  638. if (!$options || !isset($options['product_id']) || !isset($options['price_id']) || !isset($options['options'])) {
  639. throw new NotFoundHttpException();
  640. }
  641. if($options['product_id'] !== $productID){
  642. throw new NotFoundHttpException();
  643. }
  644. $price = $this->priceRepository->queryOrder($options['price_id']);
  645. $options['options'] = array_map('trim', explode(',', $options['options']));
  646. $option_list = $this->stepOptionRepository->whereIn($options['options']);
  647. if($price->getProductId() != $productID){
  648. throw new NotFoundHttpException();
  649. }
  650. $simulator_link = $this->simulatorLinkRepository->getProductSimulatorLink($productID, $price->getOptionIds());
  651. $delivery_time = null;
  652. $season = $this->seasonRepository->findActiveSeason()->getCode() ?? SeasonCode::Normal;
  653. if ($season == SeasonCode::Normal) {
  654. $delivery_time = $price->getDeliveryTimeNormalSession();
  655. }
  656. if ($season == SeasonCode::Peak) {
  657. $delivery_time = $price->getDeliveryTimePeakSession();
  658. }
  659. if ($season == SeasonCode::Low) {
  660. $delivery_time = $price->getDeliveryTimeLowSession();
  661. }
  662. $plans = [];
  663. $plan_selected = $price->getPlan();
  664. $price_list = $this->priceRepository->queryOrder($options['price_id'], true);
  665. foreach($price_list as $price_plan){
  666. if($price_plan['plan'] != $plan_selected){
  667. $delivery_time_plan = 0;
  668. if ($season == SeasonCode::Normal) {
  669. $delivery_time_plan = $price_plan['delivery_time_normal_session'];
  670. }
  671. if ($season == SeasonCode::Peak) {
  672. $delivery_time_plan = $price_plan['delivery_time_peak_session'];
  673. }
  674. if ($season == SeasonCode::Low) {
  675. $delivery_time_plan = $price_plan['delivery_time_low_session'];
  676. }
  677. if($delivery_time_plan != 0){
  678. $plans[] = [
  679. 'plan' => $price_plan['plan'],
  680. 'delivery_time' => $delivery_time_plan
  681. ];
  682. }
  683. }
  684. }
  685. return [
  686. 'quantity_from' => $price->getFromQuantity(),
  687. 'quantity_to' => $price->getToQuantity(),
  688. 'quantity_view' => $price->getQuantityView(),
  689. 'plan' => $plan_selected,
  690. 'plans' => $plans,
  691. 'price' => $price->getPrice(),
  692. 'delivery_time' => $delivery_time,
  693. 'options' => $option_list,
  694. 'price_list' => $price_list,
  695. 'simulator_link' => $simulator_link
  696. ];
  697. }
  698. }