src/Eccube/Controller/TopController.php line 37

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;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  14. use Eccube\Form\Type\TopType;
  15. use Eccube\Entity\Cart;
  16. use Doctrine\DBAL\Connection;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. use Symfony\Contracts\HttpClient\HttpClientInterface;
  22. use Symfony\Component\Form\FormFactoryInterface;
  23. use Eccube\Service\CartService;
  24. use Eccube\Service\PurchaseFlow\PurchaseContext;
  25. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  26. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  27. use Symfony\Component\HttpFoundation\RedirectResponse;
  28. use Eccube\Entity\ProductClass;
  29. use Eccube\Entity\CartItem;
  30. use Doctrine\ORM\EntityManagerInterface;
  31. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  32. class TopController extends AbstractController
  33. {
  34.     private $connection;
  35.     private $httpClient;
  36.     protected $session;
  37.     protected $entityManager;
  38.      /**
  39.      * @var CartService
  40.      */
  41.     protected $cartService;
  42.     /**
  43.      * @var PurchaseFlow
  44.      */
  45.     protected $purchaseFlow;
  46.      public function __construct(Connection $connection,HttpClientInterface $httpClient,CartService $cartService,PurchaseFlow $cartPurchaseFlowEntityManagerInterface $entityManager,UrlGeneratorInterface $urlGenerator)
  47.      {
  48.          $this->connection $connection;
  49.          $this->httpClient $httpClient;
  50.          $this->cartService $cartService;
  51.          $this->purchaseFlow $cartPurchaseFlow;
  52.          $this->entityManager $entityManager;
  53.          $this->urlGenerator $urlGenerator;
  54.      }
  55.     /**
  56.      * @Route("/", name="homepage", methods={"POST", "GET"})
  57.      * @Template("index.twig")
  58.      */
  59.      public function index(Request $requestFormFactoryInterface $formFactorySessionInterface $session)
  60.      {
  61.         $builder $formFactory->createNamedBuilder(''TopType::class);
  62.         $form $builder->getForm();
  63.          $err['shipping_delivery_date'] = "";
  64.          $err['end_date'] = "";
  65.          if ($request->request->get('mode')=="sel") {
  66.             //日付計算
  67.             $shipping_delivery_date = new \DateTime$request->get('shipping_delivery_date') );
  68.             $end_date               = new \DateTime$request->get('end_date') );
  69.             $today                  = new \DateTime('today');
  70.             $asatte                 $today->modify('+1 day');
  71.             $order_plan             $request->get('order_plan');
  72.             if ($request->get('shipping_delivery_date') < $asatte->format('Y-m-d')) {
  73.                 $err['shipping_delivery_date'] = "select one day later";
  74.             } elseif ($request->get('shipping_delivery_date') > $request->get('end_date')) {
  75.                 $err['end_date'] = "select two days later";
  76.             } elseif (
  77.                 ($end_date->getTimestamp() - $shipping_delivery_date->getTimestamp()) / 86400 93 &&
  78.                     $order_plan != "205" &&
  79.                     $order_plan != "206" &&
  80.                     $order_plan != "207" &&
  81.                     $order_plan != "208" &&
  82.                     $order_plan != "209" &&
  83.                     $order_plan != "210" &&
  84.                     $order_plan != "867" &&
  85.                     $order_plan != "868" &&
  86.                     $order_plan != "872"
  87.             ) {
  88.                 $err['end_date'] = "select within 93 days";
  89.             }
  90.             //エラーがない
  91.             if ($err['shipping_delivery_date'] == "" && $err['end_date'] == "") {
  92.                 $kikan = (($end_date->getTimestamp() - $shipping_delivery_date->getTimestamp()) / 86400) + 1;
  93.                 if ($order_plan == "1") {
  94.                     $product_code "Basic";
  95.                 } elseif ($order_plan == "2") {
  96.                     $product_code "Premium";
  97.                 } elseif ($order_plan == "4") {
  98.                     $product_code "5G";
  99.                 } elseif ($order_plan == "205") {
  100.                     $product_code "SIM";
  101.                 } elseif ($order_plan == "206") {
  102.                     $product_code "SIM";
  103.                 } elseif ($order_plan == "207") {
  104.                     $product_code "SIM";
  105.                 } elseif ($order_plan == "208") {
  106.                     $product_code "Basic";
  107.                 } elseif ($order_plan == "209") {
  108.                     $product_code "Basic";
  109.                 } elseif ($order_plan == "210") {
  110.                     $product_code "Basic";
  111.                 } elseif ($order_plan == "867") {
  112.                     $product_code "Basic";
  113.                 } elseif ($order_plan == "868") {
  114.                     $product_code "Basic";
  115.                 } elseif ($order_plan == "872") {
  116.                     $product_code "Basic";
  117.                 } else {
  118.                     $product_code "super";
  119.                 }
  120.                 //product_class_idを入手する
  121.                 $res null;
  122.                 if ($product_code == "SIM" || $product_code == "Basic") {
  123.                     $q "SELECT pc.id AS product_class_id, pc.product_id
  124.                     FROM dtb_product_class AS pc
  125.                     LEFT JOIN dtb_product AS pr ON pc.product_id = pr.id
  126.                     WHERE pc.visible='1' AND pr.product_status_id='1' AND pc.product_code='" $product_code "' AND product_id = '" $order_plan "'";
  127.                 } else {
  128.                     $q "SELECT pc.id AS product_class_id, pc.product_id
  129.                     FROM (SELECT id, product_id FROM dtb_product_class WHERE visible='1' AND product_code='" $product_code "') AS pc
  130.                     LEFT JOIN dtb_product ON pc.product_id=dtb_product.id
  131.                     WHERE dtb_product.product_status_id='1' AND dtb_product.kikan='" $kikan "'";
  132.                 }
  133.                 $res $this->connection->fetchAllAssociative($q);
  134.                 //たっぷり安心パック(保証)500円(税込)    product_id:81    product_class_id:179
  135.                 //モバイル充電器 800円(税込)            product_id:82    product_class_id:180
  136.                 //カートに入れる
  137.                 $addCartForm $builder->getForm();
  138.                 $addCartForm->handleRequest($request);
  139.                 $addCartData $addCartForm->getData();
  140.                     try {
  141.                         // データベースから商品情報を取得
  142.                         $res $this->connection->fetchAllAssociative($q);
  143.                         $productClassId $res[0]['product_class_id'];
  144.                         $totalQuantity 1;
  145.                         // 商品をカートに追加
  146.                         $this->cartService->addProduct($productClassId$totalQuantity);
  147.                         // カートを保存
  148.                         $this->cartService->save();
  149.                         // カートの中身を確認
  150.                         // dump($this->cartService->getCart());
  151.                         // exit; // dumpの結果を確認したい場合はexitを追加
  152.                         // if ($result) {
  153.                         //     // 商品がカートに追加された場合
  154.                         //     dd("商品がカートに追加されました。");
  155.                         // } else {
  156.                         //     // 商品追加が失敗した場合
  157.                         //     dd("商品追加に失敗しました。");
  158.                         // }
  159.                         $arrOrderTappuri $request->get('order_tappuri');
  160.                         if ($arrOrderTappuri != "") {
  161.                             for ($i 0$i count($arrOrderTappuri); $i++) {
  162.                                 // 期間なしのPortable Charger
  163.                                 if ($arrOrderTappuri[$i] == "81") {
  164.                                     // $app['eccube.service.cart']->addProduct(179, 1)->save();
  165.                                     $productClassId 179;
  166.                                     $totalQuantity 1;
  167.                                     $this->cartService->addProduct($productClassId$totalQuantity);
  168.                                     $this->cartService->save();
  169.                                 }
  170.                                 // 期間なしのPremium Insurance
  171.                                 elseif ($arrOrderTappuri[$i] == "82") {
  172.                                     // $app['eccube.service.cart']->addProduct(180, 1)->save();
  173.                                     $productClassId 180;
  174.                                     $totalQuantity 1;
  175.                                     $this->cartService->addProduct($productClassId$totalQuantity);
  176.                                     $this->cartService->save();
  177.                                 } elseif ($arrOrderTappuri[$i] == "393") {
  178.                                     // $app['eccube.service.cart']->addProduct(491, 1)->save();
  179.                                     $productClassId 491;
  180.                                     $totalQuantity 1;
  181.                                     $this->cartService->addProduct($productClassId$totalQuantity);
  182.                                     $this->cartService->save();
  183.                                 } elseif ($arrOrderTappuri[$i] == "461") {
  184.                                     // $app['eccube.service.cart']->addProduct(913, 1)->save();
  185.                                     $productClassId 913;
  186.                                     $totalQuantity 1;
  187.                                     $this->cartService->addProduct($productClassId$totalQuantity);
  188.                                     $this->cartService->save();
  189.                                 }
  190.                                 // 本体レンタル期間と同じ日数のPortable Chargerをカートに入れる
  191.                                 elseif ($arrOrderTappuri[$i] == "charger") {
  192.                                     switch ($order_plan) {
  193.                                         case "208":
  194.                                             $optKikan 90;
  195.                                             break;
  196.                                         case "209":
  197.                                             $optKikan 180;
  198.                                             break;
  199.                                         case "210":
  200.                                             $optKikan 360;
  201.                                             break;
  202.                                         case "867":
  203.                                             $optKikan 120;
  204.                                             break;
  205.                                         case "868":
  206.                                             $optKikan 150;
  207.                                             break;
  208.                                         case "872":
  209.                                             $optKikan 300;
  210.                                             break;
  211.                                         default:
  212.                                             $optKikan $kikan ?? 0;
  213.                                     }
  214.                                     $q "SELECT pc.id AS product_class_id, pc.product_id
  215.                                     FROM (SELECT id, product_id FROM dtb_product_class WHERE visible='1' AND product_code='4589779235272') AS pc
  216.                                     LEFT JOIN dtb_product ON pc.product_id = dtb_product.id
  217.                                     WHERE dtb_product.product_status_id='1' AND dtb_product.kikan='" $optKikan "'";
  218.                                     $resCharger $this->connection->fetchAllAssociative($q);
  219.                                     // $app['eccube.service.cart']->addProduct($resCharger[0]['product_class_id'], 1)->save();
  220.                                     if (!empty($resCharger)) {
  221.                                         $productClassIdPocketalk $resCharger[0]['product_class_id'];
  222.                                         // 数量をレンタル期間で決定(例: 90日なら quantity = 3 など)
  223.                                         $totalQuantityPocketalk ceil($optKikan 30); // 1ヶ月ごとに1つ加算
  224.                                         // 商品をカートに追加
  225.                                         $this->cartService->addProduct($productClassIdPocketalk$totalQuantityPocketalk);
  226.                                         // カートを保存
  227.                                         $this->cartService->save();
  228.                                     }
  229.                                 }
  230.                                 // 本体レンタル期間と同じ日数のPremium Insuranceをカートに入れる
  231.                                 elseif ($arrOrderTappuri[$i] == "insurance") {
  232.                                     switch ($order_plan) {
  233.                                         case "208":
  234.                                             $optKikan 90;
  235.                                             break;
  236.                                         case "209":
  237.                                             $optKikan 180;
  238.                                             break;
  239.                                         case "210":
  240.                                             $optKikan 360;
  241.                                             break;
  242.                                         case "867":
  243.                                             $optKikan 120;
  244.                                             break;
  245.                                         case "868":
  246.                                             $optKikan 150;
  247.                                             break;
  248.                                         case "872":
  249.                                             $optKikan 300;
  250.                                             break;
  251.                                         default:
  252.                                             $optKikan $kikan ?? 0;
  253.                                     }
  254.                                     $q "SELECT pc.id AS product_class_id, pc.product_id
  255.                                         FROM (SELECT * FROM dtb_product WHERE product_status_id = '1' AND name like '%Premium Insurance%day%' AND kikan = $optKikan) pr
  256.                                         LEFT JOIN dtb_product_class AS pc ON pc.product_id = pr.id AND pc.visible='1'";
  257.                                     $resInsurance $this->connection->fetchAllAssociative($q);
  258.                                     // $app['eccube.service.cart']->addProduct($resInsurance[0]['product_class_id'], 1)->save();
  259.                                     if (!empty($resInsurance)) {
  260.                                         $productClassIdPocketalk $resInsurance[0]['product_class_id'];
  261.                                         // 数量をレンタル期間で決定(例: 90日なら quantity = 3 など)
  262.                                         $totalQuantityPocketalk ceil($optKikan 30); // 1ヶ月ごとに1つ加算
  263.                                         // 商品をカートに追加
  264.                                         $this->cartService->addProduct($productClassIdPocketalk$totalQuantityPocketalk);
  265.                                         // カートを保存
  266.                                         $this->cartService->save();
  267.                                     }
  268.                                 }
  269.                                 // 本体レンタル期間と同じ日数のPOCKETALKをカートに入れる
  270.                                 elseif ($arrOrderTappuri[$i] == "pocketalk") {
  271.                                     switch ($order_plan) {
  272.                                         case "208":
  273.                                             $optKikan 90;
  274.                                             break;
  275.                                         case "209":
  276.                                             $optKikan 180;
  277.                                             break;
  278.                                         case "210":
  279.                                             $optKikan 360;
  280.                                             break;
  281.                                         case "867":
  282.                                             $optKikan 120;
  283.                                             break;
  284.                                         case "868":
  285.                                             $optKikan 150;
  286.                                             break;
  287.                                         case "872":
  288.                                             $optKikan 300;
  289.                                             break;
  290.                                         default:
  291.                                             $optKikan $kikan ?? 0;
  292.                                     }
  293.                                     $q "SELECT pc.id AS product_class_id, pc.product_id
  294.                                     FROM (SELECT id, product_id FROM dtb_product_class WHERE visible='1' AND product_code='POCKETALK') AS pc
  295.                                     LEFT JOIN dtb_product ON pc.product_id = dtb_product.id
  296.                                     WHERE dtb_product.product_status_id='1' AND dtb_product.kikan='" $optKikan "'";
  297.                                     $resPocketalk $this->connection->fetchAllAssociative($q);
  298.                                     // $app['eccube.service.cart']->addProduct($resPocketalk[0]['product_class_id'], 1)->save();
  299.                                     if (!empty($resPocketalk)) {
  300.                                         $productClassIdPocketalk $resPocketalk[0]['product_class_id'];
  301.                                         // 数量をレンタル期間で決定(例: 90日なら quantity = 3 など)
  302.                                         $totalQuantityPocketalk ceil($optKikan 30); // 1ヶ月ごとに1つ加算
  303.                                         // 商品をカートに追加
  304.                                         $this->cartService->addProduct($productClassIdPocketalk$totalQuantityPocketalk);
  305.                                         // カートを保存
  306.                                         $this->cartService->save();
  307.                                     }
  308.                                 }
  309.                                 // 本体レンタル期間と同じ日数のSpare Wifi 3GBをカートに入れる
  310.                                 elseif ($arrOrderTappuri[$i] == "sparewifi3gb") {
  311.                                     switch ($order_plan) {
  312.                                         case "208":
  313.                                             $optKikan 90;
  314.                                             break;
  315.                                         case "209":
  316.                                             $optKikan 180;
  317.                                             break;
  318.                                         case "210":
  319.                                             $optKikan 360;
  320.                                             break;
  321.                                         case "867":
  322.                                             $optKikan 120;
  323.                                             break;
  324.                                         case "868":
  325.                                             $optKikan 150;
  326.                                             break;
  327.                                         case "872":
  328.                                             $optKikan 300;
  329.                                             break;
  330.                                         default:
  331.                                             $optKikan $kikan ?? 0;
  332.                                     }
  333.                                     $q "SELECT pc.id AS product_class_id, pc.product_id
  334.                                     FROM (SELECT id, product_id FROM dtb_product_class WHERE visible='1' AND product_code='Spare Wi-Fi 3GB') AS pc
  335.                                     LEFT JOIN dtb_product ON pc.product_id = dtb_product.id
  336.                                     WHERE dtb_product.product_status_id='1' AND dtb_product.kikan='" $optKikan "'";
  337.                                     $resSpareWifi3GB $this->connection->fetchAllAssociative($q);
  338.                                     // $app['eccube.service.cart']->addProduct($resSpareWifi3GB[0]['product_class_id'], 1)->save();
  339.                                     if (!empty($resSpareWifi3GB)) {
  340.                                         $productClassIdPocketalk $resSpareWifi3GB[0]['product_class_id'];
  341.                                         // 数量をレンタル期間で決定(例: 90日なら quantity = 3 など)
  342.                                         $totalQuantityPocketalk ceil($optKikan 30); // 1ヶ月ごとに1つ加算
  343.                                         // 商品をカートに追加
  344.                                         $this->cartService->addProduct($productClassIdPocketalk$totalQuantityPocketalk);
  345.                                         // カートを保存
  346.                                         $this->cartService->save();
  347.                                     }
  348.                                 }
  349.                             }
  350.                         }
  351.                         //セッションへ記録
  352.                         if ($this->session->get('order_st') != "") {
  353.                             $this->session->set('order_st'array_merge($this->session->get('order_st'), [$res[0]['product_class_id'] => $request->get('order_st')]));    // 商品ごと
  354.                         } else {
  355.                             $this->session->set('order_st', [$res[0]['product_class_id'] => $request->get('order_st')]);    // 商品ごと
  356.                         }
  357.                         $this->session->set('shipping_delivery_date'$request->get('shipping_delivery_date')); // 注文1件ごと
  358.                         if ($this->session->get('end_date') != "") {
  359.                             $this->session->set('end_date'array_merge($this->session->get('end_date'), [$res[0]['product_class_id'] => $request->get('end_date')]));    // 商品ごと
  360.                         } else {
  361.                             $this->session->set('end_date', [$res[0]['product_class_id'] => $request->get('end_date')]);    // 商品ごと
  362.                         }
  363.                 } catch (CartException $e) {
  364.                     $this->addRequestError($e->getMessage());
  365.                 }
  366.                 // 初期
  367.                 // return $app->redirect($app->url('cart', ['buystep' => 1]));
  368.                 // 次のページで右上のカートに一時的に商品入る
  369.                 // return $this->render('Cart/index.twig', [
  370.                 //     'totalQuantity' => $request->query->get('totalQuantity', 0), // クエリパラメータから取得
  371.                 // ]);
  372.                 //初期を少し改変
  373.                 return new RedirectResponse($this->urlGenerator->generate('cart', ['buystep' => 1]));
  374.                 // return $this->render('Cart/index.twig', [
  375.                 //     'totalQuantity' => $totalQuantity,
  376.                 // ]);
  377.                 // return $this->redirectToRoute('cart', ['buystep' => 1]);
  378.                 //念のためデータ表示
  379.                 $form->get('order_st')->setData($request->get('order_st'));
  380.                 $form->get('order_plan')->setData($request->get('order_plan'));
  381.                 $form->get('shipping_delivery_date')->setData($shipping_delivery_date);
  382.                 $form->get('end_date')->setData($end_date);
  383.                 $form->get('order_tappuri')->setData($request->get('order_tappuri'));
  384.             //エラーのときの再表示
  385.             }else{
  386.                 $form->get('order_st')->setData($request->get('order_st'));
  387.                 $form->get('order_plan')->setData($request->get('order_plan'));
  388.                 $form->get('shipping_delivery_date')->setData($shipping_delivery_date);
  389.                 $form->get('end_date')->setData($end_date);
  390.                 $form->get('order_tappuri')->setData($request->get('order_tappuri'));
  391.             }
  392.         }
  393.         // Clear shopping cart
  394.         if ($request->request->get('mode') == "set_cancel") {
  395.             $this->cartService->clear()->save();  // cartService を使ってカートをクリア
  396.             $session->remove('shipping_delivery_date');
  397.             $session->remove('end_date');
  398.         }
  399.         // 買い物を続けた場合、2回目の表示
  400.         // セッションへのアクセス
  401.         $session $request->getSession();
  402.         // セッションから値を取得
  403.         if ($session->get('shipping_delivery_date') != "") {
  404.             $SD_Flg $session->get('shipping_delivery_date');
  405.         } else {
  406.             $SD_Flg 2;
  407.         }
  408.         return $this->render('index.twig', [
  409.             'form' => $form->createView(),
  410.             'err' => $err,
  411.             'SD_Flg' => $SD_Flg,
  412.         ]);
  413.      }
  414.      public function getTotalPrice(Request $request)
  415.      {
  416.         // Ajaxリクエストからパラメータを取得
  417.         $product_code $request->request->get('product_code');
  418.         $product_id $request->request->get('product_id');
  419.         $kikan $request->request->get('num');
  420.         $insurance $request->request->get('insurance');
  421.         $charger $request->request->get('charger');
  422.         $adapter $request->request->get('adapter');
  423.         $sparewifi $request->request->get('sparewifi');
  424.         $sparewifi3gb $request->request->get('sparewifi3gb');
  425.         $pocketalk $request->request->get('pocketalk');
  426.         $total 0;
  427.         if ($product_code == 'Basic' || $product_code == 'SIM') {
  428.             // 価格を取得
  429.             $q "SELECT pc.id AS product_class_id, pc.price02, pc.product_id
  430.             FROM dtb_product_class AS pc
  431.             LEFT JOIN dtb_product AS pr ON pc.product_id = pr.id
  432.             WHERE pc.visible='1' AND pr.product_status_id='1' AND pc.product_code = :product_code AND pc.product_id = :product_id";
  433.         } else {
  434.             // 価格を取得
  435.             $q "SELECT pc.id AS product_class_id, pc.price02, pc.product_id
  436.             FROM dtb_product_class AS pc
  437.             LEFT JOIN dtb_product AS pr ON pc.product_id = pr.id
  438.             WHERE pc.visible='1' AND pr.product_status_id='1' AND pc.product_code = :product_code
  439.             AND pr.kikan = :kikan";
  440.         }
  441.         $res $this->connection->fetchAllAssociative($q, [
  442.             'product_code' => $product_code,
  443.             'product_id' => $product_id,
  444.             'kikan' => $kikan
  445.         ]);
  446.         foreach ($res as $item) {
  447.             $total += $item['price02'];
  448.         }
  449.         // 保険あり
  450.         if ($insurance == "true") {
  451.             // 価格を取得
  452.             $q "SELECT pc.id AS product_class_id, pc.price02, pc.product_id
  453.             FROM (SELECT * FROM dtb_product WHERE product_status_id = 1 AND name like '%Premium Insurance%day%' AND kikan = $kikan) pr
  454.             LEFT JOIN dtb_product_class AS pc ON pc.product_id = pr.id AND pc.visible='1'";
  455.             $res $this->connection->fetchAllAssociative($q, ['kikan' => $kikan]);
  456.             foreach ($res as $item) {
  457.                 $total += $item['price02'];
  458.             }
  459.         }
  460.         // バッテリーあり
  461.         if ($charger == "true") {
  462.             // 価格を取得
  463.             $q "SELECT pc.id  AS product_class_id, pc.price02, pc.product_id
  464.             FROM dtb_product_class AS pc
  465.             LEFT JOIN dtb_product AS pr ON pc.product_id=pr.id
  466.             WHERE pc.visible='1' AND pc.product_code='4589779235272' AND pr.product_status_id='1' AND pr.kikan='" $kikan "'";
  467.             $res $this->connection->fetchAllAssociative($q, ['kikan' => $kikan]);
  468.             foreach ($res as $item) {
  469.                 $total += $item['price02'];
  470.             }
  471.         }
  472.         // Travel Adapter あり
  473.         if ($adapter == "true") {
  474.             // 価格を取得
  475.             $q "SELECT pc.id  AS product_class_id, pc.price02, pc.product_id
  476.             FROM dtb_product_class AS pc
  477.             LEFT JOIN dtb_product AS pr ON pc.product_id=pr.id
  478.             WHERE pc.visible='1' AND pr.product_status_id='1' AND pc.product_id = '393'";
  479.             $res $this->connection->fetchAllAssociative($q);
  480.             foreach ($res as $item) {
  481.                 $total += $item['price02'];
  482.             }
  483.         }
  484.         // Spare Wifiあり
  485.         if ($sparewifi == "true") {
  486.             // 価格を取得
  487.             $q "SELECT pc.id  AS product_class_id, pc.price02, pc.product_id
  488.             FROM dtb_product_class AS pc
  489.             LEFT JOIN dtb_product AS pr ON pc.product_id=pr.id
  490.             WHERE pc.visible='1' AND pr.product_status_id='1' AND product_id = '461'";
  491.             $res $this->connection->fetchAllAssociative($q);
  492.             foreach ($res as $item) {
  493.                 $total += $item['price02'];
  494.             }
  495.         }
  496.         // Spare Wifi 3GB (日数別料金) あり
  497.         if ($sparewifi3gb == "true") {
  498.             // 価格を取得
  499.             $q "SELECT pc.id  AS product_class_id, pc.price02, pc.product_id
  500.             FROM dtb_product_class AS pc
  501.             LEFT JOIN dtb_product AS pr ON pc.product_id=pr.id
  502.             WHERE pc.visible='1' AND pc.product_code='Spare Wi-Fi 3GB' AND pr.product_status_id='1' AND pr.kikan='" $kikan "'";
  503.             $res $this->connection->fetchAllAssociative($q, ['kikan' => $kikan]);
  504.             foreach ($res as $item) {
  505.                 $total += $item['price02'];
  506.             }
  507.         }
  508.         // POCKETALKあり
  509.         if ($pocketalk == "true") {
  510.             // 価格を取得
  511.             $q "SELECT pc.id  AS product_class_id, pc.price02, pc.product_id
  512.             FROM dtb_product_class AS pc
  513.             LEFT JOIN dtb_product AS pr ON pc.product_id=pr.id
  514.             WHERE pc.visible='1' AND pc.product_code='POCKETALK' AND pr.product_status_id='1' AND pr.kikan='" $kikan "'";
  515.             $res $this->connection->fetchAllAssociative($q, ['kikan' => $kikan]);
  516.             foreach ($res as $item) {
  517.                 $total += $item['price02'];
  518.             }
  519.         }
  520.         // 為替レートを取得
  521.         $response $this->httpClient->request('GET''https://www.gaitameonline.com/rateaj/getrate');
  522.         $data $response->toArray();
  523.         if (empty($data)) {
  524.             $usd 0;
  525.         } else {
  526.             foreach ($data as $row) {
  527.                 foreach ($row as $r) {
  528.                     if ($r["currencyPairCode"] == "USDJPY") {
  529.                         $usd $total $r["ask"];
  530.                     }
  531.                 }
  532.             }
  533.         }
  534.         // レスポンスを返す(例:JSON形式)
  535.         return new JsonResponse(['total' => $total'usd' => $usd]);
  536.     }
  537.     public function addProductToCart($ProductClass$quantity 1)
  538.     {
  539.         if (!$ProductClass instanceof ProductClass) {
  540.             $ProductClassId $ProductClass;
  541.             $ProductClass $this->entityManager
  542.                 ->getRepository(ProductClass::class)
  543.                 ->find($ProductClassId);
  544.             if (is_null($ProductClass)) {
  545.                 return false;
  546.             }
  547.         }
  548.         $ClassCategory1 $ProductClass->getClassCategory1();
  549.         if ($ClassCategory1 && !$ClassCategory1->isVisible()) {
  550.             return false;
  551.         }
  552.         $ClassCategory2 $ProductClass->getClassCategory2();
  553.         if ($ClassCategory2 && !$ClassCategory2->isVisible()) {
  554.             return false;
  555.         }
  556.         $newItem = new CartItem();
  557.         $newItem->setQuantity($quantity);
  558.         $newItem->setPrice($ProductClass->getPrice02IncTax());
  559.         $newItem->setProductClass($ProductClass);
  560.         // カートアイテムのマージ処理
  561.         $allCartItems $this->mergeAllCartItems([$newItem]);
  562.         $this->restoreCarts($allCartItems);
  563.         return true;
  564.     }
  565. }