<?php
/**
* @version EC=CUBE4
* @copyright 株式会社 翔 kakeru.co.jp
* @author
* 2021年11月29日作成
*
* app\Customize\Twig\Extension\ServiceExtension.php
*
* TWIGからサービスの呼び出し
*
*
*
* C= C= C= ┌(;・_・)┘トコトコ
******************************************************/
namespace Customize\Twig\Extension;
use Customize\Entity\CacheTrait;
use Customize\Service\FavoriteService;
use Customize\Service\GoodsPriceService;
use Customize\Service\Google\ReCaptchaService;
use Customize\Service\InventoryMatrixService;
use Customize\Service\OrderService;
use Customize\Service\Payment\PaymentService;
use Customize\Service\SampleService;
use DOMNamedNodeMap;
use DOMNode;
use Eccube\Entity\CartItem;
use Eccube\Entity\OrderItem;
use Eccube\Repository\ClassCategoryRepository;
use Eccube\Repository\ProductRepository;
use Lm\Engine\EC\Entity\GoodsWithRelated;
use Lm\Engine\EC\Entity\Item\Item;
use Lm\Engine\EC\Entity\OrderHeaderExtended;
use Lm\Engine\InventoryMatrix\InventoryMatrix;
use Lm\Engine\Zaiko\Yoyaku;
use Lm\Entity\Goods;
use Lm\Entity\OrderHeader;
use Lm\Service\Cache\CacheService;
use Lm\Util\Date;
use Detection\MobileDetect as MobileDetector;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
use Twig\TwigFilter;
use Twig\Environment as Twig;
use Customize\Service\LmHelper;
use Customize\Service\CustomerService;
use Customize\Service\CommonService;
use Eccube\Repository\ProductClassRepository;
use Eccube\Repository\OrderRepository;
use Eccube\Repository\Master\PrefRepository;
use Eccube\Repository\Master\JobRepository;
use Lm\Service\Db\SqlService;
use Lm\Engine\NoukiKeisan\NoukiKeisan as NoukiEngine;
use Customize\Service\CatalogService;
use Customize\Service\CartService;
use Customize\Service\GoodsService;
use Customize\Service\MetaTagService;
use Customize\Service\EstimateCharacterizer;
use Eccube\Repository\Master\OrderItemTypeRepository;
use Customize\Converter\OrderConverter;
use Customize\Service\OrderHelper;
use Customize\Service\AutoLoadService;
use Customize\Service\MobileDetector as LmMobileDetector;
use Lm\Engine\SokujitsuHassou\SokujitsuHassou;
use Twig\TwigTest;
use Customize\Converter\ProductConverter;
class ServiceExtension extends AbstractExtension
{
use CacheTrait;
const Cache1 = 'EstimateProductClassIds';
const MetatagTwig = 'Common/MetaTags.twig';
const BreadCrumTwig = 'Common/BreadCrumb.twig';
const EstimateTwig = 'Common/Estimate.twig';
const ExclusionTwig = 'Cart/Parts/Exclusion.twig';
const CartAddLineTwig = 'Cart/Parts/Responsive/AddLine.twig';
const ShoppingEstimate = 'Shopping/Parts/Estimate.twig';
const MobileShoppingEstimate = 'Common/MobileEstimate.twig';
const MailEstimate = 'Mail/Parts/Estimate.twig';
const JWeek = ['日', '月', '火', '水', '木', '金', '土'];
/**
* @var Container
*/
protected $Container;
protected $Session;
protected $RequestStack;
protected $LmHelper;
protected $CustomerService;
protected $CommonService;
protected $PrefRepository;
protected $JobRepository;
protected $Router;
protected $Request;
protected $CatalogService;
protected $CartService;
protected $CatalogValue;
protected $GoodsService;
protected $Twig;
/**
* @var ProductRepository
*/
private $ProductRepository;
protected $ProductClassRepository;
protected $Bank;
protected $CacheService;
protected $MetaTagService;
protected $EstimateCharacterizer;
protected $OrderItemTypeRepository;
protected $PaymentDetails = [];
protected $EstimateOptions = [];
protected $OrderConverter;
protected $OrderRepository;
protected $EstimateType;
protected $AutoLoadService;
protected $CartSortFlg;
/**
* @var MobileDetector
*/
private $mobileDetector;
/**
* @var LmMobileDetector
*/
private $LmMobileDetector;
/**
* @var FavoriteService
*/
private $FavoriteService;
/**
* @var SampleService
*/
private $SampleService;
/**
* @var OrderService
*/
private $OrderService;
private $paymentService;
private $reCaptchaService;
private $productConverter;
public function __construct(ContainerInterface $Container,
SessionInterface $Session,
RequestStack $RequestStack,
LmHelper $LmHelper,
CustomerService $CustomerService,
CommonService $CommonService,
PrefRepository $PrefRepository,
JobRepository $JobRepository,
CatalogService $CatalogService,
CartService $CartService,
GoodsService $GoodsService,
Twig $Twig,
ProductRepository $productRepository,
ProductClassRepository $ProductClassRepository,
ClassCategoryRepository $ClassCategoryRepository,
CacheService $CacheService,
MetaTagService $MetaTagService,
EstimateCharacterizer $EstimateCharacterizer,
OrderItemTypeRepository $OrderItemTypeRepository,
OrderService $orderService,
OrderConverter $OrderConverter,
OrderRepository $OrderRepository,
GoodsPriceService $GoodsPriceService,
AutoLoadService $AutoLoadService,
MobileDetector $mobileDetector,
LmMobileDetector $LmMobileDetector,
FavoriteService $FavoriteService,
SampleService $SampleService,
PaymentService $paymentService,
InventoryMatrixService $inventoryMatrixService,
ReCaptchaService $reCaptchaService,
ProductConverter $productConverter
)
{
$this->Container = $Container;
$this->Session = $Session;
$this->RequestStack = $RequestStack;
$this->LmHelper = $LmHelper;
$this->CustomerService = $CustomerService;
$this->CommonService = $CommonService;
$this->PrefRepository = $PrefRepository;
$this->JobRepository = $JobRepository;
$this->Router = $Container->get('router');
$this->Request = $RequestStack->getCurrentRequest();
$this->CatalogService = $CatalogService;
$this->CartService = $CartService;
$this->GoodsService = $GoodsService;
$this->Twig = $Twig;
$this->ProductRepository = $productRepository;
$this->ProductClassRepository = $ProductClassRepository;
$this->ClassCategoryRepository = $ClassCategoryRepository;
$this->CacheService = $CacheService;
$this->MetaTagService = $MetaTagService;
$this->EstimateCharacterizer = $EstimateCharacterizer;
$this->OrderItemTypeRepository = $OrderItemTypeRepository;
$this->OrderService = $orderService;
$this->OrderConverter = $OrderConverter;
$this->OrderRepository = $OrderRepository;
$this->GoodsPriceService = $GoodsPriceService;
$this->AutoLoadService = $AutoLoadService;
$this->mobileDetector = $mobileDetector;
$this->LmMobileDetector = $LmMobileDetector;
$this->FavoriteService = $FavoriteService;
$this->SampleService = $SampleService;
$this->paymentService = $paymentService;
$this->inventoryMatrixService = $inventoryMatrixService;
$this->reCaptchaService = $reCaptchaService;
$this->productConverter = $productConverter;
}
public function getFunctions()
{
return [
new TwigFunction('Service', function ($Service) {
return new $Service($this->Container, $this->RequestStack);
}, ['pre_escape' => 'html', 'is_safe' => ['html']]),
new TwigFunction('LmCssList', [$this, 'GetLmCssList']),
new TwigFunction('LmCartType', [$this, 'GetLmCartType']),
new TwigFunction('FristLogin', [$this, 'GetFirstLogin']),
new TwigFunction('AmazonLogin', [$this, 'GetAmazonLogin']),
new TwigFunction('GetPrefs', [$this, 'GetPrefs']),
new TwigFunction('GetLmCuatomer', [$this, 'GetLmCuatomer']),
new TwigFunction('GetJob', [$this, 'GetJob']),
new TwigFunction('GetPrivacy3', [$this, 'GetPrivacy3']),
new TwigFunction('OlToken', [$this, 'GetOlToken']),
new TwigFunction('RequestLmOrderOption', [$this->CommonService, 'RequestLmOrderOption']),
new TwigFunction('Survey', [$this->CommonService, 'SetSurvey']),
new TwigFunction('SurveyData', [$this->CommonService, 'SetSurveyData']),
new TwigFunction('RequestUri', [$this, 'GetRequestUri']),
new TwigFunction('CouponData', [$this, 'GetCouponData']),
new TwigFunction('InitiarizeLmOrederOption', [$this, 'SetInitiarizeLmOrederOption']),
new TwigFunction('DiscountName', [$this, 'SetDiscountName']),
new TwigFunction('SetReceipt', [$this, 'SetReceipt']),
new TwigFunction('Receipt', [$this, 'GetReceipt']),
new TwigFunction('LmOptionName', [$this, 'GetLmOptionName']),
new TwigFunction('CatalogLimit', [$this->CatalogService, 'GetLimit']),
new TwigFunction('CatalogLimitMessage', [$this, 'CatalogLimitMessage']),
new TwigFunction('CatalogValidation', [$this->CatalogService, 'CatalogValidation']),
new TwigFunction('CatalogChecked', [$this, 'GetCatalogChecked']),
new TwigFunction('ShoppingTitle', [$this, 'SetShoppingTitle']),
new TwigFunction('ShoppingConfirmBtn', [$this, 'ShoppingConfirmBtn']),
new TwigFunction('GetCatalogViews', [$this, 'GetCatalogViews']),
new TwigFunction('GetSampleCatalogs', [$this->CatalogService, 'GetSampleCatalogs']),
new TwigFunction('CartSumImage', [$this, 'GetCartSumImage']),
new TwigFunction('GoodsMainImage', [$this, 'GetGoodsMainImage']),
new TwigFunction('CartItemPullDown', [$this, 'GetCartItemPullDown']),
new TwigFunction('LoadStockLabel', [$this, 'getStockLabel']),
new TwigFunction('CartItemSizePullDown', [$this, 'GetCartItemSizePullDown']),
new TwigFunction('CartItemColorPullDown', [$this, 'GetCartItemColorPullDown']),
new TwigFunction('lm_tax', [$this, 'GetLmTax']),
new TwigFunction('Caet_item_stock', [$this, 'GetCartItmeStock']),
new TwigFunction('CartItemSameDayShippingFlg', [$this, 'GetCartItemSameDayShippingFlg']),
new TwigFunction('CartItemStockNumber', [$this, 'GetCartItemStockNumber']),
new TwigFunction('GetConfig', [$this, 'GetConfig']),
new TwigFunction('GetCartNextBtnText', [$this, 'GetCartNextBtnText']),
new TwigFunction('GetCartBackBtnText', [$this, 'GetCartBackBtnText']),
new TwigFunction('GetShoppingNextBtnText', [$this, 'GetShoppingNextBtnText']),
new TwigFunction('GetShoppingBackBtnText', [$this, 'GetShoppingBackBtnText']),
new TwigFunction('GetLmOrderOption', [$this, 'GetLmOrderOption']),
new TwigFunction('Bank', [$this, 'GetBank']),
new TwigFunction('JunctionMode', [$this->CommonService, 'GetJunctionMode']),
new TwigFunction('CartHybridBtn', [$this, 'SetCartHybridBtn']),
new TwigFunction('CartHybridBtnByCartItem', [$this, 'ShowCartHybridBtnByCartItem']),
new TwigFunction('ShowOrderItem', [$this, 'SetShowOrderItem']),
new TwigFunction('ExclusionControl', [$this, 'SetExclusionControl']),
new TwigFunction('SetMetaTags', [$this, 'SetMetaTags']),
new TwigFunction('HeaderH1', [$this, 'SetHeaderH1']),
new TwigFunction('SetBreadCrumb', [$this, 'SetBreadCrumb']),
new TwigFunction('EstimateCharaCart', [$this, 'SetEstimateCharaCart']),
new TwigFunction('ItemType', [$this, 'GetItemType']),
new TwigFunction('isSliderEnabled', [$this, 'isSliderEnabled']),
new TwigFunction('PaymentDetails', [$this, 'GetPaymentDetails']),
new TwigFunction('SetEstimateOptions', [$this, 'SetEstimateOptions']),
new TwigFunction('GetEstimateOption', [$this, 'GetEstimateOption']),
new TwigFunction('ShowEstimateOptions', [$this, 'ShowEstimateOptions']),
new TwigFunction('ShowEstimateMobileOptions', [$this, 'ShowEstimateMobileOptions']),
new TwigFunction('ShowEstimateOptionsMail', [$this, 'ShowEstimateOptionsMail']),
new TwigFunction('ZeusCardDatas', [$this, 'GetZeusCardDatas']),
new TwigFunction('ZeusCardError', [$this, 'GetZeusCardError']),
new TwigFunction('EstimateType', [$this, 'GetEstimateType']),
new TwigFunction('GetCustomerBangou', [$this, 'GetCustomerBangou']),
new TwigFunction('NariKawariSession', [$this->AutoLoadService, 'GetNariKawariSession']),
new TwigFunction('NariKawariFormData', [$this->AutoLoadService, 'GetNariKawariFormData']),
new TwigFunction('GetCatalogNoukiSchedule', [$this, 'getCatalogNoukiSchedule']),
new TwigFunction('CartSortFlg', [$this, 'GetCartSortFlg']),
new TwigFunction('CartAddLine', [$this, 'GetCartAddLine']),
new TwigFunction('PageType', [$this, 'getPageType']),
new TwigFunction('isMobile', [$this, 'isMobile']),
new TwigFunction('wannaSeePc', [$this, 'wannaSeePc']),
new TwigFunction('CartBackBtn', [$this, 'GetCartBackBtn']),
new TwigFunction('WithGetParams', [$this, 'WithGetParams']),
new TwigFunction('PageWithGetParams', [$this, 'PageWithGetParams']),
new TwigFunction('ShowSendScheduleDate', [$this, 'showSendScheduleDate']),
new TwigFunction('ShowSendScheduleMessage', [$this, 'showSendScheduleMessage']),
new TwigFunction('GetCategoryImageUrlById', [$this, 'getCategoryImageUrlById']),
new TwigFunction('EigyoubiCalendar', [$this->CommonService, 'EigyoubiCalendar']),
new TwigFunction('GetOrderPaymentId', [$this, 'getOrderPaymentId']),
new TwigFunction('GetShippingAddr03', [$this->CustomerService, 'getShippingAddr03']),
new TwigFunction('GetLandMarkCustomerInfo', [$this->CustomerService, 'GetLandMarkCustomerId']),
new TwigFunction('CalculateTotalQuantityForOrder', [$this->CommonService, 'calculateTotalQuantityForOrder']),
new TwigFunction('getMessageForPayment', [$this->paymentService, 'getMessage']),
new TwigFunction('GetFavoriteFlashMessage', [$this->FavoriteService, 'getFavoriteFlashMessage']),
new TwigFunction('GetFavoriteFlashGoods', [$this->FavoriteService, 'getFavoriteFlashGoods']),
new TwigFunction('FileUploadNotice', [$this, 'showFileSizeUpload']),
new TwigFunction('GetSampleLimitError', [$this->SampleService, 'getSampleLimitError']),
new TwigFunction('formatDataToJson', [$this, 'formatDataToJson']),
new TwigFunction('getCurrentBreadcrumb', [$this, 'getCurrentBreadcrumb']),
new TwigFunction('getCartSessionName', [$this, 'getCartSessionName']),
new TwigFunction('groupItemsHasSameProductId', [$this, 'groupItemsHasSameProductId']),
new TwigFunction('getColorRGBCode', [$this, 'getColorRGBCode']),
new TwigFunction('formatDate', [$this, 'formatDate']),
new TwigFunction('formatMonthAndDay', [$this, 'formatMonthAndDay']),
new TwigFunction('getToTraceParent', function () {
return $this->RequestStack->getCurrentRequest()->attributes->get('toTraceParent');
}),
new TwigFunction('getTrackId', function () {
return $this->RequestStack->getCurrentRequest()->attributes->get('toTrackId');
}),
new TwigFunction('getInventoryMatrix', [$this, 'getInventoryMatrixData']),
new TwigFunction('shouldProcessReCaptcha', [$this->reCaptchaService, 'shouldProcessReCaptcha']),
new TwigFunction('showYoyakuFlag', [$this, 'showYoyakuFlag']),
new TwigFunction('showSokujitsuHassouBannerIfSo', [$this, 'showSokujitsuHassouBannerIfSo']),
];
}
/**
* Get inventory matrix via cache
*
* @param GoodsWithRelated $goods
* @param $color
* @param $size
* @return mixed|null
* @throws \Psr\Cache\InvalidArgumentException
*/
public function getInventoryMatrixData(GoodsWithRelated $goods, &$color = null, &$size = null)
{
$cacheKey = $this->LmHelper->getCacheKey("getInventoryMatrixData", [$goods, $color, $size]);
$id = $goods->getGoodsId();
$stock = $this->GoodsService->getGoodsStock($id, 1); // value of stock is not should cache
return $this->getCacheByKey($cacheKey, function () use ($goods, $color, $size, $stock, $id) {
// JAN情報(=product_class id)
list($jan, $janColor) = $this->productConverter->getGoodsJanById($id);
// 色情報
$color = $this->GoodsService->getGoodsColorSelectSql($id);
// サイズ情報
$size = $this->GoodsService->getGoodsSizeListById($id);
// 商品即日情報
$sokujitsu = $this->GoodsService->getGoodsSameDayShipping($id, 1);
// 商品在庫情報
// 商品予約情報
$yoyaku = $this->GoodsService->getGoodsReservation($id, 1);
// 商品入荷予定日情報
$yoteibi = $this->GoodsService->getGoodsStockDate($id, 1);
// カートマトリックス用のデータ生成
$matrixData = [];
$matrixData_cnt = [];
$line = 0;
$sizeMax = ($this->LmMobileDetector->isMobile() ? 999 : 8);
$max = 0;
foreach ($color as $v1) {
$line++;
$line2 = 0;
$no = 1;
foreach ($size as $v2) {
if ($line2 % ($sizeMax) === 0) {
$no++;
} else {
$max = $line2 % ($sizeMax);
}
$tmpYoteibi = NULL;
if (!empty($yoteibi[$v1["gcl_id"]][$v2["gp_id"]]) and $sokujitsu[$v1["gcl_id"]][$v2["gp_id"]] <= SokujitsuHassou::FLG_NONE) {
$tmpYoteibi = date("n月j日", strtotime($yoteibi[$v1["gcl_id"]][$v2["gp_id"]]));
}
$matrixData_cnt[$no] = $max;
$matrixData[$no][$line][$line2] = [
'line' => $line,
'product_id' => $jan[$v1["gcl_id"]][$v2["gp_id"]],
'shiire_color' => $janColor[$v1["gcl_id"]][$v2["gp_id"]],
'color' => $v1,
'size' => $v2,
'stock' => $stock[$v1["gcl_id"]][$v2["gp_id"]],
'yoyaku' => $yoyaku[$v1["gcl_id"]][$v2["gp_id"]],
'yoteibi' => $tmpYoteibi,
'sokujitsu' => $sokujitsu[$v1["gcl_id"]][$v2["gp_id"]],
];
$line2++;
}
}
return $matrixData;
});
}
public function getFilters()
{
return [
new TwigFilter('Base', [$this, 'BaseInfo']),
new TwigFilter('LmPrice', [$this, 'GetLmPrice']),
new TwigFilter('FormatPrice', [$this, 'FormatPrice']),
new TwigFilter('phone', [$this, 'SetPhone']),
new TwigFilter('post', [$this, 'SetPost']),
new TwigFilter('jweek', [$this, 'SetJWeek']),
new TwigFilter('AjaxPrice', [$this->GoodsPriceService, 'embedGoodsPrice']),
new TwigFilter('OrderId', [$this->LmHelper, 'convertOrderToOrderId']),
new TwigFilter('InventoryMatrix', [$this, 'showInventoryMatrix']),
new TwigFilter('LmWebTeika', [$this, 'filterLmWebTeika']),
new TwigFilter('LmWebPrice', [$this, 'filterLmWebPrice']),
];
}
public function getTests()
{
return [
new TwigTest('numeric', 'is_numeric'),
];
}
/**
* Master Job をゲットする
*
* @return obj Job
*/
public function GetPrefs()
{
return $this->PrefRepository->finsBy([], ['sort_no' => 'asc']);
}
public function GetJob()
{
return $this->JobRepository->findBy([], ['sort_no' => 'asc']);
}
/**
* TWIG に LMカートタイプを返す
* cart_type:
* 1 -- 購入(加工なし)
* 2 -- 購入(加工あり(加工なしとの混在含む))
* 3 -- 貸出サンプル
* 4 -- カタログ請求
*/
public function GetLmCartType()
{
return $this->LmHelper->getCartType();
}
/**
* 初回ログイン
*
*/
public function GetFirstLogin()
{
$Flg = $this->CustomerService->GetFirstLoginFlg();
$this->CustomerService->SetFirstLoginFlg(null);
return $Flg;
}
public function GetLmCuatomer($Eail)
{
if (!$Lmcustomer = $this->CustomerService->GetLandMarkCustomerEmail($Eail)) {
$Columns = $this->CommonService->GetYaml('LmCustomer.yaml');
foreach ($Columns as $Column) {
switch ($Column) {
case 'address03':
$Lmcustomer['customer_address3'] = '';
break;
case 'fax_number':
$Lmcustomer['customer_fax'] = '';
break;
default:
$Lmcustomer[$Column] = '';
break;
}
}
};
return $Lmcustomer;
}
/**
* アマゾンログイン
*
*/
public function GetAmazonLogin()
{
return $this->CustomerService->GetAmazonLoginFlg();
}
/**
* LMプライバシーポリシーの取得
*
* @return string admin_privacy3
*/
public function GetPrivacy3()
{
$Sql = new SqlService;
$Data = $Sql->Table('admin_table')
->Find();
return $Data['admin_privacy3'] ?? '';
}
/**
* オリジナルトークンを返す
* @param string $Cd
* @param string $name 'token'
*
* @return string $Token
*/
public function GetOlToken($Cd, $Name = 'token')
{
return $this->CommonService->ResetToken($Cd, $Name);
}
/**
* クーポンの値引き時 リダイレクト先URIを返す
*
*/
public function GetRequestUri()
{
return $this->Request->server->get('REQUEST_URI');
}
/**
* クーポンのData
*
*/
public function GetCouponData()
{
return $this->CommonService->GetLmOrderOption(CommonService::Lm_Option_Coupon);
}
/**
* 領収書
*
*/
public function SetReceipt($CompanyName, $Name, $Write)
{
$Receipt = $this->CommonService->GetLmOrderOption(CommonService::Lm_Option_Receipt);
$Re = $Receipt;
$Re['flg'] = ['', ''];
if (!$Receipt) {
$Re['name'] = $CompanyName ? $CompanyName : $Name;
$Re['flg'][0] = 'checked="checked"';
$Re['write'] = $Write;
$Re['comment'] = '';
} else {
$Re['flg'][$Receipt['flg']] = 'checked="checked"';
}
return $Re;
}
public function GetReceipt()
{
if (!$Receipt = $this->CommonService->GetLmOrderOption(CommonService::Lm_Option_Receipt)) {
return false;
}
return $Receipt['flg'] == 0 ? false : $Receipt;
}
public function GetLmOptionName($Name = null)
{
switch ($Name) {
case 'catalog':
$Re = CommonService::Lm_Option_Catalog;
break;
case 'receipt';
default:
$Re = CommonService::Lm_Option_Receipt;
break;
}
return $Re;
}
/**
* LMOrderPption 初期化
*
*/
public function SetInitiarizeLmOrederOption($OrderId)
{
$this->CommonService->SetInitiarizeLmOrederOption($OrderId);
}
public function SetShoppingTitle($Message, $Num)
{
$Message = trans($Message);
if (is_null($Num)) {
return $Message;
}
return $this->LmHelper->getCartType() <= CartService::CartTypeEstimate ? $Num . '.' . $Message : $Message;
}
/**
* 確認気年のボタン
*
* @return string
*/
public function ShoppingConfirmBtn()
{
$Message = 'front.shopping.checkout';
switch ($this->LmHelper->getCartType()) {
case CartService::CartTypeCatalog:
$Message = 'front.Shopping_Button04';
break;
case CartService::CartTypeNormal:
default:
break;
}
return $Message;
}
public function GetCatalogChecked($Id, $Name = null)
{
$Checked = ['', 'checked="checked"'];
if ('Open' == $Name) {
$OpenCtalog = $this->CommonService->GetLmOrderOption('OpenCatalog');
if (is_null($OpenCtalog) && $Id == 0) {
return $Checked[1];
}
return $Id == $OpenCtalog ? $Checked[1] : $Checked[0];
}
if (!$this->CatalogValue) {
if ($Value = $this->CommonService->GetLmOrderOption(CommonService::Lm_Option_Catalog)) {
$this->CatalogValue = array_flip($Value);
}
}
if (isset($this->CatalogValue[$Id])) {
return $Checked[1];
}
return $Checked[0];
}
public function GetLmOrderOption($name)
{
return $this->CommonService->GetLmOrderOption($name);
}
/**
* LMOrderPption クーポン
* ショッピング 表示
*
* @return string $name
*/
public function SetDiscountName()
{
return $this->CommonService->GetLmOrderOption(CommonService::Lm_Option_Coupon) ? 'クーポン' : trans('common.discount');
}
/**
* カタログの札数メッセージ
*
* @param int num
*
* @return string メッセージ
*/
public function CatalogLimitMessage($Num)
{
return str_replace('@@', $Num, trans('front.cart_catalog.message09'));
}
public function CatalogValidation()
{
if (CartService::CartTypeCatalog != $this->CartService->getCartType()) {
return false;
}
return $this->CatalogService->CatalogValidation();
}
public function GetCatalogViews()
{
return $this->CatalogService->GetView();
}
/**
* カートにて サムネイルのURLを生成する
*
*/
public function GetCartSumImage($ProductId)
{
$Dir = substr($ProductId, -1);
return "/goods.img/{$Dir}/{$ProductId}/main_sum.jpg";
}
/**
* カートにて サムネイルのURLを生成する
*
*/
public function GetGoodsMainImage($ProductId)
{
$Dir = substr($ProductId, -1);
return "/goods.img/{$Dir}/{$ProductId}/main.jpg";
}
/**
* LMの価格に対して 税込価格を返す
*
*/
public function GetLmTax($ProductClassId)
{
$ProductClass = $this->ProductClassRepository->find($ProductClassId);
return $ProductClass->getPrice02IncTax();
}
/**
* LM在庫数を返す
*
* 0 ・・・ 在庫なし
* 1以上 ・・・ 在庫あり
* # null ・・・ 99(入荷予定)
* # * ・・・ 999
*`@param int ClassId
*
* @return string 在庫数
*/
public function GetCartItmeStock($ProductClass)
{
$ClassId = $ProductClass->getId();
$Stock = $this->GoodsService->getValidationStock($ClassId);
$Re = '';
switch (true) {
case is_null($Stock):
$Re = trans('front.cart_item.title10');
break;
case $Stock == 0:
$Re = trans('front.cart_item.title11');;
break;
default:
$Text = $this->CommonService->GetConfig('ESTIMATE_TEXT');
$Re = $Text['Text23'] . number_format($Stock) . $Text['Text04'];
break;
}
return $Re;
}
public function GetCartItemSameDayShippingFlg($ProductClass, $quantity = null)
{
$result = $this->GoodsService->getGoodsSameDayShipping($ProductClass->getProduct()->getId(), 0, $ProductClass->getId(), null, null, $quantity);
return $result;
}
public function GetCartItemStockNumber($productClass, $sameShippingFlg)
{
$stock = $this->GoodsService->getGoodsStock(null, false, $productClass->getId());
if ($sameShippingFlg > SokujitsuHassou::FLG_NONE) {
return $stock['stock_sokujitsu'];
} else {
return $stock['stock_total'];
}
}
public function GetCartNextBtnText()
{
switch ($this->GetLmCartType()) {
case CartService::CartTypeSample:
return 'サンプル申込の手続きへ';
case CartService::CartTypeNormal:
case CartService::CartTypeEstimate:
default:
return '次へ(レジへ進む)';
}
}
public function GetCartBackBtnText()
{
switch ($this->GetLmCartType()) {
case CartService::CartTypeSample:
return '他にもサンプル申込商品を選ぶ';
case CartService::CartTypeNormal:
case CartService::CartTypeEstimate:
default:
return '買い物を続ける';
}
}
public function GetShoppingNextBtnText()
{
switch ($this->GetLmCartType()) {
case CartService::CartTypeSample:
return '同意して次へ';
case CartService::CartTypeCatalog:
return '送信する';
case CartService::CartTypeNormal:
case CartService::CartTypeEstimate:
default:
return '確認画面に進む';
}
}
public function GetShoppingBackBtnText()
{
switch ($this->GetLmCartType()) {
case CartService::CartTypeCatalog:
return '入力画面に戻る';
case CartService::CartTypeNormal:
case CartService::CartTypeEstimate:
case CartService::CartTypeSample:
default:
return 'カートに戻る';
}
}
public function GetConfig($key)
{
return $this->LmHelper->getConfig($key);
}
public function getColorRGBCode($productId)
{
$colors = [];
$goodColors = $this->GoodsService->getGoodsColorSelectSql($productId);
if (is_array($goodColors) && count($goodColors) > 0) {
foreach ($goodColors as $goodColor) {
if (!$goodColor['color_name']) {
continue;
}
$id = $this->LmHelper->convGclIdToClassCategory1Id($goodColor['gcl_id']);
$colors[$id] = $goodColor['color_rgb'];
}
}
return $colors;
}
public function GetCartItemColorPullDown($ItemId, $ProductId, $classCategory1Id, $EstimateId, $EmptyOptionAsFirst = false)
{
//
$Type = 'color';
//
$Data = [];
$Value = null;
$Id = 0;
//
$kbn = 1;
if ($classCategory1Id) {
$ClassCategory1 = $this->ClassCategoryRepository->find($classCategory1Id);
$Value = $ClassCategory1->getId();
$ClassName = $ClassCategory1->getClassName();
$kbn = $ClassName->getId();
}
foreach ($this->GoodsService->getGoodsColorSelectSql($ProductId) as $Val) {
if (!$Val['color_name']) {
continue;
}
$Id = $this->LmHelper->convGclIdToClassCategory1Id($Val['gcl_id']);
$Selected = !$EmptyOptionAsFirst && $Value == $Id ? 'selected="selected"' : '';
$Rgb = 'data-rgb=#' . $Val['color_rgb'];
$Data[$Id] = [
'name' => $Val['color_name'],
'Selected' => $Selected,
'disabled' => '',
'Data' => $Rgb
];
};
//
return $this->GetCartItemPullDown($ItemId, $ProductId, $Type, $Data, $Value, $EstimateId, $EmptyOptionAsFirst);
}
public function GetCartItemSizePullDown($ItemId, $ProductId, $classCategory2Id, $classCategory1Id, $EstimateId, $EmptyOptionAsFirst = false)
{
//
$Type = 'size';
//
$Data = [];
$Value = null;
$Id = 0;
//
$kbn = 2;
if ($classCategory2Id) {
$ClassCategory2 = $this->ClassCategoryRepository->find($classCategory2Id);
$Value = $ClassCategory2->getId();
$ClassName = $ClassCategory2->getClassName();
$kbn = $ClassName->getId();
}
if ($classCategory1Id) {
//
$ClassCategory1 = $this->ClassCategoryRepository->find($classCategory1Id);
$sizeList = $this->GoodsService->getGoodsSizeListWithStockInfoByClassCategory1($ClassCategory1);
} else {
$sizeList = $this->GoodsService->getGoodsSizeListById($ProductId);
}
foreach ($sizeList as $Val) {
if (!$Val['size_name']) {
continue;
}
$Id = $this->LmHelper->convGpIdToClassCategory2Id($Val['gp_id']);
$Selected = !$EmptyOptionAsFirst && $Value == $Id ? 'selected="selected"' : '';
$disabled = (isset($Val['disabled']) && $Val['disabled'] === 1) ? 'disabled' : '';
$Data[$Id] = [
'name' => $Val['size_name'],
'Selected' => $Selected,
'disabled' => $disabled,
'Data' => ''
];
};
//
return $this->GetCartItemPullDown($ItemId, $ProductId, $Type, $Data, $Value, $EstimateId, $EmptyOptionAsFirst);
}
public function GetCartItemPullDown($ItemId, $ProductId, $Type, $ItemDatas, $Value, $EstimateId, $EmptyOptionAsFirst = false)
{
//
$Re = [
'ItemId' => $ItemId,
'ProductId' => $ProductId,
'Type' => $Type,
'ItemDatas' => $ItemDatas,
'Value' => $Value,
'EstimateId' => $EstimateId,
'EmptyOptionAsFirst' => $EmptyOptionAsFirst
];
//
return $this->Twig->render('Cart/Parts/PullDown.twig', $Re);
}
public function getStockLabel($ProductId, $ClassCategory1Id, $ClassCategory2Id)
{
//
$context = [
'ProductClass' => $this->ProductClassRepository->findOneBy([
'Product' => $ProductId,
'ClassCategory1' => $ClassCategory1Id,
'ClassCategory2' => $ClassCategory2Id,
]),
];
//
return $this->Twig->render('Cart/Parts/StockLabel.twig', $context);
}
public function GetBank($Name, $Bancode = '')
{
if (!$this->Bank) {
$Banks = $this->CommonService->GetYaml('Bank.yaml');
if ($Bancode) {
$this->Bank = $Banks[1];
$this->Bank['account'] = $Bancode;
} else {
$this->Bank = $Banks[0];
}
}
return $this->Bank[$Name];
}
/**
* ハイブリッドボタンの設置
* 1 サンプルは出力しない
* 2 加工できない商品は出力しない
* 3 分割対応 2022/10/20
*/
public function SetCartHybridBtn($ProductId, $EstimateId, $ItemId, $btnName = null)
{
#1
if ($this->CartService->getCartType() >= CartService::CartTypeSample) {
return;
}
#2
if (!$Type = GoodsService::getEnableEstimateTypeById($ProductId)) {
return;
}
#3
if (CartService::CartTypeEstimate == $this->CartService->GetCartType() &&
$this->CommonService->GetConfig('BunkaruFlg') == false) {
$this->EstimateType = $this->EstimateType ?? $this->CartService->GetEstimateType();
}
if (is_numeric($ItemId)) {
$Itemids = $ItemId;
} else {
$Ids = [];
foreach ($ItemId as $Item) {
if ($Item->getEstimateId() != $EstimateId) {
continue;
}
$productItemId = $Item->getProductClass()->getProduct()->getId();
if (!GoodsService::getEnableEstimateTypeById($productItemId)) {
continue;
}
$Ids[] = $Item->getId();
}
$Itemids = implode(',', $Ids);
}
$Re = [
'ItemIds' => $Itemids,
'Name' => $btnName ?? trans('front.cart_item_button04_' . $Type),
'EstimateId' => $EstimateId,
'Type' => $ProductId,
];
return $this->Twig->render('Cart/Parts/CartHybridBtn.twig', $Re);
}
/**
* @param CartItem $CartItem
* @return string
*/
public function ShowCartHybridBtnByCartItem(CartItem $CartItem)
{
//
$ProductId = $CartItem->getProductClass()->getProduct()->getId();
$EstimateId = $CartItem->getEstimateId();
// TODO: 旧・セット品番への対応
// // $ItemId = array_filter(is_array($CartItems = $CartItem->getCart()->getCartItems()) ? $CartItems : $CartItems->toArray(), function ($CartItem) {
// // /**
// // * @var CartItem $CartItem
// // */
// // return !$this->CartService->isProductNoOptions($CartItem->getProductClass()->getProduct()->getId());
// // });
$ItemId = $CartItem->getCart()->getCartItems();
$btnName = $CartItem->isSusoage() ? '裾上げ内容の変更' : '加工内容の変更';
//
return $this->SetCartHybridBtn($ProductId, $EstimateId, $ItemId, $btnName);
}
public function SetShowOrderItem($Order, $Type)
{
$Item = null;
foreach ($Order->getOrderItems() as $OrderItem) {
$OrderItemType = $OrderItem->getOrderItemType();
if ($Type == $OrderItemType->getId()) {
$Item = $OrderItem;
}
};
if (!$Item) {
return '';
}
$Re = [
'Item' => $Item,
'Type' => $Item->getOrderItemType(),
];
return $this->Twig->render('Shopping/Parts/OrderItem.twig', $Re);
}
/**
* カート排他制御
*
*/
public function SetExclusionControl()
{
$Type = '';
if (!$Type = $this->Session->get(CartService::Session_ExclusionControlFlg)) {
return;
};
#2022/10/22 リピート注文特殊処理 Cartエラーで返せない
switch ($Type) {
case CartService::RepeatError01:
$Messages[] = trans('front.Cart.Repeat_message01');
break;
case CartService::RepeatError02:
$Messages[] = trans('front.ExclusionControl.message04');
break;
case CartService::RepeatError03:
$Messages[] = trans('front.ExclusionControl.message05');
break;
default:
for ($i = 1; $i <= 2; $i++) {
$Messages[] = $this->CommonService->SetExclusionControl($Type, $i);
}
break;
}
$this->Session->set(CartService::Session_ExclusionControlFlg, null);
return $this->Twig->render(self::ExclusionTwig,
[
'Messages' => $Messages,
]);
}
public function SetMetaTags($Datas)
{
$Key = array_key_first($Datas);
$Data = $Datas[$Key] ?? null;
switch (true) {
case $Key === 'item':
$this->MetaTagService->SetItem($Datas[$Key]);
$Image = $this->LmHelper->getGoodsImageUrl($Data['goods_id'], 'main.jpg');
$this->MetaTagService->SetOpgs(4, $Image);
break;
case $Key === 'SubCategory':
case $Key === 'Category':
$this->MetaTagService->SetCategory($Datas[$Key]);
$this->MetaTagService->SetOpgs();
break;
case $Key === 'message':
$this->MetaTagService->SetMessage($Datas[$Key]);
$this->MetaTagService->SetOpgs();
break;
case $Key === 'review':
$this->MetaTagService->SetReview($Datas[$Key]);
$this->MetaTagService->SetOpgs(4);
break;
case $Key === 0:
$this->MetaTagService->SetMetaTags($Data); //
break;
default:
$this->MetaTagService->SetMetaPages(); //
break;
}
return $this->Twig->render(self::MetatagTwig, [
'Title' => $this->MetaTagService->GetTitle(),
'MetaTags' => $this->MetaTagService->GetMetaTags(),
'Opgs' => $this->MetaTagService->GetOpgs(),
'UrlName' => $this->Request->get('_route'),
]);
}
public function SetHeaderH1()
{
return $this->MetaTagService->GetHeaderH1();
}
/**
* パンクズを一括管理する
* @param $BreadCrumbs string | array none 非表示
* 1 第一因子を TOPページとする 固定
* 2 BreadCrumbsのKEYを1にすると 最後に ページ名を追加します
* 3 配列の内容は、KEYが href' 'label' になります
*/
public function SetBreadCrumb($BreadCrumbs)
{
$Type = $BreadCrumbs[0] ?? null;
if (!is_array($Type) && $Type == 'none') {
return;
}
$this->getBreadCrumb('homepage');
$Re[] = $this->getBreadCrumb('homepage');
#第一因子 (0)
$UrlName = $this->Request->get('_route');
if (count($BreadCrumbs) > 0) {
foreach ($BreadCrumbs as $Key => $BreadCrumb) {
$BC['label'] = $BreadCrumb['label'] ?? '';
$BC['href'] = $BreadCrumb['href'] ?? '';
switch (array_key_first($BreadCrumbs)) {
case 1:
$Re[] = $BC;
$Re[] = $this->getBreadCrumb($UrlName);
break;
default:
$Re[] = $BC;
}
}
} else {
$Re[] = $this->getBreadCrumb($UrlName);
}
return $this->Twig->render(self::BreadCrumTwig, [
'BreadCrumbs' => $Re,
]);
}
protected function getBreadCrumb($UrlName)
{
$Name = $this->CommonService->GetPagename($UrlName);
switch ($UrlName) {
case 'cart':
if ($this->LmHelper->getCartType() == 4) {
$MetaTags = $this->CommonService->GetYaml(CommonService::MetaTagData);
$Name = $MetaTags['catalog']['PageName'];
}
break;
case 'shopping_login':
$Name = "ログイン";
break;
default:
break;
}
try {
return [
'href' => $this->Router->generate($UrlName) ?? '',
'label' => $this->LmHelper->display_text($Name)
];
} catch (\Exception $e) {
return $this->getBreadCrumb('homepage');
}
}
public function getCurrentBreadcrumb()
{
$Re[] = $this->getBreadCrumb('homepage');
$UrlName = $this->Request->get('_route');
$Re[] = $this->getBreadCrumb($UrlName);
return $Re;
}
/**
* 見積もりシミュレーション文字化
*
*/
public function SetEstimateCharaCart($CartKey, $EstimateId, $Options, $isDisplayOnSp = false)
{
if (!$Option = $Options[$CartKey][$EstimateId] ?? null) {
return;
}
if ($isDisplayOnSp) {
return $this->Twig->render('Common/EstimateMobile.twig', [
'Prints' => $Option['print'] ?? [],
'Susoage' => $Option['susoage'] ?? '',
'Lot' => $Option['lot'] ?? null,
]);
}
return $this->Twig->render(self::EstimateTwig, [
'Prints' => $Option['print'] ?? [],
'Susoage' => $Option['susoage'] ?? '',
'Lot' => $Option['lot'] ?? null,
]);
}
public function GetItemType($Id, $Flg = null)
{
$ItemType = $this->OrderItemTypeRepository->find($Id);
return $ItemType->getName();
}
public function GetPaymentDetails($Param, $Items)
{
foreach ($Items as $Item) {
$Type = $Item->getOrderItemTypeId();
if ($Type == $Param) {
return $Item->getPrice();
}
}
return null;
}
/**
* @param OrderItem[] $Items
* @return void
*/
public function SetEstimateOptions($Items)
{
$this->EstimateOptions = [];
$EstimetIds = [];
$Options = [];
$I = null;
$Num = 1;
$ItemCount = 0;
foreach ($Items as $Item) {
$ProductClass = $Item->getProductClass();
$Product = $ProductClass->getProduct();
$EstimetIds[$Product->getId()][$Item->getEstimateId()] = $Item->getId();
$Options[$Item->getId()] = $Item->getOptions();
$L = $Product->getId() . '-' . $Item->getEstimateId();
if ($I != $L) {
$this->CartSortFlg[$Product->getId()][$Item->getEstimateId()]['h'] = $Item->getId();
$this->CartSortFlg[$Product->getId()][$Item->getEstimateId()]['n'] = $Num;
$Num++;
$ItemCount = 0;
}
$I = $L;
$ItemCount++;
$this->CartSortFlg[$Product->getId()][$Item->getEstimateId()]['f'] = $Item->getId();
$this->CartSortFlg[$Product->getId()][$Item->getEstimateId()]['ItemCount'] = $ItemCount;
}
foreach ($EstimetIds as $ProductId) {
foreach ($ProductId as $Id) {
$this->EstimateOptions[$Id] = $Options[$Id];
}
}
}
public function GetEstimateOption($Id, $Page = 'Shopping')
{
if (!$Options = $this->EstimateOptions[$Id] ?? null) {
return;
}
$this->EstimateCharacterizer->EstimateCharacterIzation($Options, [], $Page);
$EstimateOption = $this->EstimateCharacterizer->GetCharacters();
return [
'print' => $EstimateOption['print'] ?? [],
'susoage' => $EstimateOption['susoage'] ?? '',
'lot' => $EstimateOption['lot'] ?? null,
];
}
public function ShowEstimateOptions($Id)
{
if (!$OpipnData = $this->EstimateOptions[$Id] ?? null) {
return;
}
$this->EstimateCharacterizer->EstimateCharacterIzation($OpipnData, [], 'Shopping');
$Option = $this->EstimateCharacterizer->GetCharacters();
return $this->Twig->render(self::ShoppingEstimate, [
'Prints' => $Option['print'] ?? [],
'Susoage' => $Option['susoage'] ?? '',
'Lot' => $Option['lot'] ?? null,
]);
}
public function ShowEstimateMobileOptions($item)
{
if (!$optionData = $this->EstimateOptions[$item->getId()] ?? null) {
return;
}
$this->EstimateCharacterizer->EstimateCharacterIzation($optionData, [], 'Shopping');
$Option = $this->EstimateCharacterizer->GetCharacters();
return $this->Twig->render(self::MobileShoppingEstimate, [
'orderItem' => $item,
'Prints' => $Option['print'] ?? [],
'Susoage' => $Option['susoage'] ?? '',
'Lot' => $Option['lot'] ?? null,
'ProductClass' => $item->getProductClass(),
]);
}
public function ShowEstimateOptionsMail($Id, $SubTotal)
{
if (!isset($this->EstimateOptions[$Id])) {
return;
}
if (!$OptionData = $this->EstimateOptions[$Id]) {
'注文別合計:' . number_format($SubTotal) . '円';
}
$this->EstimateCharacterizer->EstimateCharacterIzation($OptionData, [], 'Shopping');
$Option = $this->EstimateCharacterizer->GetCharacters();
return $this->Twig->render(self::MailEstimate, [
'Prints' => $Option['print'] ?? [],
'Susoage' => $Option['susoage'] ?? '',
'Lot' => $Option['lot'] ?? null,
'kakouhi' => $Option['total'] ?? 0,
'OptionSubTotal' => ($Option['total'] ?? 0) + ($Option['lot']['total'] ?? 0) + ($Option['product_total'] ?? 0),
]);
}
public function GetCartSortFlg($Item, $Flg = 'h')
{
$ProductClass = $Item->getProductClass();
$Product = $ProductClass->getProduct();
$ProductId = $Product->getId();
$EstimateId = $Item->getEstimateId();
$ItemId = $Item->getId();
switch ($Flg) {
case 'f' :
return $this->CartSortFlg[$ProductId][$EstimateId][$Flg] == $ItemId ? true : false;
break;
case 'n':
return $this->CartSortFlg[$ProductId][$EstimateId][$Flg];
break;
case 'ItemCount':
return $this->CartSortFlg[$ProductId][$EstimateId][$Flg];
case 'h':
default:
return $this->CartSortFlg[$ProductId][$EstimateId][$Flg] == $ItemId ? true : false;
break;
}
}
public function GetZeusCardDatas($Name, $Order)
{
$Value = '';
switch ($Name) {
case 'money':
$Value = $this->OrderService->calculateCreditTotal($Order);
break;
case 'sendid':
$Customer = $Order->getCustomer();
$LmCustomer = $this->CustomerService->GetLandMarkCustomerId($Customer->getLmCustomerId(), true);
$Value = $LmCustomer['customer_bangou'];
break;
case 'sendpoint':
$Value = $Order->getZeusRequestData();
break;
case 'telno':
$Value = $Order->getPhoneNumber();
break;
case 'email':
$Value = $Order->getEmail();
break;
}
return $Value;
}
/**
* ZeusCardError
* カードエラーの場合表示する
*
*/
public function GetZeusCardError()
{
$CardError = false;
if ($OrderId = $this->Session->get(OrderHelper::SESSION_ORDER_ID)) {
$Order = $this->OrderRepository->find($OrderId);
$Paymenr = $Order->getPayment();
if ($this->CommonService->GetConfig('ZEUS_CARD_PAYMAET_ID') == $Paymenr->getId()) {
$CardError = $Order->getLmOrderId();
}
$this->Session->get(OrderHelper::SESSION_ORDER_ID, null);
}
return $CardError;
}
public function GetEstimateType()
{
if ($this->CommonService->getConfig('BunkaruFlg')) {
return 0;
}
switch ($this->CartService->GetCartType()) {
case CartService::CartTypeEstimate:
return $this->CartService->getEstimateType();
break;
case CartService::CartTypeNormal:
default:
return 0;
break;
}
}
public function GetCartAddLine($CartItem)
{
$Item = $this->GetCartItemData($CartItem);
$lineItemId = $Item['EstimateId'] . '-' . $Item['ProductId'];
return $this->Twig->render(self::CartAddLineTwig, [
'num' => $this->GetCartSortFlg($CartItem, 'n'),
'ItemId' => $CartItem->getId(),
'ProductId' => $Item['ProductId'],
'ProductClass' => $Item['ProductClass'],
'ClassCategory1Id' => $Item['ClassCategory1Id'],
'ClassCategory2Id' => $Item['ClassCategory2Id'],
'EstimateId' => $Item['EstimateId'],
'lineItemId' => $lineItemId,
]);
}
protected function GetCartItemData($CartItem)
{
$ProductClass = $CartItem->getProductClass();
$Product = $ProductClass->getProduct();
$ClassCategory1 = is_null($ProductClass) ? null : $ProductClass->getClassCategory1();
$ClassCategory1Id = is_null($ClassCategory1) ? null : $ClassCategory1->getId();
$ClassCategory2 = is_null($ProductClass) ? null : $ProductClass->getClassCategory2();
$ClassCategory2Id = is_null($ClassCategory2) ? null : $ClassCategory2->getId();
return [
'ProductClass' => $ProductClass,
'Product' => $Product,
'ProductId' => $Product->getId(),
'ClassCategory1Id' => $ClassCategory1Id,
'ClassCategory2Id' => $ClassCategory2Id,
'EstimateId' => $CartItem->getEstimateId(),
];
}
public function GetCartBackBtn()
{
return $this->LmHelper->getBackUrl();
}
/********************************************************************************************************************* */
/**
* メッセージのbaseinfo config Messegeを 変換する
* 例
* {{BaseInfo.shop_name}}
* {{Config.Payment_Charge_free}}
* {{message.common.ResetPassward_messeg02}} or {{trans.common.ResetPassward_messeg02}}
*/
public function BaseInfo($Text)
{
// return $Text;
return $this->CommonService->BaseInfo($Text);
}
/**
* LMのプライス出力フォーマット
* @param int $Price
* @param string|false $yen
*/
public function GetLmPrice($Price, $yen = '円')
{
if (!is_numeric($Price)) {
return $Price;
}
if ($yen === false) {
$yen = '';
}
return number_format($Price) . $yen;
}
public function FormatPrice($Price)
{
if (!is_numeric($Price)) {
return $Price;
}
return number_format($Price) . '<span class="prices-unit">円</span>';
}
/**
* LMのプライス出力フォーマット
*
*/
public function SetPhone($Phone)
{
return $this->CommonService->GetPhoneNumber($Phone, false);
}
public function SetPost($Post)
{
$Post = str_replace('-', '', $Post);
if (strlen($Post) < 7) {
return $Post;
}
return substr($Post, 0, 3) . '-' . substr($Post, 3, 4);
}
public function SetJWeek($Da)
{
return \Lm\Util\Date::weekDay($Da, \Lm\Util\Date::COUNTRY_JP);
}
public function GetLmCssList()
{
//
$context = [];
//
$cssConfig = $this->CommonService->GetConfig('Css');
$cssRoot = $cssConfig['Root'];
$cssIndex = $cssConfig['CssList'];
$cssList = [];
//
$deviceType = strtolower($this->CommonService->GetDevice(false, $this->LmMobileDetector));
//
$pageTypeConfig = $this->LmHelper->getPageType();
$pageType = $pageTypeConfig['type'];
//
$cssList = array_merge($cssList, $cssIndex[$deviceType]['common']);
$cssList = array_merge($cssList, $cssIndex[$deviceType][$pageType]);
//
foreach ($cssList as $css) {
$context['CssList'][] = [
'href' => "{$cssRoot}/{$deviceType}/{$css}",
];
}
//
return $this->Twig->render('Common/CssList.twig', $context);
}
public function isSliderEnabled()
{
return $this->LmHelper->filterSliderEnabled();
}
public function GetCustomerBangou($lmCustomerId)
{
//
$result = (new SqlService())
->Select('customer_bangou')
->Table('customer_table')
->Set('customer_id', $lmCustomerId)
->Find();
//
$customerBangou = $result['customer_bangou'];
//
return $customerBangou;
}
public function getCatalogNoukiSchedule()
{
//
return (new NoukiEngine())
->getCatalogSendDate();
}
public function getPageType()
{
return $this->LmHelper->getPageType();
}
/**
* @param bool|false $strict
* @return bool
*/
public function isMobile($strict = false)
{
if ($strict) {
return $this->mobileDetector->isMobile();
} else {
return $this->LmMobileDetector->isMobile();
}
}
/**
* @return bool
*/
public function wannaSeePc()
{
return !$this->isMobile() && $this->isMobile(true);
}
/**
* @param array $paramsAdd
* @param array $params
* @return string
*/
public function WithGetParams($paramsAdd, $params = [])
{
if (is_array($params) && count($params) === 0) {
$params = $this->Request->query->all();
}
$params = array_merge($params, $paramsAdd);
$result = http_build_query($params);
return $result;
}
/**
* @param int $page
* @return string
*/
public function PageWithGetParams($page)
{
return $this->WithGetParams([
'page' => $page,
]);
}
/**
* @param OrderHeader|array|int $order
* @return string|null
* @throws \Exception
*/
public function showSendScheduleDate($order)
{
try {
/**
* @var OrderHeader $orderHeader
*/
if ($orderHeader = OrderHeader::factory($order)) {
//
return NoukiEngine::showSendScheduleByOrder($orderHeader);
} else {
//
return null;
}
} catch (\Exception $e) {
//
if (is_string($order)) {
//
if (Date::validate($order, 'Y/m/d')) {
//
return NoukiEngine::showSendSchedule($order);
} else {
//
return $order;
}
} else {
//
throw new \Exception('お届け予定日の計算処理に失敗しました', 0, $e);
}
}
}
/**
* @param OrderHeader|array|int $order
* @return string
* @throws \Exception
*/
public function showSendScheduleMessage($order)
{
//
$orderHeader = OrderHeader::factory($order);
//
return $this->Twig->render('Common/SendScheduleDate.twig', [
'orderHeader' => $orderHeader,
'isMobile' => $this->isMobile(),
'sendSchedule' => $this->showSendScheduleDate($order),
'paymentAtobarai' => [OrderHeader::PAYMENT_TYPE_ATOBARAI, OrderHeader::PAYMENT_TYPE_ATOBARAI_MONTHLY],
]);
}
public function getOrderPaymentId($Order)
{
return !empty($Order->getPayment()) ? $Order->getPayment()->getId() : null;
}
public function getCategoryImageUrlById($categoryId)
{
return "/category_images/{$categoryId}.webp";
}
public function showFileSizeUpload($name = 'default')
{
//
$config = $this->CommonService->GetConfig('FILE_UPLOAD');
//
if (!isset($config[$name])) {
//
throw new \Exception('Config name specified is invalid.');
}
//
$FileUploadConfig = $config[$name];
//
return $this->Twig->render('Common/FileUploadNotice.twig', [
'FileUploadConfig' => $FileUploadConfig,
]);
}
public function showInventoryMatrix(GoodsWithRelated $goods)
{
//
$id = $goods->getGoodsId();
$data = $this->GoodsService->getGoodsById($id);
$Product = $this->ProductRepository->find($id);
// $matrixData = $this->inventoryMatrixService->getInventoryMatrixData($goods, $color, $size);
$inventoryMatrix = (new InventoryMatrix())
->getMatrixStock($goods, false, $color, $size)
;
$colorCnt = count($color);
$sizeCnt = count($size);
$SellingColor = $this->GoodsService->getSellingColorSql($id, count($color));
$isShowMatrixButtonAbove = (($colorCnt * (intval(($sizeCnt - 1) / 6) + 1)) >= 10);
//
return $this->Twig->render('Item/matrix.twig', [
'isShowMatrixButtonAbove' => $isShowMatrixButtonAbove,
'data' => $data,
'goods' => $goods,
// 'matrixData' => $matrixData,
'Product' => $Product,
'SellingColor' => $SellingColor,
'inventoryMatrix' => $inventoryMatrix,
]);
}
/**
* Handle format Object or array to json
*
* @param $data
* @return string|null
*/
public function formatDataToJson($data)
{
if (empty($data)) {
return null;
}
return json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
public function getCartSessionName($key)
{
switch ($key) {
case 'GROUP_1_NORMAL':
return '通常注文';
case 'GROUP_2_RESERVATION':
return '予約注文';
case 'GROUP_3_KYOUEI':
return 'メーカー「共栄-KYOEI」';
default:
return '商品一覧';
}
}
public function groupItemsHasSameProductId($items)
{
$result = [];
foreach ($items as $item) {
$productId = $item->getProduct()->getId();
if (!isset($result[$productId])) {
$result[$productId] = [];
}
$result[$productId][] = $item;
}
return $result;
}
/**
* Get format date. Example: 2023/09/15 -> 2023年9月15日(金)
*
* @param string $date
* @return string
*/
public function formatDate(string $date, bool $showDay = true)
{
if (!empty($date) && strtotime($date) !== false) {
$weekdays = [
1 => '月',
2 => '火',
3 => '水',
4 => '木',
5 => '金',
6 => '土',
7 => '日'
];
$dateString = date('Y年n月j日', strtotime($date));
if ($showDay == false) {
return $dateString;
}
$dayOfWeek = date('N', strtotime($date));
$day = $weekdays[$dayOfWeek];
return $dateString . '(' . $day . ')';
}
return $date;
}
public function formatMonthAndDay(string $date, bool $showDay = true, $format = "n/j")
{
if (!empty($date) && strtotime($date) !== false) {
$weekdays = [
1 => '月',
2 => '火',
3 => '水',
4 => '木',
5 => '金',
6 => '土',
7 => '日'
];
$dateString = date($format, strtotime($date));
if ($showDay == false) {
return $dateString;
}
$dayOfWeek = date('N', strtotime($date));
$day = $weekdays[$dayOfWeek];
return $dateString . '(' . $day . ')' . ' 頃';
}
return $date;
}
public function getDayOfWeek(string $date)
{
if (!empty($date) && strtotime($date) !== false) {
$weekdays = [
1 => '月',
2 => '火',
3 => '水',
4 => '木',
5 => '金',
6 => '土',
7 => '日'
];
$dayOfWeek = date('N', strtotime($date));
return $weekdays[$dayOfWeek];
}
return null;
}
/**
* @param int $goodsId
* @param int $janId
* @return string
*/
public function showYoyakuFlag($goodsId, $janId)
{
//
return Yoyaku::check($goodsId, false, $janId) ? '(予約)' : null;
}
/**
* @param Item|Goods|int
* @return string
*/
public function filterLmWebTeika($item) {
/**
* @var Item $Item
*/
$item = Item::factory($item);
//
return $this->Twig->render('Common/LmWebPrice.twig', [
'minPrice' => $item->getMinTeika(),
'maxPrice' => $item->getMaxTeika(),
]);
}
/**
* @param Item|Goods|int
* @return string
*/
public function filterLmWebPrice($item) {
/**
* @var Item $Item
*/
$item = Item::factory($item);
//
return $this->Twig->render('Common/LmWebPrice.twig', [
'minPrice' => $item->getMinPrice(),
'maxPrice' => $item->getMaxPrice(),
]);
}
/**
* @param Goods $goods
* @return string
*/
public function showSokujitsuHassouBannerIfSo(Goods $goods)
{
/**
* @var GoodsWithRelated $goods
*/
$goods = GoodsWithRelated::factory($goods);
//
return $this->Twig->render('Common/SokujitsuHassouBanner.twig', [
'goods' => $goods,
]);
}
}