<?php
/**
* @version EC=CUBE4
* @copyright 株式会社 翔 kakeru.co.jp
* @author
* 2021年11月16日作成
*
* app\Customize\Service\CommonService.php
*
*
* 共通サービス
*
* YAML・EC-CUBE CONFIG の読み込み・サービス
*
* C= C= C= ┌(;・_・)┘トコトコ
******************************************************/
namespace Customize\Service;
use Doctrine\ORM\EntityManager;
use Eccube\Entity\Cart;
use Eccube\Entity\Master\DeviceType;
use Eccube\Entity\Order;
use Eccube\Entity\Page;
use Eccube\Entity\PageLayout;
use Eccube\Repository\BaseInfoRepository;
use Lm\Engine\EC\Entity\GoodsWithRelated;
use Detection\MobileDetect as MobileDetector;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Eccube\Common\EccubeConfig;
use Symfony\Component\Yaml\Yaml;
use Twig\Environment as Twig;
use Eccube\Entity\Layout;
use Eccube\Entity\Payment;
use Eccube\Repository\DeliveryFeeRepository;
use Lm\Entity\OrderHeader;
use Lm\Engine\NoukiKeisan\NoukiKeisan as NoukiEngine;
class CommonService
{
const RouteingFilename = 'Routeing.yaml';
const OliginalToken = 'OliginalToken';
const Session_Junction_Mode = 'Session_Junction_Mode';
const Lm_Order_Option_Session = 'Lm_Order_Option_Session';
const Lm_Order_Option = 'LmOrderOption';
const Lm_Option_Survey = 'survey';
const Lm_Option_Survey_Data = 'survey_data';
const Lm_Option_Coupon = 'coupon';
const Lm_Option_OrderId = 'order_id';
const Lm_Option_Catalog = 'catalog';
const Lm_Option_Receipt = 'receipt';
const RemoveCartItme = 'RemoveCartItme';
const Matrix_Token = 'matrix';
const MetaTagData = 'MetaTag.yaml';
const TOP_DIR = 'front-public/files/top/';
protected $Config;
protected $Container;
protected $Twig;
protected $PageRepository;
protected $RouteingYamlPath;
protected $LmPayments = [];
protected $BaseInfo;
protected $BaseInfoRepository;
protected $Session;
protected $Request;
protected $TokenStorage;
protected $LmHelper;
protected $MobileDetector;
protected $DeliveryFeeRepository;
/**
* @var OrderOptionsService
*/
protected $OrderOptionsService;
/**
* @var YamlService
*/
protected $YamlService;
public function __construct(
ContainerInterface $Container,
EccubeConfig $eccubeConfig,
BaseInfoRepository $BaseInfoRepository,
Twig $Twig,
SessionInterface $Session,
RequestStack $RequestStack,
TokenStorageInterface $TokenStorage,
LmHelper $LmHelper,
MobileDetector $mobileDetector,
DeliveryFeeRepository $DeliveryFeeRepository,
OrderOptionsService $OrderOptionsService,
YamlService $YamlService
)
{
$this->Container = $Container;
$this->Config = $eccubeConfig;
$this->RouteingYamlPath = $this->GetConfig('eccube_config_routes_dir');
$this->SetTwig($Twig);
$this->BaseInfoRepository = $BaseInfoRepository;
$this->Session = $Session;
$this->Request = $RequestStack->getCurrentRequest();
$this->TokenStorage = $TokenStorage;
$this->Router = $Container->get('router');
$this->LmHelper = $LmHelper;
$this->MobileDetector = $mobileDetector;
$this->DeliveryFeeRepository = $DeliveryFeeRepository;
$this->OrderOptionsService = $OrderOptionsService;
$this->YamlService = $YamlService;
}
/**
* コンフィグ取得する
* @param str コンフィグ名 null 全ての配列を返す
* @return {string,int,array} $Config
*/
public function GetConfig($Str = null)
{
if (!$Str) {
return $this->Config;
} else {
return $this->Config[$Str] ?? $Str;
}
}
/**
* Ymlファイルを配列で取得する
* @param $Yml str YMLファイル名
* @param %flg boolean true form 逆
* @param $Path str パス
* @return Array
*/
public function GetYaml($Yaml, $Flg = false, $Path = null)
{
return $this->YamlService->GetYaml($Yaml, $Flg, $Path);
}
/**
* Ymlファイルを書き込む
* @param $Add array 書き込む配列
* @param $Yml str YMLファイル名
* @param $Path str パス
* @return Array
*/
public function MergeYaml(array $Adds, $Yaml, $Path = null)
{
return $this->YamlService->MergeYaml($Adds, $Yaml, $Path);
}
/**
* Ymlファイルを書き込む
* @param $Data array 書き込む配列
* @param $Yml str YMLファイル名
* @param $Path str パス
*/
public function WriteYml(array $Data, $Yaml, $Path = null)
{
return $this->YamlService->WriteYml($Data, $Yaml, $Path);
}
/**
* BaseINfo
*/
public function GetBaseInfo($Param = null)
{
if (!is_array($this->BaseInfo)) {
#連想配列で格納
$BaseInfos = $this->BaseInfoRepository->get();
$SetName = function ($Keys) {
$Re = '';
foreach (explode('_', $Keys) as $Key) {
$Re .= ucfirst($Key);
}
return $Re;
};
foreach ($BaseInfos->ToNormalizedArray() as $Key => $BaseInfo) {
$Name = $SetName($Key);
switch ($Key) {
case 'postal_code':
$this->BaseInfo[$Name] = substr_replace($BaseInfo, '-', 3, 0);
break;
case 'Pref':
$Pref = $BaseInfos->getPref();
$this->BaseInfo[$Name] = $Pref->getName() ;
break;
case 'phone_number';
$this->BaseInfo[$Name] = $this->GetPhoneNumber($BaseInfo,false) ;
$this->BaseInfo['Tel'] = $BaseInfo;
break;
case 'fax_number';
$this->BaseInfo[$Name] = $this->GetPhoneNumber($BaseInfo,false) ;
$this->BaseInfo['Fax'] = $BaseInfo;
break;
case 'delivery_free_amount':
$this->BaseInfo['delivery_free_amounte'] = number_format((int)$BaseInfo);
$this->BaseInfo[$Name] = number_format((int)$BaseInfo);
break;
default:
$this->BaseInfo[$Name] = $BaseInfo;
break;
}
}
}
if (!$Param) {
return $this->BaseInfo;
}
return $this->BaseInfo[$Param] ?? '' ;
}
/**
* ルーティンファイルを書き込む
* @param $Yml str YMLファイル名
* @param $Add array 書き込む配列
* @param $flg boolean true 追加 false 上書き
* @param $Path str パス
* @return Array
*/
public function RouteYml(array $Data, $Yaml = self::RouteingFilename)
{
$Path = $this->RouteingYamlPath;
$Path .= $Yaml;
$Yml = '#' . date('Ymd') . ' ' . $Yaml . ' RouteYml ' . PHP_EOL;
$Yml .= Yaml::dump($Data);
$fp = fopen($Path, 'w');
fwrite($fp, $Yml);
fclose($fp);
}
/**
* Twig\Environment のセット
* @param Twig $Twig
*/
public function SetTwig(Twig $Twig)
{
$this->Twig = $Twig;
return $this;
}
/**
* Twig\Environment のゲット
*
* @return Twig
*/
public function GetTwig()
{
return $this->Twig;
}
/**
* ページレイアウトの設定
* @param $Nmae string URL の設定
* @param $isMobile
* @param $MetaTags メタタグ array() Author Description Keyword Robots MetaTags
* @param $LayoutId int レイアウトIDの変更
*
*/
public function SetPageLayout($Name, $isMobile = false, $MetaTags = [], $LayoutId = null)
{
$Globals = $this->Twig->getGlobals();
if (empty($Globals['Page']) || is_null($Globals['Page']->getId())) {
$Page = $this->GetPageByRoute($Name);
} else {
$Page = $Globals['Page'];
}
if (count($MetaTags) > 0) {
#メタタグの設定
//Author
if ($Author = $MetaTags['Author'] ?? null) {
$Page->setAuthor($Author);
}
//Description
if ($Description = $MetaTags['Description'] ?? null) {
$Page->setDescription($Description);
}
//Keyword
if ($Keyword = $MetaTags['Keyword'] ?? null) {
$Page->setKeyword($Keyword);
}
//Robots
if ($Robots = $MetaTags['Robots'] ?? null) {
$Page->setMetaRobots($Robots);
}
#MetaTags
if ($MetaTagss = $MetaTags['MetaTags'] ?? null) {
$Page->setMetaTags($MetaTagss);
}
}
#ページレイアウト
/**
* @var PageLayout[] $Layouts
*/
$Layouts = $Page->getPageLayouts();
if (empty($LayoutId)) {
//
$LayoutId = $Layouts[0]->getLayoutId() ?? Layout::DEFAULT_LAYOUT_UNDERLAYER_PAGE;
//
if ($isMobile) {
//
foreach ($Layouts as $pageLayout) {
//
if ($pageLayout->getDeviceTypeId() === DeviceType::DEVICE_TYPE_MB) {
//
$LayoutId = $pageLayout->getLayoutId();
}
}
}
}
$em = $this->Container->get('doctrine.orm.entity_manager');
$Layout = $em->getRepository(Layout::class)->find($LayoutId);
$this->Twig->addGlobal('Layout', $Layout);
$this->Twig->addGlobal('Page', $Page);
}
/**
* ページレイアウトの設定
* Eccube\Repository\PageRepository
* GetPageByRoute のコピー
*
* @param $Nmae string URL の設定
* @return Page
*/
protected function GetPageByRoute($Name)
{
/**
* @var EntityManager $em
*/
$em = $this->Container->get('doctrine.orm.entity_manager');
$Qb = $em->createQueryBuilder();
$Page = $Qb
->select(['p', 'pl', 'l'])
->from("Eccube\\Entity\\page", 'p')
->leftJoin('p.PageLayouts', 'pl')
->leftJoin('pl.Layout', 'l')
->where('p.url = :url')
->setParameter('url', $Name)
->getQuery()
->useResultCache(true, 3600)
->getSingleResult();
return $Page;
}
/**
* EC-CUBEの時間をセットする 通常EC-Cubeの時間はUTC
* 9時間引いたUTC
*
* @param $DataTime string 2016-10-18 16:19:02
* @param Flg boolean
*
* @return Flg=true UTC object
*/
public function SetEcTime($DataTime = null, $Flg = false)
{
$Data = new \DateTime($DataTime);
return $Flg ? $Data->modify('-9 hours') : $Data;
}
/**
* EC-CUBE URLのリダイレクト
*
*
* @param URL string
* @param param array()
*
*/
public function Redirect($Url, $Param = [])
{
$Router = $this->Container->get('router');
$Rout = $Router->generate($Url, $Param);
return new RedirectResponse($Rout);
exit;
}
/**
* EC-CUBE URLのリダイレクト
* shimfony のRedirectResponse ではリダイレクトしない場合がある
*
* @param URL string
* @param param array()
*
*/
public function Redirect2($Url, $Param = [])
{
$Router = $this->Container->get('router');
$Rout = $Router->generate($Url, $Param);
header('Location: ' . $Rout);
exit;
}
public function GetPhoneNumber($PhoneNumber, $Flg=true)
{
$PhoneNumber = str_replace(['-'], '', $PhoneNumber);
if (!$PhoneNumber) {
return $Flg ? [null,null,null] : null;
}
$RePhon[2] = substr($PhoneNumber, -4);
$AreaCodes = $this->GetYaml('PhoneNumber.yaml');
for ($i = 5; $i >= 2; $i--) {
$Code = substr($PhoneNumber, 0, $i);
if (isset($AreaCodes[$Code])) {
$RePhon[0] = $Code;
break;
}
}
$Len1 = strlen($PhoneNumber);
if (isset($RePhon[0])) {
$len2 = strlen($RePhon[0]);
$RePhon[1] = substr($PhoneNumber, $len2, $Len1 - $len2 - 4);
} else {
$RePhon[0] = substr($PhoneNumber, 0, $Len1 - 8);
$RePhon[1] = substr($PhoneNumber, $Len1 - 8, 4);
}
for ($i = 0; $i <= 2; $i++) {
if (!isset($RePhon[$i])) {
$RePhon[$i] = null;
}
}
return $Flg ? $RePhon : $RePhon[0] .'-' .$RePhon[1] .'-' . $RePhon[2];
}
/**
* 乱数を取得する
*
* @param int 桁数
* @return string 乱数
*/
public static function GetRand($Num)
{
$ReRand = '';
$Arr = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9));
for ($i = 0; $i < $Num; $i++) {
$ReRand .= $Arr[rand(0, count($Arr) - 1)];
}
return $ReRand;
}
public function GetLayout($LayoutId, $Page)
{
$em = $this->Container->get('doctrine.orm.entity_manager');
$Layout = $em->getRepository(Layout::class)->find($LayoutId);
$this->Container;
$T = $Page->getPageLayouts();
//foreach ($Page->getPageLayouts() as $key =>$d){
//echo $ke;
//}
return $Layout;
}
/**
* LM の支払いIDで EC-Cubuno支払い先をGETする
*
* @param inr LN paymentId
*
* @return ID`が NULLの場合 全ての配列を返す array()
* @return ID が ある場合 名前を返す
*/
public function GetLmPayment($Id = null)
{
if (count($this->LmPayments) < 1) {
$em = $this->Container->get('doctrine.orm.entity_manager');
$Payments = $em->getRepository(Payment::class)->findAll();
$Map = $this->GetYaml('PaymentMapping.yaml');
foreach ($Payments as $Payment) {
if (!$LmId = ($Map[$Payment->getId()] ?? 0)) {
continue;
}
$this->LmPayments[$LmId] = $Payment->getMethod();
}
}
return $Id ? $this->LmPayments[$Id] ?? NULL : $this->LmPayments;
}
/**
* オリジナルトークンを作成
*
* @param string $Cd トークン名
* @param string $name
* @param string $Value メッセージなど
*
* @param this
*/
public function SetToken($Cd, $Name = 'token', $Value = null)
{
$Token = $this->Session->get(self::OliginalToken) ?? [];
$Token[$Cd][$Name] = $Value ?? md5($this->GetRand(8));
$this->Session->set(self::OliginalToken, $Token);
return $this;
}
public function ResetToken($Cd, $Name = 'token', $Value = null){
return $this->RemoveToken($Cd)
->SetToken($Cd,$Name,$Value)
->GetToken($Cd,$Name);
}
/**
* オリジナルトークントークンを返す
*
* @param string $Cd
* @param string $Token
*
* @param string
*/
public function GetToken($Cd, $Name = 'token')
{
$Data = $this->Session->get(self::OliginalToken);
return $Data[$Cd][$Name] ?? null;
}
/**
* オリジナルトークントークンをリセット
* @param string $Cd
*
* @param string
*/
public function RemoveToken($Cd)
{
$Token = $this->Session->get(self::OliginalToken);
Unset($Token[$Cd]);
$this->Session->set(self::OliginalToken,$Token);
return $this;
}
/**
* YAML からアンケートを作成する
* @param string $YAML
* @param string $Param
*/
public function SetSurvey($Yaml = 'survey.yaml', $Param = self::Lm_Order_Option, $Option = null)
{
if (!$Option) {
$Option = $this->GetLmOrderOption(self::Lm_Option_Survey);
#1 初期化
$this->InitializeLmOrderOption(self::Lm_Option_Survey);
}
$Html = function ($flg, $Type, $Title, $Val, $Parameter, $Sub = '') use ($Param, $Option) {
if (0 != $flg) {
$Name = "name=\"{$Param}[" . self::Lm_Option_Survey . "][{$Title}][{$Val['name']}]\"";
} else {
$Name = "name=\"{$Param}[" . self::Lm_Option_Survey . "][$Title]\"";
}
switch ($Type) {
case 'select':
$Re = "<select {$Name} >";
$Datas = $Val['data'] ?? [];
foreach ($Datas as $Data) {
$Selected = '';
if ($Option) {
$Selected = $Data == ($Option[$Title][$Val['name']] ?? '') ? 'selected' : '';
}
$Re .= "<option value=\"{$Data}\" {$Selected}>{$Data}</oprion>";
}
$Re .= '</select>';
break;
case 'for':
$Name = rtrim($Name, '"') . '[]"';
$Re = '';
$Unit = $Parameter[$Val['name']]['unit'] ?? '';
foreach ($Val['data'] as $Key => $Data) {
$Da = explode('-', $Data);
$Re .= "<select {$Name}><option value=\"\"></oprion>";
for ($i = $Da[0]; $i <= $Da[1]; $i++) {
$Selected = '';
if ($Option) {
$Selected = $i == ($Option[$Title][$Val['name']][$Key] ?? '999') ? 'selected' : '';
}
$Re .= "<option value=\"{$i}\" $Selected>{$i}</oprion>";
}
$Re .= "</select>" . $Unit[$Key] ?? '';
}
break;
case 'text':
$Unit = $Parameter[$Val['name']]['unit'] ?? '';
$Value = $Option[$Title][$Val['name']] ?? $Val['data'];
$Re = "<input type=\"text\" {$Name} value=\"{$Value}\">" . $Unit;
break;
case 'radio';
deffault:
$Name = rtrim($Name, '"') . '[0]"';
$Checked = '';
if ($Option) {
$Checked = $Val == ($Option[$Title][0] ?? '') ? 'checked="chekced"' : '';
}
$Re = "<label><input type=\"radio\" {$Name} value=\"{$Val}\" {$Checked}>{$Val}</label>";
}
if (0 == $flg) {
$Re = "<p>{$Re}{$Sub}</p>";
}
return $Re;
};
$Re = '';
foreach ($this->GetYaml($Yaml) as $key => $Value) {
$Re .= "<div class=\"{$key}\"><p class =\"title\">{$Value['title']}</p>" . PHP_EOL;
foreach ($Value['data'] as $Data) {
$Sub = '';
if (is_array($Data)) {
$Val = key($Data);
$Arr = $Data[$Val];
$Type = $Arr['type'] ?? 'select';
$Parameter = $Value['parameter'] ?? '';
$Sub = $Html(1, $Arr['type'], $key, $Arr, $Parameter);
} else {
$Val = $Data;
}
$Type = $Data['type'] ?? 'radio';
$Parameter = '';
$Re .= $Html(0, $Type, $key, $Val, $Parameter, $Sub);
}
foreach ($Value['span'] ?? [] as $span) {
$Re .= "<span>{$span}</span>";
}
$Re .= '</div>' . PHP_EOL;
}
return $Re;
}
/**
* 2022/03/15
* LM orede option を初期化する
* アマゾンぺがあるために コントローラーではなくここでセット
*
*/
public function InitializeLmOrderOption($Name = null)
{
#1 初期化
if (is_null($Name)) {
$this->Session->set(self::Lm_Order_Option_Session, null);
return;
}
#2 $Name のみ
$Option = $this->Session->Get(self::Lm_Order_Option_Session);
unset($Option[$Name]);
$this->Session->set(self::Lm_Order_Option_Session, $Option);
return;
}
/**
* 2022/03/18
* LM orede option を初期化する
* アマゾンぺイがあるために コントローラーではなくここでセット
*
*/
public function SetInitiarizeLmOrederOption($OrderId)
{
$OptionOrderid = $this->GetLmOrderOption(self::Lm_Option_OrderId);
switch (true) {
case is_null($OptionOrderid):
case $OptionOrderid != $OrderId:
$Catalog = $this->GetLmOrderOption(self::Lm_Option_Catalog);
$this->InitializeLmOrderOption();
$this->AddLmOrderOption(self::Lm_Option_Catalog, $Catalog);
$this->AddLmOrderOption(self::Lm_Option_OrderId, $OrderId);
case $OptionOrderid == $OrderId:
default:
##
break;
}
return;
}
/**
* 2022/03/15
* LM orede option トする
* Shopping でできたDATAをconfirmでせっと
* 貸出サンプルのカタログ同梱 sample_catalog
* アンケート
*
*
* アマゾンぺイがあるために コントローラーではなくここでセット
*
*/
public function RequestLmOrderOption()
{
#2022/03/15 kakeru Order OPtion の取得
if ($Datas = $this->Request->get(self::Lm_Order_Option)) {
foreach ($Datas as $Name => $Data) {
$this->AddLmOrderOption($Name, $Data);
}
}
}
/**
* 2022/03/17
* LM orede option をセットする
* アマゾンぺイがあるために コントローラーではなくここでセット
*
*/
public function AddLmOrderOption($Name, $Data)
{
#2022/03/15 kakeru Order OPtion の取得
#1 Dataの取得
$Option = $this->Session->get(self::Lm_Order_Option_Session);
#2 設定
$Option[$Name] = $Data;
$this->Session->set(self::Lm_Order_Option_Session, $Option);
//
$this->OrderOptionsService->addOrderOptions($Name, $Data);
}
/**
* 2022/03/15
* LM orede option をセットする
* アマゾンぺイイがあるために コントローラーではなくここでセット
*
*/
public function GetLmOrderOption($Name = null)
{
return $this->OrderOptionsService->getOrderOptions($Name) ?: $this->_GetLmOrderOption($Name);
}
protected function _GetLmOrderOption($Name = null)
{
return $this->OrderOptionsService->_GetLmOrderOption($Name);
}
/**
* 確認画面にアンケートを表示する
* アンケートのDATaはバラバラなので ここで保存する
*
*/
public function SetSurveyData()
{
$Servey = $this->GetLmOrderOption(self::Lm_Option_Survey);
$Re = [];
foreach ($this->GetYaml('survey.yaml') as $key => $Value) {
$Text = '';
if (isset($Servey[$key][0])) {
$Re[] = $Value['title'];
foreach ($Servey[$key] as $Name => $Data) {
$Parameter = $Value['parameter'][$Name] ?? '';
$Unit = $Parameter['unit'] ?? '';
switch (true) {
case is_array($Data):
foreach ($Data as $i => $Da) {
$Text .= $Da . ($Unit[$i] ?? '') . ' ';
}
break;
default:
$Text .= $Data . $Unit . ' ';
break;
}
}
$Re[] = $Text;
}
}
$this->AddLmOrderOption(self::Lm_Option_Survey_Data, $Re);
return $Re;
}
/**
* デバイスの判定
*
* @param $strict
* @return string
* SP ・・・ スマホ
* PC ・・・ パソコン
* TB ・・・ タブレット ※パラメータ $strict = true 時のみ
*/
public function GetDevice($strict = false, MobileDetector $mobileDetector = null)
{
//
if ($mobileDetector === null) {
$mobileDetector = $this->MobileDetector;
}
//
if ($strict && $mobileDetector->isTablet()) {
// タブレット
return 'TB';
} else if ($mobileDetector->isMobile()) {
// スマホ
// $strict = false のとき、タブレットも含む。
return 'SP';
} else {
// PC
return 'PC';
}
}
/**
* 会員を取得する
*
*/
public function getUser()
{
if (null === $token = $this->TokenStorage->getToken()) {
return;
}
if (!is_object($user = $token->getUser())) {
// e.g. anonymous authentication
return;
}
return $user;
}
/**
* メッセージのbaseinfo config Messegeを 変換する
* 例
* {{BaseInfo.shop_name}}
* {{Config.Payment_Charge_free}}
* {{message.common.ResetPassward_messeg02}} or {{trans.common.ResetPassward_messeg02}}
*/
public function BaseInfo($Text){
if (preg_match('/^[A-Za-z0-9_]+$/',$Text)){
return $this->GetBaseInfo($Text);
}
while(preg_match("/\{\{(.+?)\}\}/",$Text,$Param)){
$Pa =explode('.',$Param[1]);
$Parameter = trim($Pa[1]);
$Value='';
switch (true) {
case preg_match('/BaseInfo\./i',$Param[1]):
$Value = $this->GetBaseInfo($Parameter);
break;
case preg_match('/Config\./i', $Param[1]):
$Value = $this->GetConfig($Parameter);
break;
case preg_match('/Message\.|trans\./i', $Param[1]):
$Parameter = preg_replace('/message\.|trans\./i','',$Param[1]);
$Value = trans($Parameter) ?? '' ;
break;
case preg_match('/url\./i', $Param[1]):
$Value = $this->Router->generate($Parameter);
break;
case preg_match('/Other\./i', $Param[1]):
switch ($Parameter){
case 'LargeDiscount':
$Value = $this->BaseInfoLageDiscount();
break;
case 'DeliveryFree';
$Value = $this->BaseInfoDeliveryFree();
break;
case 'Charge':
$Value = $this->BaseInfoCharge();
break;
}
break;
default:
$Value = $Parameter;
break;
}
if (!$Value){$Value=$Parameter;}
$Text = str_replace($Param[0],$Value,$Text);
}
return $Text;
}
/**
* 大口割引のDATAをもとに文字化する
*
* @return string
*/
protected function BaseInfoLageDiscount(){
$Re= [];
$LargeDiscount = $this->GetConfig('LargeDiscount');
foreach ($LargeDiscount as $Discount){
$Re[] =$Discount['more']/10000 .'万円以上で'.$Discount['discount'].'%';
}
return implode('、',$Re);
}
/**
* 全国一律 東京の運賃を算出
*
*/
protected function BaseInfoDeliveryFree(){
$DeliveryFee = $this->DeliveryFeeRepository->find(13);
return number_format($DeliveryFee->getFee());
}
protected function BaseInfoCharge(){
$em = $this->Container->get('doctrine.orm.entity_manager');
$Payment = $em->getRepository(Payment::class)->find(4);
return number_format($Payment->getCharge());
}
public function getSpOtherCategoryPulldownMap()
{
return array(
'item' => array(
'group_label' => '商品で探す',
'map' => array(
"/polo/" => 'ポロシャツ',
"/shirt/" => 'シャツ',
"/tshirt/" => 'Tシャツ',
"/staff/" => 'ジャンパー',
"/vest/" => 'ベスト',
"/warm/" => '防寒服',
"/sweat/" => 'トレーナー',
"/pants/" => 'パンツ',
"/food-uniform/cook-coat/" => 'コックコート',
"/apron/" => 'エプロン',
"/shirt/aloha/" => 'アロハシャツ',
"/happi/" => 'はっぴ',
"/cap/" => 'キャップ',
"/overall/" => 'つなぎ',
"/anzengutsu/" => '安全靴',
"/towel/" => 'タオル',
"/scrub/" => 'スクラブ',
"/bag/" => 'バッグ'
)
),
'use' => array(
'group_label' => '目的・用途で探す',
'map' => array(
"/kucho-fuku/" => '空調服®・エアークラフト',
"/work/" => '作業服',
"/jimufuku/" => '事務服',
"/hakui/" => '医療白衣',
"/food-uniform/" => '飲食店',
"/esthe-uniform/" => 'エステ',
"/election-item/" => '選挙用品',
"/care-wear/" => '介護服',
"/patrol/" => '防犯パトロール',
"/food-uniform/formal-vest/" => 'フォーマル',
)
)
);
}
/**
* @param $src
* @param $attrname
* @param array $dst
* @return string
*/
public static function addAttrRegexp($src, $attrname, array $dst)
{
$attrs = preg_replace_callback("/{$attrname}=\"([^\"]+)\"/", function ($matches) {
return $matches[1];
}, $src);
$attrs = explode(' ', $attrs);
$attrs = $dst + $attrs;
$attrs = implode(' ', $attrs);
return $attrs;
}
public function GetJunctionMode(){
return $this->Session->get(self::Session_Junction_Mode);
}
public function GetExclusionControl($Type, $Message = null)
{
$Message = $Message ?? $this->SetExclusionControl($Type, 1);
return ['errid' => 0 , 'message' => $Message ,'class_id'=>0 ,'add_lines' => null];
}
/**
* カート排他制御
*
*/
public function SetExclusionControl($Type ,$Flg)
{
$TypeName01 = $this->SetTypeName($this->LmHelper->GetCartType());
$TypeName02 = $this->SetTypeName($Type);
//$Url = $this->Router->generate('cart');
$Message = trans('front.ExclusionControl.message0' . $Flg);
$Message = str_replace('@TypeName01', $TypeName01, $Message);
$Message = str_replace('@TypeName02', $TypeName02, $Message);
//$Message = str_replace('@URL', $Url, $Message);
return $Message;
}
protected function SetTypeName($Type)
{
switch ($Type) {
case 3: #CartService::CartTypeSample:
$TypeName = trans('front.cart_Sample');
break;
case 4: #CartService::CartTypeCatalog:
$TypeName = trans('front.cart_catalog');
break;
case 101:
$TypeName = trans('front.Cart.Repeat');
break;
default:
$TypeName = trans('front.ExclusionControl.message03');
break;
}
return $TypeName;
}
/**
* 配列に一個でもNULLか空有白 がある
* @param array
*
* @return boolean ある true ない false
*/
public function IsNull($Data){
if(in_array(null, $Data,true)){return true;};
return in_array('', $Data,true);
}
/**
* app/Customize/Twig/Extension/ServiceExtension.php から移動
*
*/
public function GetPagename($UrlName)
{
$MetaTags = $this->GetYaml(self::MetaTagData);
return $MetaTags[$UrlName]['PageName'];
}
public function generateSetSiteTypeValueForCriteoReturn()
{
if ($this->MobileDetector->isTablet()) {
return 't';
} else if ($this->MobileDetector->isMobile()) {
return 'm';
} else {
return 'd';
}
}
public function get_page_type ($route = null) {
//
if (empty($route)) {
$route = $this->Request->get('_route');
}
$yahoo_retargeting_page_type = '';
// PC
switch (true) {
case $route === 'homepage':
// トップページ
$yahoo_retargeting_page_type = 'home';
break;
case $route === 'page/main-category':
case $route === 'page/sub-category':
// 商品一覧ページ - 親カテ・子カテ・コラム
$yahoo_retargeting_page_type = 'category';
break;
case $route === 'item_searchlist':
// 検索結果ページ
$yahoo_retargeting_page_type = 'search';
break;
case $route === 'item/detail':
// 商品詳細ページ
$yahoo_retargeting_page_type = 'detail';
break;
case $route === 'cart':
case $route === 'shopping_login':
case $route === 'shopping':
case $route === 'amazon_pay_shopping':
// 購入
// カートページ
$yahoo_retargeting_page_type = 'cart';
break;
case $route === 'shopping_confirm':
case $route === 'amazon_pay_shopping_confirm':
// 購入
// 購入、申込ページ(コンバージョン直前)
$yahoo_retargeting_page_type = 'conversionintent';
break;
case $route === 'shopping_complete':
// 購入
// コンバージョンページ
$yahoo_retargeting_page_type = 'conversion';
break;
}
return $yahoo_retargeting_page_type;
}
public function get_yahoo_retargeting_page_type ($route = null) {
//
return $this->get_page_type($route);
}
public function get_google_retargeting_item($goodsId, $google_business_vertical = 'retail')
{
try {
return GoodsWithRelated::getFeedGoodsByIdForGDN($goodsId, $google_business_vertical);
} catch (\Exception $e) {
return null;
}
}
public function get_yahoo_retargeting_item($goodsId, $quantity = 1)
{
try {
return GoodsWithRelated::getFeedGoodsByIdForYDN($goodsId, $quantity);
} catch (\Exception $e) {
return null;
}
}
public function EigyoubiCalendar()
{
$cal="";
// Google PSI対応
// ファイル・キャッシュ化
// / $s3 = new FileStoreService(env('S3_LM_DOC'), self::TOP_DIR);
// / $Filename = "1day4cal.inc";
// / $cal = $s3->getObject($Filename);
if (file_exists($filename = 'files/top/1day4cal.inc')) {
//
$cal = file_get_contents($filename);
}
//
return $cal;
}
/**
* @param Cart[] $carts
* @return int
*/
public function calculateTotalQuantityForCarts(array $carts = [])
{
//
$totalQuantity = 0;
//
foreach ($carts as $cart) {
//
$totalQuantity += $cart->getQuantity();
}
//
return $totalQuantity;
}
/**
* @param Order $order
* @return int
*/
public function calculateTotalQuantityForOrder(Order $order)
{
//
$totalQuantity = 0;
//
foreach ($order->getProductOrderItems() as $orderItem) {
//
$totalQuantity += $orderItem->getQuantity();
}
//
return $totalQuantity;
}
public function getSendScheduleDate($orderHeader, &$message = null)
{
if ($oh = OrderHeader::factory($orderHeader)) {
return (new NoukiEngine())->calculate($oh, null, $message);
}
return null;
}
}