<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
* 2024/05/10 Pico鈴木 サロンオーナーに会員登録用QRを出さないように修正
*/
namespace Customize\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
//追加
use Eccube\Controller\AbstractController;
use Customize\Repository\EigyoRepository;
use Customize\Repository\QRCodeMikiRepository;
use Customize\Repository\CustomerRepository;
class TopController extends AbstractController
{
/**
* @Route("/", name="homepage", methods={"GET"})
* @Template("index.twig")
*/
public function index()
{
/* Cookieに会員情報をセット */
$this->setCookieSenyoPage();
return [];
}
//専用ページにCookieで会員情報を渡すため以下追加
/**
* @var EigyoRepository
*/
protected $eigyoRepository;
/**
* @var QRCodeMikiRepository
*/
protected $qrcodeMikiRepository;
public function __construct(
EigyoRepository $eigyoRepository,
QRCodeMikiRepository $qrcodeMikiRepository
)
{
$this->eigyoRepository = $eigyoRepository;
$this->qrcodeMikiRepository = $qrcodeMikiRepository;
}
/**
* 専用ページ用Cookie設定処理
*/
private function setCookieSenyoPage()
{
$Customer = $this->getUser();
if ($Customer->getHostKono() != null) {
$bcKbn = $Customer->getBc()->getId();
$sibuCd = $Customer->getSibu()->getSibuCd();
$Eigyo = $this->eigyoRepository->findOneBy(['sibu_cd' => $Customer->getSibu()->getSibuCd(), 'eigyo_cd' => $Customer->getEigyoCd()]);
$eigyoCd = $Customer->getEigyoCd();
$hostKono = $Customer->getHostKono();
$qrPath = '';
$qrCCode = '';
$qrMikiPCode = '';
$qrMikiPath = '';
$qrSOSCode = '';
$qrSOPath = '';
if ($bcKbn != 5) {
//パートナー以外
if ($bcKbn != 6) {
//サロンオーナー以外
$qrPath = '/bsof/QRCode/' . $Customer->getSibu()->getSibuCd() . $Customer->getEigyoCd() . '.gif';
$qrCCode = $Eigyo->getCampaignCd10();
}
$QRCodeMiki = $this->qrcodeMikiRepository->findOneBy(['sibu_cd' => $Customer->getSibu()->getSibuCd(), 'eigyo_cd' => $Customer->getEigyoCd()]);
if (!is_null($QRCodeMiki)) {
$qrMikiPCode = $QRCodeMiki->getPcode();
$qrMikiPath = '/bsof/QRCodeMiki/' . $qrMikiPCode .'.gif';
}
//フォルダに該当ファイルがあるかチェック 例:/bsof/QRCodeSO/S3990009999_SSALONQRDUMY.gif
$qrFolder = $_SERVER["DOCUMENT_ROOT"] . "/bsof/QRCodeSO/";
$handle = opendir($qrFolder);
if (false == is_null($handle)){
while (false !== ($fileName = readdir($handle))){
if (is_file($qrFolder . $fileName)){
if (pathinfo($qrFolder . $fileName, PATHINFO_EXTENSION) == "gif"){
if (substr($fileName, 0, 11) == 'S' . $sibuCd . $eigyoCd . "9999"){
// ファイル名が前方一致したので、ファイル名からSコードを切り出す
$qrSOPath = "/bsof/QRCodeSO/" . $fileName;
$qrSOSCode = substr($fileName, 12, 12);
}
}
}
}
closedir($handle);
}
}
//ライフタイム=0,クッキーパス=/でクッキーを作成
setcookie('ec', serialize(array('bc_kbn'=>$bcKbn,
'sibu_cd'=>$sibuCd,
'eigyo_cd'=>$eigyoCd,
'host_kono'=>$hostKono,
'qr_path'=>$qrPath,
'qr_ccode'=>$qrCCode,
'qrmiki_path'=>$qrMikiPath,
'qrmiki_pcode'=>$qrMikiPCode,
'qrso_path'=>$qrSOPath,
'qrso_scode'=>$qrSOSCode)), 0, '/');
//WordPress側でUnSeiralizeできないためCSVで出力
setcookie('ec_wp', 'bc_kbn|' . $bcKbn .
',sibu_cd|' . $sibuCd .
',eigyo_cd|' . $eigyoCd .
',host_kono|' . $hostKono .
',qr_path|' . $qrPath .
',qr_ccode|' . $qrCCode .
',qrmiki_path|' . $qrMikiPath .
',qrmiki_pcode|' . $qrMikiPCode .
',qrso_path|' . $qrSOPath .
',qrso_scode|' . $qrSOSCode, 0, '/');
}
}
}