app/Plugin/ECCUBE4LineLoginIntegration42/LineLoginIntegrationEvent.php line 130

Open in your IDE?
  1. <?php
  2. namespace Plugin\ECCUBE4LineLoginIntegration42;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Eccube\Event\EventArgs;
  5. use Eccube\Event\TemplateEvent;
  6. use Eccube\Event\EccubeEvents;
  7. use Eccube\Entity\Master\CustomerStatus;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Psr\Container\ContainerInterface;
  10. use Symfony\Component\Form\FormFactoryInterface;
  11. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  12. use Plugin\ECCUBE4LineLoginIntegration42\Controller\LineLoginIntegrationController;
  13. use Plugin\ECCUBE4LineLoginIntegration42\Controller\Admin\LineLoginIntegrationAdminController;
  14. use Plugin\ECCUBE4LineLoginIntegration42\Entity\LineLoginIntegration;
  15. use Plugin\ECCUBE4LineLoginIntegration42\Repository\LineLoginIntegrationRepository;
  16. use Plugin\ECCUBE4LineLoginIntegration42\Repository\LineLoginIntegrationSettingRepository;
  17. use Symfony\Component\Routing\RouterInterface;
  18. use Twig\Environment as Twig;
  19. use Symfony\Component\HttpFoundation\RequestStack;
  20. class LineLoginIntegrationEvent implements EventSubscriberInterface
  21. {
  22.     private $lineLoginIntegrationRepository;
  23.     private $lineLoginIntegrationSettingRepository;
  24.     private $router;
  25.     private $session;
  26.     private $entityManager;
  27.     private $formFactory;
  28.     private $twig;
  29.     public function __construct(
  30.         LineLoginIntegrationRepository $lineLoginIntegrationRepository,
  31.         LineLoginIntegrationSettingRepository $lineLoginIntegrationSettingRepository,
  32.         RequestStack $requestStack,
  33.         Twig $twig,
  34.         EntityManagerInterface $entityManager,
  35.         RouterInterface $router,
  36.         FormFactoryInterface $formFactory
  37.     ) {
  38.         $this->lineLoginIntegrationRepository $lineLoginIntegrationRepository;
  39.         $this->lineLoginIntegrationSettingRepository $lineLoginIntegrationSettingRepository;
  40.         $this->router $router;
  41.         $this->session $requestStack->getSession();
  42.         $this->entityManager $entityManager;
  43.         $this->formFactory $formFactory;
  44.         $this->twig $twig;
  45.     }
  46.     public static function getSubscribedEvents()
  47.     {
  48.         return [
  49.             'Entry/index.twig' => [
  50.                 ['onRenderEntryIndex'10],
  51.                 ['onRenderLineEntryButton', -10]
  52.             ],
  53.             EccubeEvents::FRONT_ENTRY_INDEX_COMPLETE => 'onCompleteEntry',
  54.             'Entry/before.twig' => 'onRenderLineBeforeEntryButton',
  55.             'Mypage/login.twig' => 'onRenderLineLoginButton',
  56.             'Mypage/change.twig' => 'onRenderMypageChange',
  57.             'Shopping/login.twig' => 'onRenderShoppingLineLoginButton',
  58.             'Shopping/nonmember.twig' => 'onRenderNonmemberLineLoginButton',
  59.             EccubeEvents::FRONT_MYPAGE_CHANGE_INDEX_COMPLETE => 'onCompleteMypageChange',
  60.             EccubeEvents::FRONT_MYPAGE_WITHDRAW_INDEX_COMPLETE => 'onCompleteMypageWithdraw',
  61.             EccubeEvents::ADMIN_CUSTOMER_EDIT_INDEX_COMPLETE => 'onCompleteCustomerEdit',
  62.         ];
  63.     }
  64.     /**
  65.      * 新規会員登録画面の表示
  66.      * @param TemplateEvent $event
  67.      */
  68.     public function onRenderEntryIndex(TemplateEvent $event)
  69.     {
  70.         if (!$this->isLineSettingCompleted()) {
  71.             return;
  72.         }
  73.     }
  74.     /**
  75.      * 新規会員登録前の画面にLINEボタンを出力します
  76.      *
  77.      * @param TemplateEvent $event
  78.      */
  79.     public function onRenderLineBeforeEntryButton(TemplateEvent $event)
  80.     {
  81.         if (!$this->isLineSettingCompleted()) {
  82.             return;
  83.         }
  84.         $lineUserId $this->session->get(LineLoginIntegrationController::PLUGIN_LINE_LOGIN_INTEGRATION_SSO_USERID);
  85.         $linkUrl $this->router->generate("plugin_line_login", array(), UrlGeneratorInterface::ABSOLUTE_URL);
  86.         $imgUrl $this->router->generate("homepage", array(),
  87.                 UrlGeneratorInterface::ABSOLUTE_URL) . 'html/plugin/line_login_integration/assets/img/btn_register_base.png';
  88.         $snipet '';
  89.         $snipet_disabled '';
  90.         // LINEボタンを表示
  91.         if (empty($lineUserId)) {
  92.             $snipet .= '<a href="' $linkUrl '" class="line-button"><img src="{{ asset("assets/img/common/entry_line.png", "user_data") }}" alt="Lineログイン" style="max-width: 100%; border-radius: 10px;"></a>' PHP_EOL;
  93.             $snipet .= '<div class="line_btn_outer">' PHP_EOL;
  94.             $snipet .= '<img src="{{ asset("assets/img/common/line_relate_3000.png", "user_data") }}" alt="メールログイン" style="width: 277px;">' PHP_EOL;
  95.             $snipet .= '</div>' PHP_EOL;
  96.             $snipet_disabled .= '<img src="{{ asset("assets/img/common/entry_line_disabled.png", "user_data") }}" alt="Lineログイン" style="max-width: 100%; border-radius: 10px;">' PHP_EOL;
  97.             $snipet_disabled .= '<div class="line_btn_outer">' PHP_EOL;
  98.             $snipet_disabled .= '<img src="{{ asset("assets/img/common/line_relate_3000.png", "user_data") }}" alt="メールログイン" style="width: 277px;">' PHP_EOL;
  99.             $snipet_disabled .= '</div>' PHP_EOL;
  100.         }
  101.         $search '<div class="line_replace">';
  102.         $replace $search $snipet;
  103.         $source str_replace($search$replace$event->getSource());
  104.         $search2 '<div class="line_replace_disabled">';
  105.         $replace2 $search2 $snipet_disabled;
  106.         $source str_replace($search2$replace2$source);
  107.         $event->setSource($source);
  108.     }
  109.     /**
  110.      * 新規会員登録画面にLINEボタンを出力します
  111.      *
  112.      * @param TemplateEvent $event
  113.      */
  114.     public function onRenderLineEntryButton(TemplateEvent $event)
  115.     {
  116.         if (!$this->isLineSettingCompleted()) {
  117.             return;
  118.         }
  119.         $lineUserId $this->session->get(LineLoginIntegrationController::PLUGIN_LINE_LOGIN_INTEGRATION_SSO_USERID);
  120.         $linkUrl $this->router->generate("plugin_line_login", array(), UrlGeneratorInterface::ABSOLUTE_URL);
  121.         $imgUrl $this->router->generate("homepage", array(),
  122.                 UrlGeneratorInterface::ABSOLUTE_URL) . 'html/plugin/line_login_integration/assets/img/btn_register_base.png';
  123.         $snipet '';
  124.         // LINEボタンを表示
  125.         if (empty($lineUserId)) {
  126.             $snipet .= '<div style="font-weight: bold;">Lineのアカウントで会員登録をする</div>' PHP_EOL;
  127.             $snipet .= '<div style="margin-top: 20px; margin-bottom: 20px; font-size: 14px; line-height: 30px;">Lineのアカウントを使って新規登録ができます。<br>ログインメールアドレスを忘れにくいので便利です。</div>' PHP_EOL;
  128.             $snipet .= '<div style="max-width: 320px; margin: auto;">' PHP_EOL;
  129.             $snipet .= '<a href="' $linkUrl '" class="line-button"><img src="{{ asset("assets/img/common/entry_line.png", "user_data") }}" alt="Lineログイン" style="max-width: 100%; border-radius: 10px;"></a>' PHP_EOL;
  130.             $snipet .= '<div style="color: #525263; text-align: left; margin-bottom: 60px; font-size: 14px;letter-spacing: 1.5px; line-height: 30px;">' PHP_EOL;
  131.             $snipet .= '<img src="{{ asset("assets/img/common/line_relate_3000.png", "user_data") }}" alt="メールログイン" style="width: 277px;">' PHP_EOL;
  132.             $snipet .= '</div>' PHP_EOL;
  133.             $snipet .= '</div>' PHP_EOL;
  134.             $snipet .= PHP_EOL;
  135.         }
  136.         // LINEにログイン済みなので登録を促す
  137.         else {
  138.             $snipet .= '<div id="isLineLogined" class="col" style="margin-top:-10px; padding:10px;">LINEログイン済みです。<br>この会員登録が完了するとクーポンが獲得できます。</div>';
  139.             $snipet .= PHP_EOL;
  140.         }
  141.         $search '<div class="line_replace">';
  142.         $replace $search $snipet;
  143.         $source str_replace($search$replace$event->getSource());
  144.         $event->setSource($source);
  145.     }
  146.     /**
  147.      * 会員登録処理完了時のLINE連携処理
  148.      * @param EventArgs $event
  149.      */
  150.     public function onCompleteEntry(EventArgs $event)
  151.     {
  152.         if (!$this->isLineSettingCompleted()) {
  153.             return;
  154.         }
  155.         // 顧客とLINEユーザーIDをひも付け(line_login_integrationテーブルのレコードを作成)
  156.         log_info('LINEユーザーとの関連付け開始');
  157.         $lineUserId $this->session->get(LineLoginIntegrationController::PLUGIN_LINE_LOGIN_INTEGRATION_SSO_USERID);
  158.         $lineUserName $this->session->get(LineLoginIntegrationController::PLUGIN_LINE_LOGIN_INTEGRATION_SSO_USERNAME);
  159.         $lineUserAvator $this->session->get(LineLoginIntegrationController::PLUGIN_LINE_LOGIN_INTEGRATION_SSO_USERAVATOR);
  160.         if (!empty($lineUserId)) {
  161.             log_info('LINEログインしているため、ユーザーとの関連付けを実行');
  162.             $this->lineLoginIntegration $this->lineLoginIntegrationRepository->findOneBy(['line_user_id' => $lineUserId]);
  163.             if (empty($this->lineLoginIntegration)) {
  164.                 $customer $event['Customer'];
  165.                 log_info('LINE IDとユーザーの関連付けを開始', [$customer['id']]);
  166.                 $lineLoginIntegration = new LineLoginIntegration();
  167.                 $lineLoginIntegration->setLineUserId($lineUserId);
  168.                 $lineLoginIntegration->setLineUserName($lineUserName);
  169.                 $lineLoginIntegration->setLineUserAvatar($lineUserAvator);
  170.                 $lineLoginIntegration->setCustomer($customer);
  171.                 $lineLoginIntegration->setCustomerId($customer['id']);
  172.                 $this->entityManager->persist($lineLoginIntegration);
  173.                 $this->entityManager->flush($lineLoginIntegration);
  174.                 log_info('LINEユーザーとの関連付け終了');
  175.             }
  176.             log_info('LINEユーザーとの関連付け終了');
  177.         } else {
  178.             log_info('LINE未ログインのため関連付け未実施');
  179.         }
  180.     }
  181.     /**
  182.      * ログイン画面にLINEボタンを出力します
  183.      * @param TemplateEvent $event
  184.      */
  185.     public function onRenderLineLoginButton(TemplateEvent $event)
  186.     {
  187.         if (!$this->isLineSettingCompleted()) {
  188.             return;
  189.         }
  190.         $linkUrl $this->router->generate("plugin_line_login", array(), UrlGeneratorInterface::ABSOLUTE_URL);
  191.         $imgUrl $this->router->generate("homepage", array(),
  192.                 UrlGeneratorInterface::ABSOLUTE_URL) . 'html/plugin/line_login_integration/assets/img/btn_login_base.png';
  193.         // ログイン画面にLineログインボタンとLine経由の会員登録ボタンを表示する
  194.         $snipet_login '';
  195.         $snipet_login .= '<div class="ec-login__actions" style="margin-top: 40px;">' PHP_EOL;
  196.         $snipet_login .= '<div style="max-width: 320px; margin: auto;">' PHP_EOL;
  197.         $snipet_login .= '<a href="' $linkUrl '" class="line-button"><img src="{{ asset("assets/img/common/login-line.png", "user_data") }}" alt="Lineログイン" style="max-width: 100%; border-radius: 10px;"></a>' PHP_EOL;
  198.         $snipet_login .= '</div>' PHP_EOL;
  199.         $snipet_login .= '</div>' PHP_EOL;
  200.         $snipet_login .= '' PHP_EOL;
  201.         $search '<div class="line_login_replace">';
  202.         $replace $search $snipet_login;
  203.         $source str_replace($search$replace$event->getSource());
  204.         $event->setSource($source);
  205.         $snipet_entry_1 '';
  206.         $snipet_entry_1 .= '<div class="ec-login__actions" style="margin-top: 10px; margin-bottom: 40px;">' PHP_EOL;
  207.         $snipet_entry_1 .= '<div style="max-width: 320px; margin: auto;">' PHP_EOL;
  208.         $snipet_entry_1 .= '<a href="' $linkUrl '" class="line-button"><img src="{{ asset("assets/img/common/entry_line.png", "user_data") }}" alt="Lineログイン" style="max-width: 100%; border-radius: 10px;"></a>' PHP_EOL;
  209.         $snipet_entry_1 .= '<div style="color: #525263; text-align: center; margin-bottom: 20px; line-height: 30px;">' PHP_EOL;
  210.         $snipet_entry_1 .= '<img src="{{ asset("assets/img/common/line_relate_3000.png", "user_data") }}" alt="メールログイン" style="width: 277px;">' PHP_EOL;
  211.         $snipet_entry_1 .= '</div>' PHP_EOL;
  212.         $snipet_entry_1 .= '</div>' PHP_EOL;
  213.         $snipet_entry_1 .= '</div>' PHP_EOL;
  214.         $snipet_entry_1 .= '' PHP_EOL;
  215.         $search '<div class="line_entry_1_replace">';
  216.         $replace $search $snipet_entry_1;
  217.         $source str_replace($search$replace$event->getSource());
  218.         $event->setSource($source);
  219.         $snipet_entry_2 '';
  220.         $snipet_entry_2 .= '<div class="ec-login__actions" style="margin-top: 10px; margin-bottom: 40px;">' PHP_EOL;
  221.         $snipet_entry_2 .= '<div style="max-width: 320px; margin: auto;">' PHP_EOL;
  222.         $snipet_entry_2 .= '<a href="' $linkUrl '" class="line-button"><img src="{{ asset("assets/img/common/entry_line.png", "user_data") }}" alt="Lineログイン" style="max-width: 100%; border-radius: 10px;"></a>' PHP_EOL;
  223.         $snipet_entry_2 .= '<div style="color: #525263; text-align: center; margin-bottom: 20px; line-height: 30px;">' PHP_EOL;
  224.         $snipet_entry_2 .= '<img src="{{ asset("assets/img/common/line_relate_3000.png", "user_data") }}" alt="メールログイン" style="width: 277px;">' PHP_EOL;
  225.         $snipet_entry_2 .= '</div>' PHP_EOL;
  226.         $snipet_entry_2 .= '</div>' PHP_EOL;
  227.         $snipet_entry_2 .= '</div>' PHP_EOL;
  228.         $snipet_entry_2 .= '' PHP_EOL;
  229.         $search '<div class="line_entry_2_replace">';
  230.         $replace $search $snipet_entry_2;
  231.         $source str_replace($search$replace$event->getSource());
  232.         $event->setSource($source);
  233.     }
  234.     /**
  235.      * カート経由のログイン画面にLINEボタンを出力します
  236.      * @param TemplateEvent $event
  237.      */
  238.     public function onRenderShoppingLineLoginButton(TemplateEvent $event)
  239.     {
  240.         if (!$this->isLineSettingCompleted()) {
  241.             return;
  242.         }
  243.         $linkUrl $this->router->generate("plugin_line_login", array(), UrlGeneratorInterface::ABSOLUTE_URL);
  244.         $imgUrl $this->router->generate("homepage", array(),
  245.                 UrlGeneratorInterface::ABSOLUTE_URL) . 'html/plugin/line_login_integration/assets/img/btn_login_base.png';
  246.         // ログイン画面にLineログインボタンとLine経由の会員登録ボタンを表示する
  247.         $snipet_login '';
  248.         $snipet_login .= '<div class="ec-login__actions" style="margin-top: 40px;">' PHP_EOL;
  249.         $snipet_login .= '<div style="max-width: 320px; margin: auto;">' PHP_EOL;
  250.         $snipet_login .= '<a href="' $linkUrl '" class="line-button"><img src="{{ asset("assets/img/common/login-line.png", "user_data") }}" alt="Lineログイン" style="max-width: 100%; border-radius: 10px;"></a>' PHP_EOL;
  251.         $snipet_login .= '</div>' PHP_EOL;
  252.         $snipet_login .= '</div>' PHP_EOL;
  253.         $snipet_login .= '' PHP_EOL;
  254.         $search '<div class="line_login_replace">';
  255.         $replace $search $snipet_login;
  256.         $source str_replace($search$replace$event->getSource());
  257.         $event->setSource($source);
  258.         $snipet_entry_1 '';
  259.         $snipet_entry_1 .= '<div class="ec-login__actions" style="margin-top: 10px; margin-bottom: 40px;">' PHP_EOL;
  260.         $snipet_entry_1 .= '<div style="max-width: 320px; margin: auto;">' PHP_EOL;
  261.         $snipet_entry_1 .= '<a href="' $linkUrl '" class="line-button"><img src="{{ asset("assets/img/common/entry_line.png", "user_data") }}" alt="Lineログイン" style="max-width: 100%; border-radius: 10px;"></a>' PHP_EOL;
  262.         $snipet_entry_1 .= '<div style="color: #525263; text-align: center; margin-top: 10px; margin-bottom: 20px; line-height: 30px;">' PHP_EOL;
  263.         $snipet_entry_1 .= '<img src="{{ asset("assets/img/common/line_relate_3000.png", "user_data") }}" alt="メールログイン" style="width: 277px;">' PHP_EOL;
  264.         $snipet_entry_1 .= '</div>' PHP_EOL;
  265.         $snipet_entry_1 .= '</div>' PHP_EOL;
  266.         $snipet_entry_1 .= '</div>' PHP_EOL;
  267.         $snipet_entry_1 .= '' PHP_EOL;
  268.         $search '<div class="line_entry_1_replace">';
  269.         $replace $search $snipet_entry_1;
  270.         $source str_replace($search$replace$event->getSource());
  271.         $event->setSource($source);
  272.         $snipet_entry_2 '';
  273.         $snipet_entry_2 .= '<div class="ec-login__actions" style="margin-top: 10px; margin-bottom: 40px;">' PHP_EOL;
  274.         $snipet_entry_2 .= '<div style="max-width: 320px; margin: auto;">' PHP_EOL;
  275.         $snipet_entry_2 .= '<a href="' $linkUrl '" class="line-button"><img src="{{ asset("assets/img/common/entry_line.png", "user_data") }}" alt="Lineログイン" style="max-width: 100%; border-radius: 10px;"></a>' PHP_EOL;
  276.         $snipet_entry_2 .= '<div style="color: #525263; text-align: center; margin-top: 10px; margin-bottom: 20px; line-height: 30px;">' PHP_EOL;
  277.         $snipet_entry_2 .= '<img src="{{ asset("assets/img/common/line_relate_3000.png", "user_data") }}" alt="メールログイン" style="width: 277px;">' PHP_EOL;
  278.         $snipet_entry_2 .= '</div>' PHP_EOL;
  279.         $snipet_entry_2 .= '</div>' PHP_EOL;
  280.         $snipet_entry_2 .= '</div>' PHP_EOL;
  281.         $snipet_entry_2 .= '' PHP_EOL;
  282.         $search '<div class="line_entry_2_replace">';
  283.         $replace $search $snipet_entry_2;
  284.         $source str_replace($search$replace$event->getSource());
  285.         $event->setSource($source);
  286.     }
  287.     /**
  288.      * 配送情報入力画面にLINEボタンを出力します
  289.      * @param TemplateEvent $event
  290.      */
  291.     public function onRenderNonmemberLineLoginButton(TemplateEvent $event)
  292.     {
  293.         if (!$this->isLineSettingCompleted()) {
  294.             return;
  295.         }
  296.         $linkUrl $this->router->generate("plugin_line_login", array(), UrlGeneratorInterface::ABSOLUTE_URL);
  297.         $imgUrl $this->router->generate("homepage", array(),
  298.                 UrlGeneratorInterface::ABSOLUTE_URL) . 'html/plugin/line_login_integration/assets/img/btn_login_base.png';
  299.         // ログイン画面にLineログインボタンとLine経由の会員登録ボタンを表示する
  300.         $snipet_entry_1 '';
  301.         $snipet_entry_1 .= '<div class="ec-login__actions" style="margin-top: 10px;">' PHP_EOL;
  302.         $snipet_entry_1 .= '<div style="max-width: 300px; margin: auto; margin-bottom: 20px;">' PHP_EOL;
  303.         $snipet_entry_1 .= '<a href="' $linkUrl '" class="line-button"><img src="{{ asset("assets/img/common/entry_line.png", "user_data") }}" alt="Lineログイン" style="max-width: 100%; border-radius: 10px;"></a>' PHP_EOL;
  304.         $snipet_entry_1 .= '<div style="color: #525263; text-align: center; margin-bottom: 20px; line-height: 30px;">' PHP_EOL;
  305.         $snipet_entry_1 .= '<img src="{{ asset("assets/img/common/line_relate_3000.png", "user_data") }}" alt="メールログイン" style="width: 277px;">' PHP_EOL;
  306.         $snipet_entry_1 .= '</div>' PHP_EOL;
  307.         $snipet_entry_1 .= '</div>' PHP_EOL;
  308.         $snipet_entry_1 .= '</div>' PHP_EOL;
  309.         $snipet_entry_1 .= '' PHP_EOL;
  310.         $search '<div class="line_entry_replace">';
  311.         $replace $search $snipet_entry_1;
  312.         $source str_replace($search$replace$event->getSource());
  313.         $event->setSource($source);
  314.         $snipet_login '';
  315.         $snipet_login .= '<div class="ec-login__actions" style="margin-top: 10px;">' PHP_EOL;
  316.         $snipet_login .= '<div style="max-width: 300px; margin: auto; margin-bottom: 20px;">' PHP_EOL;
  317.         $snipet_login .= '<a href="' $linkUrl '" class="line-button"><img src="{{ asset("assets/img/common/login-line.png", "user_data") }}" alt="Lineログイン" style="max-width: 100%; border-radius: 10px;"></a>' PHP_EOL;
  318.         $snipet_login .= '</div>' PHP_EOL;
  319.         $snipet_login .= '</div>' PHP_EOL;
  320.         $snipet_login .= '' PHP_EOL;
  321.         $search '<div class="line_login_replace">';
  322.         $replace $search $snipet_login;
  323.         $source str_replace($search$replace$event->getSource());
  324.         $snipet_disabled '';
  325.         $snipet_disabled .= '<img src="{{ asset("assets/img/common/entry_line_disabled.png", "user_data") }}" alt="Lineログイン" style="max-width: 100%; border-radius: 10px;">' PHP_EOL;
  326.         $snipet_disabled .= '<div class="line_btn_outer">' PHP_EOL;
  327.         $snipet_disabled .= '<img src="{{ asset("assets/img/common/line_relate_3000.png", "user_data") }}" alt="メールログイン" style="width: 277px;">' PHP_EOL;
  328.         $snipet_disabled .= '</div>' PHP_EOL;
  329.         $search2 '<div class="line_replace_disabled">';
  330.         $replace2 $search2 $snipet_disabled;
  331.         $source str_replace($search2$replace2$source);
  332.         $event->setSource($source);
  333.     }
  334.     /**
  335.      * 会員情報変更画面の表示
  336.      * @param TemplateEvent $event
  337.      */
  338.     public function onRenderMypageChange(TemplateEvent $event)
  339.     {
  340.         if (!$this->isLineSettingCompleted()) {
  341.             return;
  342.         }
  343.         $form $event->getParameter('form');
  344.         $customerId $form->vars['value']['id'];
  345.         if (empty($customerId)) {
  346.             error_log("会員IDを取得できませんでした", [$form]);
  347.             return;
  348.         }
  349.         $lineLoginIntegration $this->lineLoginIntegrationRepository
  350.             ->findOneBy(['customer_id' => $customerId]);
  351.         $lineIdBySession $this->session
  352.             ->get(LineLoginIntegrationController::PLUGIN_LINE_LOGIN_INTEGRATION_SSO_USERID);
  353.         // LINEとの紐づけがないとき
  354.         if (empty($lineLoginIntegration)) {
  355.             // LINEのログインボタン表示
  356.             $linkUrl $this->router->generate("plugin_line_login", array(), UrlGeneratorInterface::ABSOLUTE_URL);
  357.             $imgUrl $this->router->generate("homepage", array(),
  358.                     UrlGeneratorInterface::ABSOLUTE_URL) . 'html/plugin/line_login_integration/assets/img/btn_register_base.png';
  359.             
  360.             $snipet '';
  361.             $snipet .= '<div class="ec-login__actions" style="margin-top: 10px; text-align: center;">' PHP_EOL;
  362.             $snipet .= '<div style="font-weight: bold;">Lineのアカウントを連携する</div>' PHP_EOL;
  363.             $snipet .= '<div style="margin-top: 20px; margin-bottom: 20px; font-size: 16px; line-height: 30px;">Lineでログインできるようになります。<br>ログイン情報が不要で便利です。</div>' PHP_EOL;
  364.             $snipet .= '<div style="max-width: 320px; margin: auto;">' PHP_EOL;
  365.             $snipet .= '<a href="' $linkUrl '" class="line-button"><img src="{{ asset("assets/img/common/relate-line.png", "user_data") }}" alt="Lineログイン" style="max-width: 100%; border-radius: 10px;"></a>' PHP_EOL;
  366.             $snipet .= '<div style="color: #525263; text-align: left; margin-bottom: 20px; line-height: 30px;">' PHP_EOL;
  367.             $snipet .= '<img src="{{ asset("assets/img/common/line_relate_3000.png", "user_data") }}" alt="メールログイン" style="width: 277px;">' PHP_EOL;
  368.             $snipet .= '</div>' PHP_EOL;            
  369.             $snipet .= '</div>' PHP_EOL;
  370.             $snipet .= '</div>' PHP_EOL;
  371.         }
  372.         // LINEとの紐づけがあっても、現在LINEにログインしていないっぽいとき
  373.         else if (empty($lineIdBySession)) {
  374.             // LINEのログインボタン表示
  375.             $linkUrl $this->router->generate("plugin_line_login", array(), UrlGeneratorInterface::ABSOLUTE_URL);
  376.             $snipet '<div style="max-width: 300px; margin: auto;">' PHP_EOL;
  377.             $snipet .= '<a href="' $linkUrl '" class="line-button"><img src="{{ asset("assets/img/common/login-line.png", "user_data") }}" alt="Lineログイン" style="max-width: 300px; border-radius: 10px;"></a>' PHP_EOL;
  378.             $snipet .= PHP_EOL;
  379.             $snipet .= '<div class="col" style="padding-bottom:10px;">LINEアカウントと連携済みですが、現在LINEでログインしていません。</div>';
  380.             $snipet .= PHP_EOL;
  381.             $snipet .= '</div>' PHP_EOL;     
  382.         }
  383.         // LINEとの紐づけがあって、かつLINEにログイン中のとき
  384.         else {
  385.             // 連携解除項目を追加
  386.             $this->replaceMypageChangeForm($event);
  387.             $snipet '<div class="col" style="padding-bottom:10px;">LINEアカウントを連携済です。</div>';
  388.             $snipet .= PHP_EOL;
  389.         }
  390.         $search '<div class="line_login_replace">';
  391.         $replace $search $snipet;
  392.         $source str_replace($search$replace$event->getSource());
  393.         $event->setSource($source);
  394.     }
  395.     /**
  396.      * 会員情報編集完了時のイベント処理を行います
  397.      *
  398.      * @param EventArgs $event
  399.      */
  400.     public function onCompleteMypageChange(EventArgs $event)
  401.     {
  402.         if (!$this->isLineSettingCompleted()) {
  403.             return;
  404.         }
  405.         $customerId $event['Customer']->getId();
  406.         $lineLoginIntegration $this->lineLoginIntegrationRepository->findOneBy(['customer_id' => $customerId]);
  407.         // LINEの紐づけがすでにあるとき
  408.         if (!empty($lineLoginIntegration)) {
  409.             $form $event['form'];
  410.             // LINE情報を削除する
  411.             if ($form->has('is_line_delete')) {
  412.                 $is_line_delete $form->get('is_line_delete')->getData();
  413.             }
  414.             if ($is_line_delete == 1) {
  415.                 // 連携解除
  416.                 $this->lineIdUnassociate($customerIdtrue);
  417.             }
  418.         }
  419.         // LINEの紐づけがないとき
  420.         else {
  421.             // 何もしない
  422.             // LINEとの紐づけ処理はログインのコールバック関数(LineLoginIntegrationController.php)内で行われるのでここでは行わない
  423.         }
  424.     }
  425.     /**
  426.      * 会員がマイページから退会手続きを行ったとき
  427.      *
  428.      * 退会した会員のLINE連携を解除する
  429.      *
  430.      * @param EventArgs $event
  431.      */
  432.     public function onCompleteMypageWithdraw(EventArgs $event)
  433.     {
  434.         if (!$this->isLineSettingCompleted()) {
  435.             return;
  436.         }
  437.         log_info('マイページから退会');
  438.         $customerId $event['Customer']['id'];
  439.         $this->lineIdUnassociate($customerIdtrue);
  440.     }
  441.     /**
  442.      * 管理画面から顧客情報を更新したとき
  443.      *
  444.      * 会員を退会にした場合にはLINE連携を解除する
  445.      *
  446.      * @param EventArgs $event
  447.      */
  448.     public function onCompleteCustomerEdit(EventArgs $event)
  449.     {
  450.         if (!$this->isLineSettingCompleted()) {
  451.             return;
  452.         }
  453.         $customerId $event['Customer']->getId();
  454.         $customerStatus $event['Customer']->getStatus();
  455.         // 退会扱いのとき
  456.         if ($customerStatus['id'] == CustomerStatus::WITHDRAWING) {
  457.             log_info('仮画面の会員情報編集ページから退会扱い');
  458.             $this->lineIdUnassociate($customerId);
  459.         }
  460.     }
  461.     /**
  462.      * LINE設定が初期化済みかチェックする
  463.      */
  464.     private function isLineSettingCompleted()
  465.     {
  466.         $lineLoginIntegrationSetting $this->lineLoginIntegrationSettingRepository
  467.             ->find(LineLoginIntegrationAdminController::LINE_LOGIN_INTEGRATION_SETTING_TABLE_ID);
  468.         if (empty($lineLoginIntegrationSetting)) {
  469.             log_error("Line Lineの情報が未設定です");
  470.             return false;
  471.         }
  472.         $lineChannelId $lineLoginIntegrationSetting->getLineChannelId();
  473.         if (empty($lineChannelId)) {
  474.             log_error("Line Channel Idが未設定です");
  475.             return false;
  476.         }
  477.         $lineChannelSecret $lineLoginIntegrationSetting->getLineChannelSecret();
  478.         if (empty($lineChannelSecret)) {
  479.             log_error("Line Channel Secretが未設定です");
  480.             return false;
  481.         }
  482.         return true;
  483.     }
  484.     /**
  485.      * LINEアカウントとの連携を解除する処理
  486.      *
  487.      * 会員IDから連携DBを検索し、該当するレコードを削除する処理。管理画面でなくフロントからのフローでは、
  488.      * セッションを削除するのでフラグをtrueにしておく
  489.      *
  490.      * @param int $customerId       LINEとの連携を解除したい会員ID
  491.      * @param bool $isDeleteSession セッションまで削除する。デフォでfalse
  492.      * @return bool                 会員がLINEと紐づけされていて、紐づけを解除したときにtrueを返す
  493.      */
  494.     private function lineIdUnassociate(int $customerId, ?bool $isDeleteSession null)
  495.     {
  496.         $lineLoginIntegration $this->lineLoginIntegrationRepository->findOneBy(['customer_id' => $customerId]);
  497.         // LINE情報を削除する
  498.         if (!empty($lineLoginIntegration)) {
  499.             log_info('customer_id:' $customerId 'のLINE連携を解除');
  500.             $this->lineLoginIntegrationRepository->deleteLineAssociation($lineLoginIntegration);
  501.             log_info('LINEの連携を解除しました');
  502.             if ($isDeleteSession) {
  503.                 $this->session->remove(LineLoginIntegrationController::PLUGIN_LINE_LOGIN_INTEGRATION_SSO_STATE);
  504.                 $this->session->remove(LineLoginIntegrationController::PLUGIN_LINE_LOGIN_INTEGRATION_SSO_USERID);
  505.                 if(isset($this->session->is_line_delete)) {
  506.                     $this->session->remove($this->session->is_line_delete);
  507.                 }
  508.             }
  509.             return true;
  510.         }
  511.         return false;
  512.     }
  513.     private function replaceMypageChangeForm(TemplateEvent $event)
  514.     {
  515.         log_info('LINE連携削除を追加');
  516.         $snipet $this->twig->getLoader()->getSourceContext('ECCUBE4LineLoginIntegration42/Resource/template/mypage_change_add_is_line_delete.twig')->getCode();
  517.         $search '{# エンティティ拡張の自動出力 #}';
  518.         $replace $search $snipet;
  519.         $source str_replace($search$replace$event->getSource());
  520.         $event->setSource($source);
  521.     }
  522. }