<?php
namespace Customize\Service;
use Customize\Converter\EstimateConverter;
use Eccube\Entity\Order;
use Eccube\Repository\PaymentRepository;
use Customize\Service\CartService;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Eccube\Repository\DeliveryRepository;
use Eccube\Repository\DeliveryFeeRepository;
class EstimateCharacterizer
{
const DeliveryId = 1; #佐川 加工
const EstimateType = [1 => 'print', 2 => 'susoage', 9 => 'charge', 10 => 'gross'];
const OptionTotalColumn = ['product_total', 'quantity', 'white_only'];
const ICHI_OTHER = [
'ichi_id' => 0,
'ichi_name' => 'その他',
'ichi_display' => null,
];
/**
* @var CommonService
*/
protected $CommonService;
/**
* @var EstimateConverter
*/
protected $EstimateConverter;
/**
* @var LmDeliveryFee
*/
protected $LmDeliveryFee;
/**
* @var PaymentRepository
*/
protected $PaymentRepository;
/**
* @var TaxRuleService
*/
protected $TaxRuleService;
/**
* @var string[]
*/
protected $PrintName;
/**
* @var string[]
*/
protected $EstimateText;
/**
* @var array
*/
protected $EstimateDetailList;
/**
* @var int
*/
protected $Ritu = 0;
/**
* @var int
*/
protected $LargeDiscount = 0;
protected $RepeatDate;
protected $CartService;
/**
* キャンペーン割引合計
* @var int
*/
protected $CampaignDiscount = 0;
/**
* キャンペーン割引明細
* @var array
*/
protected $CampaignDetails = [];
/**
* 直近のカートアイテム
* @var array
*/
protected $LastCartItems = [];
/**
* @var DeliveryRepository
*/
protected $DeliveryRepository;
/**
* @var DeliveryFeeRepository
*/
protected $DeliveryFeeRepository;
/**
* @var YamlService
*/
protected $YamlService;
/**
* @var array
*/
private $Characters = [];
/**
* @var int
*/
private $LotBaseQuantity = 0;
/**
* @var array
*/
private $LotBaseQuantityByKind = [];
/**
* @var array
*/
private $LotBaseQuantityByKindAndType = [];
/**
* @var int
*/
private $LotQtyPrint = 0;
private $LotQtyMagic = 0;
private $LotQtyShishu = 0;
private $LotQtyTensha = 0;
/**
* @var array
*/
private $LotKindAlreadyShown = [];
/**
* @var array
*/
private $ApplyLotAllowedKind = [];
/**
* @var string
*/
protected $Page;
/**
* @var int
*/
protected $EstimateLine;
/**
* @var string
*/
protected $EstimateType;
/**
* @var int
*/
protected $Quantity;
public function __construct(CommonService $CommonService,
EstimateConverter $estimateConverter,
LmDeliveryFee $lmDeliveryFee,
PaymentRepository $paymentRepository,
TaxRuleService $taxRuleService,
CartService $CartService,
DeliveryRepository $DeliveryRepository,
DeliveryFeeRepository $DeliveryFeeRepository,
YamlService $YamlService
)
{
$this->CommonService = $CommonService;
$this->EstimateConverter = $estimateConverter;
$this->LmDeliveryFee = $lmDeliveryFee;
$this->PaymentRepository = $paymentRepository;
$this->TaxRuleService = $taxRuleService;
$this->PrintName = $CommonService->GetConfig('PRINT_NAME');
$this->EstimateText = $CommonService->GetConfig('ESTIMATE_TEXT');
$this->EstimateDetailList = $CommonService->GetConfig('ESTIMATE_DETAIL_LIST');
$this->CartService = $CartService;
$this->DeliveryRepository = $DeliveryRepository;
$this->DeliveryFeeRepository = $DeliveryFeeRepository;
$this->YamlService = $YamlService;
}
/********************************************************************************************************* */
/**
* 見積もりシミュレーション文字化
*
*/
public function EstimateCharacterIzation($Options, $OptionTotal = [], $Page = null)
{
$this->Characters = [];
if (!is_array($Options)) {
$Options = json_decode($Options, true);
}
// $Options = $this->SetOptions($Options, $OptionTotal);
if ($this->CommonService->IsNull($OptionTotal)) {
return;
}
$this->Page = $Page;
if (!isset($Options['product_total'])) {
if (!is_null($Options) && count($Options) > 0) {
$Options = $Options[0];
} else {
return;
}
}
$this->Characters['product_total'] = $Options['product_total'];
#プリントの算出
if ($Error = $this->GetPrint($Options)) {
throw new \RuntimeException("加工内容の取得処理に失敗しました。\nエラーコード: {$Error}");
}
#裾上げ
if ($Error = $this->GetSusoage($Options)) {
throw new \RuntimeException("加工内容(裾上げ)の取得処理に失敗しました。\nエラーコード: {$Error}");
}
#配送費の抽出
if ($Error = $this->GetCharge($Options)) {
throw new \RuntimeException("配送費の取得処理に失敗しました。\nエラーコード: {$Error}");
}
return;
}
/**
*
* 離島 043-1400
*/
protected function GetCharge($Options)
{
if ($this->Page) {
return;
}
$ProductTotal = $Options['product_total'];
$this->SetEstimateType(9);
$this->EstimateLine = 1;
$this->SetCharacters('title', $this->EstimateText['Text31']);
$this->SetCharacters('total', $this->EstimateText['Text32']);
$this->SetCharacters('service', false);
if (!$Charge = $Options['charge'] ?? null) {
return;
}
$Total = $ProductTotal + ($this->Characters['print_total']['total'] ?? 0)
+ ($this->Characters['susoage']['total'] ?? 0);
$ChargeTotal = 0;
if ($Prefe = $Charge['prefecture'] ?? null) {
#デリバリーFeeの計算
$DeliveryFee = $this->DeliveryFeeRepository->findOneBy([
'Delivery' => self::DeliveryId,
'Pref' => $Prefe,
]);
$Fee = is_object($DeliveryFee) ? $DeliveryFee->getFee() : 0;
$this->SetCharacters('total', Value: $Fee);
$ChargeTotal += $Fee;
#中継料
$this->EstimateLine = 2;
$RelayFee = 0;
if ($PostCode = $Charge['postcode'] ?? null) {
$RelayFee = $this->LmDeliveryFee->Island($PostCode);
}
#離島・沖縄は値引きしない;
if (1 === $this->getDelivery($Options['product_class_id'], $Options) && $RelayFee) {
$this->SetCharacters('title', $this->EstimateText['Text33']);
$this->SetCharacters('total', $RelayFee);
$this->SetCharacters('service', false);
$ChargeTotal += $RelayFee;
} else if ($Total >= $this->CommonService->GetBaseInfo('delivery_free_amounte') && 47 != $Prefe) {
#送料無料(金額)を超えている & 道府県が沖縄ではない
$this->SetCharacters('title', $this->EstimateText['Text34']);
$this->SetCharacters('total', $Fee * -1);
$this->SetCharacters('service', true);
$ChargeTotal -= $Fee;
}
}
#支払い手数料
if ($PaymentId = $Charge['payment'] ?? null) {
$this->EstimateLine = 3;
$Payment = $this->PaymentRepository->find($PaymentId);
$PaymentName = $Payment->getMethod();
$Fee = $Payment->getCharge();
if ($Fee > 0) {
$this->SetCharacters('title', $PaymentName . $this->EstimateText['Text35']);
$this->SetCharacters('total', $Fee);
$this->SetCharacters('service', false);
$ChargeTotal += $Fee;
//支払い手数料があった場合
if ($Total >= $this->CommonService->GetConfig('Payment_Charge_free')) {
$this->EstimateLine = 4;
$this->SetCharacters('title', $PaymentName . $this->EstimateText['Text36']);
$this->SetCharacters('total', $Fee * -1);
$this->SetCharacters('service', true);
$ChargeTotal -= $Fee;
}
}
}#支払い手数料
$lot = $this->Characters['lot']['total'] ?? 0 ;
$this->EstimateLine = 0;
$Re['title'] = $this->EstimateText['Text09'];
$Re['total'] = $ChargeTotal + $lot ;
$this->SetCharacters('total', $Re);
#大口割引
$this->SetLargeDiscount($Total);
if ($this->LargeDiscount) {
$Re['title'] = $this->EstimateText['Text37'] . "({$this->Ritu}%)";
$Re['total'] = $this->LargeDiscount * -1;
$Re['title2'] = $this->EstimateText['Text09'];
$this->Characters['lage_discount'] = $Re;
}
// キャンペーン割引(よりどりみどり割 / まとめ割)
if ($this->CampaignDiscount > 0) {
$Cd = [];
$Cd['title'] = 'キャンペーン割引';
$Cd['total'] = $this->CampaignDiscount * -1;
if (!empty($this->CampaignDetails)) {
$Cd['detail'] = $this->CampaignDetails;
}
$this->Characters['campaign_discount'] = $Cd;
}
#総計の計算
$this->SetEstimateType(10);
$Gross = $Total + $ChargeTotal - $this->LargeDiscount + $lot;
$this->EstimateLine = 1;
$this->SetCharacters('title', $this->EstimateText['Text38']);
$this->SetCharacters('total', $Gross);
$this->EstimateLine = 2;
$this->SetCharacters('title', $this->EstimateText['Text39']);
$this->SetCharacters('total', $One = floor($Gross / $Options['quantity']));
}
protected function SetEstimateType($Num)
{
$this->EstimateType = self::EstimateType[$Num];
$this->EstimateLine = 0;
}
protected function SetItiName($ItiName)
{
return preg_replace('/[A-Z]|:/', '', $ItiName);
}
/**
* 1 最大値のロットを表示
* 2 ロットは加算されない
* 3 0か未設定の場合計算させる
*/
protected function SetLots($Lot, $Kind = null, $PrintType = null, $isKyouei = false)
{
if (!is_null($Kind)) {
// この明細で許可されていない種別はスキップ
if (!($this->ApplyLotAllowedKind[$Kind] ?? false)) { return; }
// Create unique key based on Kind and PrintType logic
$lotKey = $this->createLotKey($Kind, $PrintType);
// 既に表示済みの種別+タイプはスキップ(lotの重複表示を防ぐ)
if (($this->LotKindAlreadyShown[$lotKey] ?? false)) { return; }
// 種別単位で厳密に判定(未集計のKindは適用しない)
if (!array_key_exists($Kind, $this->LotBaseQuantityByKind)) { return; }
// Get base quantity based on Kind and PrintType combination
$baseQuantity = $this->getBaseQuantityByKindAndType($Kind, $PrintType);
if ($baseQuantity >= $Lot) { return; }
// 刺繍 (Kind = 3) の場合は常に $PrintLot = 2000
if ($Kind == 3) {
$PrintLot = 2000;
} else {
// その他の場合は既存のロジックを維持
$PrintLot = $this->CommonService->GetConfig('PRINT_LOT');
if ($isKyouei) {
$PrintLot = 500;
}
}
$this->Characters['lot']['title'] = $this->EstimateText['Text06'];
$this->Characters['lot']['total'] = $PrintLot;
$this->LotKindAlreadyShown[$lotKey] = true;
return;
}
$baseQuantity = $this->LotBaseQuantity > 0 ? $this->LotBaseQuantity : $this->Quantity;
if ($baseQuantity < $Lot) {
// この場合はKindが指定されていないため、既存のロジックを維持
// (Kind = 3の判定は上記の$Kind != nullの場合で処理される)
if ($Kind == 3) {
$PrintLot = 2000;
} else {
$PrintLot = $this->CommonService->GetConfig('PRINT_LOT');
if ($isKyouei) {
$PrintLot = 500;
}
}
$this->Characters['lot']['title'] = $this->EstimateText['Text06'];
$this->Characters['lot']['total'] = $PrintLot;
}
}
/**
* Create lot key based on Kind and PrintType logic
*/
protected function createLotKey($Kind, $PrintType = null)
{
switch ($Kind) {
case 1: // シルクプリント
case 4: // マジック
case 3: // 刺繍
return $Kind . '_' . ($PrintType ?? 'default');
case 2: // デジタル転写
default:
return (string)$Kind;
}
}
/**
* Get base quantity by Kind and PrintType combination
*/
protected function getBaseQuantityByKindAndType($Kind, $PrintType = null)
{
// Create key based on the same logic as createLotKey
$key = $this->createLotKey($Kind, $PrintType);
// If we have specific Kind+PrintType data, use it
if (isset($this->LotBaseQuantityByKindAndType[$key])) {
return (int)$this->LotBaseQuantityByKindAndType[$key];
}
// Fallback to original logic for backward compatibility
switch ($Kind) {
case 1: return $this->LotQtyPrint;
case 4: return $this->LotQtyMagic;
case 3: return $this->LotQtyShishu;
case 2: return $this->LotQtyTensha;
default: return (int)($this->LotBaseQuantityByKind[$Kind] ?? 0);
}
}
protected function SetPrintTotal($Total)
{
if (isset($this->Characters['print_total'])) {
$this->Characters['print_total']['total'] += $Total;
} else {
$this->Characters['print_total']['title'] = $this->EstimateText['Text09'];
$this->Characters['print_total']['total'] = $Total;
}
}
protected function SetTotal($Total)
{
if (isset($this->Characters['total'])) {
$this->Characters['total'] += $Total;
} else {
$this->Characters['total'] = $Total;
}
}
protected function SetItems($Name, $Title, $Price = 0, $Quantity = 0, $Code = null, $Genka = null, $Detail = [], $basePrice = 0, $baseGenke = null, $opdKataType = null)
{
if (!$Quantity) {
$Quantity = $this->Quantity;
}
if ($opdKataType !== null){
$Re[$Name]['base_tanka'] = (int)$basePrice;
$Re[$Name]['base_genka'] = (int)$baseGenke;
$Re[$Name]['opdKataType'] = $opdKataType;
}
$Text = number_format($Price) . $this->EstimateText['Text02'] . $Quantity . $this->EstimateText['Text04'];
if ('print' == $Name) {
$Title = $this->EstimateText['Text19'] . $Text;
}
if ('shishu' == $Name) {
$Title .= $Text;
}
$Re[$Name]['title'] = $Title;
// if ($Price) {
$Total = $Price * $Quantity;
$Re[$Name]['total'] = $Total;
$this->SetPrintTotal($Total);
$this->SetTotal($Total);
// }
//
$Re[$Name]['code'] = $Code;
$Re[$Name]['quantity'] = (int)$Quantity;
$Re[$Name]['tanka'] = (int)$Price;
$Re[$Name]['genka'] = (int)$Genka;
//
if (!empty($Code) && ($EstimateDetail = $this->EstimateDetailList[$Code])) {
if (empty($Detail['name'])) {
$Detail['name'] = $EstimateDetail['name'];
}
if (empty($Detail['amount1']) && (!empty($Quantity))) {
$Detail['amount1'] = $Quantity;
}
if (empty($Detail['tanni1']) && (!empty($Detail['amount1'])) && !empty($EstimateDetail['tanni1'])) {
$Detail['tanni1'] = $EstimateDetail['tanni1'];
}
if (empty($Detail['tanni2']) && (!empty($Detail['amount2'])) && !empty($EstimateDetail['tanni2'])) {
$Detail['tanni2'] = $EstimateDetail['tanni2'];
}
if (empty($Detail['amount'])) {
$Detail['amount'] = $Detail['amount2'] ?? $Detail['amount1'];
}
}
//
$Re[$Name]['detail'] = $Detail;
//
$this->SetCharacters('item', $Re);
}
/** 本番では不要 */
public function SetOptions($Options, &$OptionTotal)
{
foreach (self::OptionTotalColumn as $Column) {
$Re = [];
if ($Total = $OptionTotal[$Column] ?? null) {
$Options[$Column] = $Total;
} else {
$Re[$Column] = $Options[$Column] ?? null;
}
}
if (count($Re) > 0) {
$OptionTotal = $Re;
}
return $Options;
}
protected function SetTitle($Kind, $Position, $Katamei = null, $Color = null)
{
$this->SetCharacters('Type', $Kind);
$Name = $this->PrintName[$Kind];
$this->SetCharacters('Type_Name', $Name);
if ($Katamei) {
$this->SetCharacters('katamei', $Katamei);
}
if ($Color) {
$this->SetCharacters('color', $Color);
}
$Title = "{$this->EstimateLine}ヶ所目 ({$Position}){$Name}";
if ($this->Page) {
$Title = $Title . ' ' . $Katamei;
}
$this->SetItems('title', $Title);
$this->SetCharacters('Position', $Position);
}
protected function SetCharacters($Name, $Value)
{
$Name = strtolower($Name);
if ($this->EstimateLine > 0) {
$Data = $this->Characters[$this->EstimateType][$this->EstimateLine][$Name] ?? null;
switch (gettype($Data)) {
case 'array':
$this->Characters[$this->EstimateType][$this->EstimateLine][$Name] = array_merge($Data, $Value);
break;
default:
$this->Characters[$this->EstimateType][$this->EstimateLine][$Name] = $Value;
}
return;
}
$this->Characters[$this->EstimateType][$Name] = $Value;
return;
}
protected function GetPrint($Options)
{
if (!$Prints = $Options['print'] ?? null) {
return;
};
$Num = $Options['kakou_me'] ?? 0;
$this->RepeatDate = $Options['date'] ?? null;
// Check if product is KYOEI supplier
$isKyouei = false;
if (isset($Options['product_class_id'])) {
$isKyouei = $this->hasKyouei($Options['product_class_id']);
}
$this->SetEstimateType(1);
for ($i = 1; $i <= $Num; $i++) {
$this->EstimateLine = $i;
$Print = $Prints[$i];
if (!$Kind = $Print['position'] ?? null) {
return 'P1';
}
$this->Quantity = $Options['quantity'] ?? 0;
switch ($Kind) {
case 1 : #シルクプリント
$Type = $Print['print_type'] ?? null;
$Iti = $Print['print_position'] ?? null;
$Color = $Print['print_detail'] ?? null;
if ($this->CommonService->IsNull([$Type, $Color])) {
continue 2;
}
if (!$Types = $this->EstimateConverter->getPrintDetail($Type)) {
return 'P1';
}
if (!$Itis = $this->EstimateConverter->getKakuninIchiById($Iti)) {
// return 'P2';
$Itis = self::ICHI_OTHER;
}
#タイトル
$Position = $this->SetItiName($Itis['ichi_name']);
$Katamei = $Types['pd_katamei'];
try {
$this->SetTitle($Kind, $Position, $Katamei, $Color);
} catch (\Exception $e) {
log_error($e->getMessage());
throw new NotFoundHttpException($e->getMessage());
}
#型代
$Kata =$this->SetKatadai(1,$Types['pd_katadai_tax10']);
$baseKata = $Types['pd_katadai_tax10'];
$Code = '993'; // TODO: Fetch actually data.
$opd_kata_type = $this->SetKatadaiType();
$Genka = $this->SetKatadai(1,$Types['pd_katadai_genka'],$Types['pd_katadai_saihan']);
$baseGenka = $opd_kata_type > 2 ? $Genka : $Types['pd_katadai_genka'];
$Kako = $this->EstimateText['Text01'];
$Title = $Kako[$Types['print_kakou']] . number_format($Kata) . $this->EstimateText['Text02'] . $Color . $this->EstimateText['Text16'];
$this->SetItems('kata', $Title, $Kata, $Color, $Code, $Genka, [], $baseKata, $baseGenka , $opd_kata_type);
#プリント代
$Price = $Types["pd_{$Color}print_tax10"];
$Quantity = null;
$Code = '996'; // TODO: Fetch actually data.
$Genka = $Types["pd_{$Color}print_genka"];
$this->SetItems('print', '', $Price, $Quantity, $Code, $Genka);
// Only set lots if product is from KYOEI supplier
if ($isKyouei) {
$this->SetLots($Types['print_lot'], $Kind, $Type, $isKyouei);
}
break;
case 4 : #マジック
$Type = $Print['magic_type'] ?? null;
$Iti = $Print['magic_position'] ?? null;
if ($this->CommonService->IsNull([$Type])) {
continue 2;
}
if (!$Types = $this->EstimateConverter->getMagickPrintDetail($Type)) {
return 'P3';
}
if (!$Itis = $this->EstimateConverter->getKakuninIchiById($Iti)) {
// return 'P4';
$Itis = self::ICHI_OTHER;
}
#️タイトル
$Position = $this->SetItiName($Itis['ichi_name']);
$Katamei = $Types['md_katamei'];
$this->SetTitle($Kind, $Position, $Katamei);
#プリント代
$Quantity = null;
$Code = '996'; // TODO: Fetch actually data.
$Genka = $Types["md_print_genka"];
$this->SetItems('print', '', $Types["md_print_tax10"], $Quantity, $Code, $Genka);
// Only set lots if product is from KYOEI supplier
if ($isKyouei) {
$this->SetLots($Types['magic_lot'], $Kind, $Type, $isKyouei);
}
break;
case 3 : #刺繍
$Type = $Print['shishu_type'] ?? null;
$Iti = $Print['shishu_position'] ?? null;
$Color = $Print['shishu_detail'] ?? null;
if ($this->CommonService->IsNull([$Type, $Color])) {
continue 2;
}
if (!$Types = $this->EstimateConverter->getShishuDetail($Type)) {
return 'P5';
}
if (!$Itis = $this->EstimateConverter->getKakuninIchiById($Iti)) {
// return 'P6';
$Itis = self::ICHI_OTHER;
}
#️タイトル
$Position = $this->SetItiName($Itis['ichi_name']);
$Katamei = $Types['sd_name'];
$this->SetTitle($Kind, $Position, $Katamei, $Color);
#パンチ
$Title = $this->EstimateText['Text07'];
$Quantity = 1;
$Code = '907'; // TODO: Fetch actually data.
$Detail = [
'amount' => 1,
];
$panchi = $this->SetKatadai(3,$Types['sd_panchi_tax10']);
$Genka = ((int)$panchi === 0) && !($Print['is_kamino'] ?? false) ? 0 : $Types["sd_panchi_genka"];
$this->SetItems('panchi', $Title, $panchi, $Quantity, $Code, $Genka, $Detail);
#刺繍代
$Title = $this->PrintName[3] . $this->EstimateText['Text03'] . ' ' . $Color . $this->EstimateText['Text16'] . ' ';
$Quantity = null;
$Code = '904'; // TODO: Fetch actually data.
$Genka = $Types["sd_{$Color}shishu_genka"];
$this->SetItems('shishu', $Title, $Types["sd_{$Color}shishu_tax10"], $Quantity, $Code, $Genka);
// 刺繍 (Kind = 3) の場合は常に SetLots を呼び出す(supplierに関係なく)
// For other kinds, only set lots if product is from KYOEI supplier
if ($Kind == 3 || $isKyouei) {
$this->SetLots($Types['shishu_lot'], $Kind, $Type, $isKyouei);
}
break;
case 2 : #デジタル転写 特殊
$Type = $Option['tensya'] ?? 1;
$Iti = $Print['tensha_position'] ?? null;
$Tate = $Print['tensha_tate'] ?? null;
$Yoko = $Print['tensha_yoko'] ?? null;
if ($this->CommonService->IsNull([$Tate, $Yoko])) {
continue 2;
}
if (!$Tensyas = $this->EstimateConverter->getTenshaDetailListById($Type)) {
return 'P5';
}
if (!$Itis = $this->EstimateConverter->getKakuninIchiById($Iti)) {
// return 'P6';
$Itis = self::ICHI_OTHER;
}
$Types = $Tensyas[0];
#️タイトル
$Position = $this->SetItiName($Itis['ichi_name']);
$Katamei = $Tate . $this->EstimateText['Text17'] . $this->EstimateText['Text18'] . $Yoko . $this->EstimateText['Text17'];
$this->SetTitle($Kind, $Position, $Katamei);
#型代
$Kata = 1;
if (is_null($Types['tensha_kata_kotei'])) {
$Kata = $Options['white_only'];
}
$Price = $this->SetKatadai(2,$Types['tensha_katadai_tax10']);
$opd_kata_type = $this->SetKatadaiType();
$basePrice = $Types['tensha_katadai_tax10'];
$Title = $this->EstimateText['Text11'] . number_format($Price) . $this->EstimateText['Text02'] . $Kata . $this->EstimateText['Text12'];
$Code = '993'; // TODO: Fetch actually data.
$Genka = $this->SetKatadai(2,$Types['tensha_katadai_genka'],$Types['tensha_katadai_saihan']);
$baseGenka = $opd_kata_type > 2 ? $Genka : $Types['tensha_katadai_genka'];
$this->SetItems('kata', $Title, $Price, $Kata, $Code, $Genka, [], $basePrice, $baseGenka, $opd_kata_type);
#シート 未定
$Price = $Types['tensha_sheet_tax10'];
$Sheet = $this->GetSheet($Types, $Tate, $Yoko);
$Title = $this->EstimateText['Text13'] . number_format($Price) . $this->EstimateText['Text02'] . $Sheet . $this->EstimateText['Text14'];
$Code = '995'; // TODO: Fetch actually data.
$Genka = $Types["tensha_sheet_genka"];
$this->SetItems('sheet', $Title, $Price, $Sheet, $Code, $Genka);
#圧着代:
$Price = $Types['tensha_acchaku_tax10'];
$Quantity = null;
$Code = '997'; // TODO: Fetch actually data.
$Genka = $Types["tensha_acchaku_genka"];
$Title = $this->EstimateText['Text15'] . number_format($Price) . $this->EstimateText['Text02'] . $this->Quantity . $this->EstimateText['Text04'];
$Detail= [
'amount1' => 1,
'amount2' => $this->Quantity,
];
$this->SetItems('acchaku', $Title, $Price, $Quantity, $Code, $Genka, $Detail);
// Only set lots if product is from KYOEI supplier
if ($isKyouei) {
$this->SetLots($Types['tensha_lot'], $Kind, $Type, $isKyouei);
}
break;
}
}
}
public function GetCharacters()
{
return $this->Characters;
}
protected function GetSusoage($Options)
{
if (!$Susoages = $Options['susoage'] ?? null) {
return;
}
$this->SetEstimateType(2);
$Num = 0;
foreach ($Susoages as $ProductId => $Susoage) {
foreach ($Susoage as $Data) {
if (!$Data['do']) {
continue;
}
$Num++;
}
}
$Susoage = $this->EstimateConverter->GetSusoage();
$Price = $Susoage['susoage_print_tax10'];
$Value =
$Total = $Price * $Num;
$this->SetCharacters('name', $this->EstimateText['Text21']);
$this->SetCharacters('hemming', $this->EstimateText['Text22']);
$this->SetCharacters('title', $this->EstimateText['Text22'] . ' ' . $Price . $this->EstimateText['Text02'] . $Num . $this->EstimateText['Text04']);
$this->SetCharacters('price', $Price);
$this->SetCharacters('suu', $Num);
$this->SetCharacters('total', $Total);
$this->Characters['total'] = $Total;
}
/**
* 2022/08/31
* 大口割聞を一括管理する
*
* 商品の合計と、加工賃で大口割引とする
* @param int $ProductTotal 商品合計
* @param int $ProcessingCost 加工費
*
*/
public function SetLargeDiscount($ProductTotal, $ProcessingCost = 0)
{
if($this->CartService->GetCartType()>=CartService::CartTypeSample){return;}
$Total = $ProductTotal + $ProcessingCost;
$Total_ = ($orderGroup = Order::getOrderGroup()) ? $orderGroup->getSubTotal() : $Total;
foreach ($this->CommonService->GetConfig('LargeDiscount') as $Param) {
if ($Total_ >= $Param['more']) {
$this->Ritu = $Param['discount'];
}
}
if (!$this->Ritu) {
return 0;
}
#2022/11/25 四捨五入から切り上げへ
//$TaxRule = $this->TaxRuleService->getTaxRule();
#$RoundingType = $TaxRule->getRoundingType();
$Discount = $Total * $this->Ritu / 100;
$this->LargeDiscount = $this->TaxRuleService->roundByRoundingType($Discount, \Eccube\Entity\Master\RoundingType::CEIL);
return $this->Ritu;
}
public function GetLargeDiscount()
{
return $this->LargeDiscount;
}
/**
* キャンペーン割引の合計を取得
*/
public function GetCampaignDiscount()
{
return (int)$this->CampaignDiscount;
}
/**
* キャンペーン割引の内訳を取得
*/
public function GetCampaignDetails()
{
return $this->CampaignDetails;
}
/**
* カートアイテムからキャンペーン割引を算出
* ・よりどりみどり割: campaign_yoridori=1 のアイテム合計。数量閾値以上で%割引
* ・まとめ割: campaign_matome=1 を商品毎に集計。数量閾値以上の商品のみ%割引
*/
protected function computeCampaignDiscount($Items)
{
$this->CampaignDiscount = 0;
$this->CampaignDetails = [];
if (empty($Items)) {
return;
}
// 期間内の有効キャンペーンを取得
$now = (new \DateTime())->format('Y-m-d H:i:s');
$campaigns = (new \Lm\Service\Db\SqlService())
->Table('campaign_table')
->Where('campaign_ddate IS NULL')
->Where('campaign_start <= :now')
->Where('campaign_end >= :now')
->Where('goods_canonical_hinban IS NOT NULL')
->Param(':now', $now)
->FindAll();
if (empty($campaigns) || empty($Items)) {
return;
}
// 単価(税込)を取得するヘルパー
$getUnitPrice = function($Item) {
try {
// 優先: 直接の税込単価があればそれを使う
if (method_exists($Item, 'getPriceIncTax')) {
return (int)$Item->getPriceIncTax();
}
// 次善: 税抜単価に対して税込化
if (method_exists($Item, 'getPrice')) {
$ex = (int)$Item->getPrice();
// TaxRuleService 経由で税込化 (四捨五入ルールに追従)
if ($this->TaxRuleService) {
return (int)$this->TaxRuleService->getIncTax($ex);
}
// フォールバック: 現行税率で簡易税込化
$taxRate = method_exists($this->TaxRuleService, 'getTaxRule') ? $this->TaxRuleService->getTaxRule()->getTaxRate() : 10;
return (int) round($ex * (1 + ($taxRate / 100)));
}
} catch (\Throwable $e) {}
return 0;
};
// 集計: 各商品ごとの小計/数量/フラグ
// goodsId => ['qty'=>int,'sum'=>int,'yoridori'=>0/1,'matome'=>0/1, 'hinban' => string, 'productCodes' => array]
$goodsMap = [];
// productCode => goodsId mapping to count different product types
$productCodeToGoodsId = []; // productCode => goodsId
foreach ($Items as $Item) {
if (!method_exists($Item, 'getProductClass') || !method_exists($Item, 'getQuantity')) {
continue;
}
$productClass = $Item->getProductClass();
if (!$productClass) {
continue;
}
$product = $productClass->getProduct();
if (!$product) {
continue;
}
$goodsId = $product->getId();
$qty = (int)$Item->getQuantity();
$unit = $getUnitPrice($Item);
$productCode = $productClass->getCode() ?? '';
// フラグは EC 側の Goods エンティティに合わせて取得(なければスキップ)
$yoridori = 0; $matome = 0;
$goodsHinban = '';
try {
// Query campaign flags directly from goods_table
$sqlService = new \Lm\Service\Db\SqlService();
$goodsData = $sqlService
->Table('goods_table')
->Where('goods_id = :goods_id')
->Param(':goods_id', $goodsId)
->Find();
if ($goodsData) {
$yoridori = (int)($goodsData['campaign_yoridori'] ?? 0);
$matome = (int)($goodsData['campaign_matome'] ?? 0);
$goodsHinban = trim($goodsData['goods_canonical_hinban'] ?? '');
}
} catch (\Throwable $e) {
// Skip error
}
if (!isset($goodsMap[$goodsId])) {
$goodsMap[$goodsId] = ['qty' => 0, 'sum' => 0, 'yoridori' => 0, 'matome' => 0, 'hinban' => '', 'productCodes' => []];
}
$goodsMap[$goodsId]['qty'] += $qty;
$goodsMap[$goodsId]['sum'] += ($unit * $qty);
if ($yoridori === 1) { $goodsMap[$goodsId]['yoridori'] = 1; }
if ($matome === 1) { $goodsMap[$goodsId]['matome'] = 1; }
if (!empty($goodsHinban)) { $goodsMap[$goodsId]['hinban'] = $goodsHinban; }
if (!empty($productCode)) {
$goodsMap[$goodsId]['productCodes'][$productCode] = true;
$productCodeToGoodsId[$productCode] = $goodsId;
}
}
// キャンペーンを種別でグルーピング: 1=よりどり → 2=まとめ
$yoridoriCampaigns = [];
$matomeCampaigns = [];
foreach ($campaigns as $c) {
$type = (int)($c['campaign_type'] ?? 0);
if ($type !== 1 && $type !== 2) {
continue;
}
$flagKey = $type === 1 ? 'yoridori' : 'matome';
$campaignHinbans = $c['goods_canonical_hinban'] ?? '';
$hinbanList = null;
if (!empty($campaignHinbans)) {
$hinbanList = array_filter(array_map('trim', explode(',', $campaignHinbans)), function ($value) {
return $value !== '';
});
if (empty($hinbanList)) {
$hinbanList = null;
}
}
$targetsGoods = [];
$totalQty = 0;
$totalSum = 0;
foreach ($goodsMap as $gid => $g) {
if (($g[$flagKey] ?? 0) !== 1) {
continue;
}
if ($hinbanList !== null) {
$goodsHinban = $g['hinban'] ?? '';
if ($goodsHinban === '' || !in_array($goodsHinban, $hinbanList, true)) {
continue;
}
}
$targetsGoods[$gid] = $g;
$totalQty += (int)($g['qty'] ?? 0);
$totalSum += (int)($g['sum'] ?? 0);
}
if (empty($targetsGoods)) {
continue;
}
$entry = [
'campaign' => $c,
'targets' => [
'goods' => $targetsGoods,
'qty' => $totalQty,
'sum' => $totalSum,
],
];
if ($type === 1) {
$yoridoriCampaigns[] = $entry;
} else {
$matomeCampaigns[] = $entry;
}
}
// カート内の異なる商品種類数(商品ID単位)
$totalUniqueProductCount = 0;
foreach ($goodsMap as $gid => $g) {
if ((int)($g['qty'] ?? 0) > 0) {
$totalUniqueProductCount++;
}
}
// よりどり: 同一キャンペーンIDごとにマージして合計 qty/sum で判定・割引
$mergedYoridori = [];
foreach ($yoridoriCampaigns as $entry) {
// よりどりはカート内に2種類以上の商品がある場合のみ適用
if ($totalUniqueProductCount < 2) {
continue;
}
$c = $entry['campaign'];
$cid = (int)($c['campaign_id'] ?? 0);
$minQty = (int)($c['min_product_count'] ?? 0);
$percent = (float)($c['discount_percent'] ?? 0);
$cname = $c['campaign_name'] ?? '';
$key = $cid > 0 ? (string)$cid : ($cname . '|' . $minQty . '|' . $percent);
if (!isset($mergedYoridori[$key])) {
$mergedYoridori[$key] = [
'campaign' => $c,
'targets' => [
'goods' => [],
'qty' => 0,
'sum' => 0,
],
];
}
// merge targets: sum qty/sum; keep union goods (last wins)
$mergedYoridori[$key]['targets']['qty'] += (int)($entry['targets']['qty'] ?? 0);
$mergedYoridori[$key]['targets']['sum'] += (int)($entry['targets']['sum'] ?? 0);
foreach (($entry['targets']['goods'] ?? []) as $gid => $g) {
$mergedYoridori[$key]['targets']['goods'][$gid] = $g;
}
}
// replace list
$yoridoriCampaigns = array_values($mergedYoridori);
// まとめ: 同一キャンペーンIDごとにマージして合算(よりどりと同様の処理)
$mergedMatome = [];
foreach ($matomeCampaigns as $entry) {
$c = $entry['campaign'];
$cid = (int)($c['campaign_id'] ?? 0);
$minQty = (int)($c['min_product_count'] ?? 0);
$percent = (float)($c['discount_percent'] ?? 0);
$cname = $c['campaign_name'] ?? '';
$key = $cid > 0 ? (string)$cid : ($cname . '|' . $minQty . '|' . $percent);
if (!isset($mergedMatome[$key])) {
$mergedMatome[$key] = [
'campaign' => $c,
'targets' => [
'goods' => [],
'qty' => 0,
'sum' => 0,
],
];
}
// merge targets: sum qty/sum; keep union goods (last wins)
$mergedMatome[$key]['targets']['qty'] += (int)($entry['targets']['qty'] ?? 0);
$mergedMatome[$key]['targets']['sum'] += (int)($entry['targets']['sum'] ?? 0);
foreach (($entry['targets']['goods'] ?? []) as $gid => $g) {
$mergedMatome[$key]['targets']['goods'][$gid] = $g;
}
}
// replace list
$matomeCampaigns = array_values($mergedMatome);
// よりどり優先仕様:
// 1) 先によりどりを判定・適用
// 2) よりどり適用済み商品は、まとめの対象から除外
$yoridoriAppliedGoodsIds = [];
foreach ($yoridoriCampaigns as $entry) {
if ($totalUniqueProductCount < 2) {
continue;
}
$c = $entry['campaign'];
$targets = $entry['targets'];
$minQty = (int)($c['min_product_count'] ?? 0);
$percent = (float)($c['discount_percent'] ?? 0);
$cid = (int)($c['campaign_id'] ?? 0);
$cname = $c['campaign_name'] ?? '';
if ($percent <= 0) {
continue;
}
$eligibleGoods = $targets['goods'] ?? [];
$eligibleQty = (int)($targets['qty'] ?? 0);
$eligibleSum = (int)($targets['sum'] ?? 0);
// よりどりは同一キャンペーン内で2種類以上の商品が必要
if (count($eligibleGoods) < 2) {
continue;
}
if ($eligibleQty < $minQty || $eligibleSum <= 0) {
continue;
}
$discount = (int)round($eligibleSum * $percent / 100);
if ($discount <= 0) {
continue;
}
$this->CampaignDiscount += $discount;
$this->CampaignDetails[] = [
'id' => $cid,
'type' => 1,
'name' => $cname,
'amount' => $discount,
'min' => $minQty,
'percent' => $percent,
];
foreach ($eligibleGoods as $gid => $_g) {
$yoridoriAppliedGoodsIds[$gid] = true;
}
}
// 2) まとめ: よりどり適用済み商品を除外して判定・適用
foreach ($matomeCampaigns as $entry) {
$c = $entry['campaign'];
$targets = $entry['targets'];
$minQty = (int)($c['min_product_count'] ?? 0);
$percent = (float)($c['discount_percent'] ?? 0);
$cid = (int)($c['campaign_id'] ?? 0);
$cname = $c['campaign_name'] ?? '';
if ($percent <= 0) {
continue;
}
$campaignDiscountTotal = 0;
foreach (($targets['goods'] ?? []) as $gid => $g) {
if (isset($yoridoriAppliedGoodsIds[$gid]) && $yoridoriAppliedGoodsIds[$gid]) {
continue;
}
$goodsQty = (int)($g['qty'] ?? 0);
if ($goodsQty < $minQty) {
continue;
}
$base = (int)($g['sum'] ?? 0);
if ($base <= 0) {
continue;
}
$goodsDiscount = (int)round($base * $percent / 100);
if ($goodsDiscount <= 0) {
continue;
}
$campaignDiscountTotal += $goodsDiscount;
}
if ($campaignDiscountTotal > 0) {
$this->CampaignDiscount += $campaignDiscountTotal;
$this->CampaignDetails[] = [
'id' => $cid,
'type' => 2,
'name' => $cname,
'amount' => $campaignDiscountTotal,
'min' => $minQty,
'percent' => $percent,
];
}
}
}
/**
* デジタル転写シートを算出
* $Tate = 230;$Yoko = 60; 2パターンの方が多くなる
*
*/
protected function GetSheet($Data, $Tate, $Yoko)
{
//$Tate = 190;$Yoko = 130;
$MaxTate = $Data['tensha_tate'];
$MaxYoko = $Data['tensha_yoko'];
$Tate += (int)$this->CommonService->GetConfig('ESTIMATE_YOHAKU');
$Yoko += (int)$this->CommonService->GetConfig('ESTIMATE_YOHAKU');
#1 縦横で算出
$S1 = floor($MaxTate / $Tate) * floor($MaxYoko / $Yoko);
#2 横縦で算出
$S2 = floor($MaxTate / $Yoko) * floor($MaxYoko / $Tate);
if(max($S1, $S2) == 0){
return $this->Quantity;
}
$Sheet = $this->Quantity / max($S1, $S2);
return ceil($Sheet);
}
/**
* @param object $Items
* @param $Param
*
*/
public function SetEstimateOption($Items, $Param, $Page = 'cart')
{
// カートアイテムを保持(キャンペーン計算用)
if (is_array($Items)) {
$this->LastCartItems = $Items;
} else if (is_iterable($Items)) {
$this->LastCartItems = iterator_to_array($Items);
}
// キャンペーン割引を計算(SetEstimateOptionで直接実行)
$this->computeCampaignDiscount($this->LastCartItems);
$Options = [];
$Total = 0;
// ロット合算対象(printあり)のみ数量集計
$this->LotBaseQuantity = 0;
$this->LotBaseQuantityByKind = [];
$this->LotBaseQuantityByKindAndType = [];
$this->LotQtyPrint = 0;
$this->LotQtyMagic = 0;
$this->LotQtyShishu = 0;
$this->LotQtyTensha = 0;
$this->LotKindAlreadyShown = [];
foreach ($Items as $qItem) {
$qty = method_exists($qItem, 'getQuantity') ? (int)$qItem->getQuantity() : 0;
if ($qty <= 0) { continue; }
$opts = null;
if (method_exists($qItem, 'getOptionsData')) {
$opts = $qItem->getOptionsData();
} elseif (method_exists($qItem, 'getOptions')) {
$raw = $qItem->getOptions();
$opts = is_string($raw) ? json_decode($raw, true) : $raw;
}
if (is_array($opts) && !empty($opts['print'])) {
// 同一アイテム内で同じKindが複数ヶ所あっても数量は一度だけ加算する
$kindsThisItem = [];
$kindsAndTypesThisItem = [];
foreach ($opts['print'] as $p) {
$kind = isset($p['position']) ? (int)$p['position'] : 0;
if ($kind === 0) { continue; }
// Get print type for this kind
$printType = null;
switch ($kind) {
case 1: // silk
$printType = $p['print_type'] ?? null;
break;
case 4: // magic
$printType = $p['magic_type'] ?? null;
break;
case 3: // shishu
$printType = $p['shishu_type'] ?? null;
break;
case 2: // tensha
$printType = 'tensha';
break;
}
// 種別ごとに必須入力を満たす場合のみ採用
$isValid = false;
switch ($kind) {
case 1: // silk
$isValid = !empty($p['print_type']) && !empty($p['print_detail']);
break;
case 4: // magic
$isValid = !empty($p['magic_type']);
break;
case 3: // shishu
$isValid = !empty($p['shishu_type']) && !empty($p['shishu_detail']);
break;
case 2: // tensha
$isValid = !empty($p['tensha_tate']) && !empty($p['tensha_yoko']);
break;
}
if ($isValid) {
$kindsThisItem[$kind] = true;
// Also track Kind+PrintType combinations using createLotKey logic
$kindTypeKey = $this->createLotKey($kind, $printType);
$kindsAndTypesThisItem[$kindTypeKey] = true;
}
}
if (!empty($kindsThisItem)) {
// このCartItemは印刷あり → 全体合算数量も加算
$this->LotBaseQuantity += $qty;
foreach (array_keys($kindsThisItem) as $kind) {
if (!isset($this->LotBaseQuantityByKind[$kind])) {
$this->LotBaseQuantityByKind[$kind] = 0;
}
$this->LotBaseQuantityByKind[$kind] += $qty;
// 明示的な4変数にも反映
switch ($kind) {
case 1: $this->LotQtyPrint += $qty; break;
case 4: $this->LotQtyMagic += $qty; break;
case 3: $this->LotQtyShishu += $qty; break;
case 2: $this->LotQtyTensha += $qty; break;
}
}
// Also add to Kind+PrintType combinations
foreach (array_keys($kindsAndTypesThisItem) as $kindTypeKey) {
if (!isset($this->LotBaseQuantityByKindAndType[$kindTypeKey])) {
$this->LotBaseQuantityByKindAndType[$kindTypeKey] = 0;
}
$this->LotBaseQuantityByKindAndType[$kindTypeKey] += $qty;
}
}
}
}
foreach ($Items as $Item) {
if (!$Item->getOptions()) {
continue;
}
// このアイテムに印刷があるか/どの種別かを判定し、本明細で許可する種別をセット
$opts = $Item->getOptions();
if (is_string($opts)) { $opts = json_decode($opts, true); }
// Add product_class_id to options if Item has it
if (method_exists($Item, 'getProductClass') && $Item->getProductClass()) {
$productClass = $Item->getProductClass();
if (method_exists($productClass, 'getId')) {
$opts['product_class_id'] = $productClass->getId();
}
}
$this->ApplyLotAllowedKind = [];
if (is_array($opts) && !empty($opts['print'])) {
foreach ($opts['print'] as $p) {
$kind = isset($p['position']) ? (int)$p['position'] : null;
if (is_null($kind)) { continue; }
// Get print type for this kind
$printType = null;
switch ($kind) {
case 1: // シルクプリント
$printType = $p['print_type'] ?? null;
break;
case 4: // マジック
$printType = $p['magic_type'] ?? null;
break;
case 3: // 刺繍
$printType = $p['shishu_type'] ?? null;
break;
case 2: // デジタル転写
$printType = 'tensha';
break;
}
// Create unique key using createLotKey logic
$lotKey = $this->createLotKey($kind, $printType);
// 未表示の種別+タイプのみ許可
if (!($this->LotKindAlreadyShown[$lotKey] ?? false)) {
$this->ApplyLotAllowedKind[$kind] = true;
}
}
}
#OrderItemの時 不要かな?
if ('order' == $Page) {
$orderItemTypeId = null;
if (method_exists($Item, 'getOrderItemTypeId')) {
$orderItemTypeId = $Item->getOrderItemTypeId();
} elseif (method_exists($Item, 'getOrderItemType') && $Item->getOrderItemType()) {
$orderItemTypeId = $Item->getOrderItemType()->getId();
} else {
// For CartItem, assume it's a product type (type 1) for processing
$orderItemTypeId = 1;
}
if (1 != $orderItemTypeId) {
$this->ApplyLotAllowedKind = []; // 念のためリセット
continue;
}
}
#重複するEstimateIdの回避
if (isset($Options[$Item->getEstimateId()])) {
$this->ApplyLotAllowedKind = []; // 念のためリセット
continue;
}
$EstimantTotal = $Param[$Item->getEstimateId()] ?? [];
if ($Error = $this->EstimateCharacterIzation($opts, $EstimantTotal, $Page)) {
$this->ApplyLotAllowedKind = []; // 念のためリセット
throw new \RuntimeException("見積もりシミュレーションのデータ解析処理に失敗しました\nエラーコード: {$Error}");
}
$Options[$Item->getEstimateId()] = $this->Characters;
$Total += $this->Characters['total'] ?? 0;
$Total += $this->Characters['lot']['total'] ?? 0;
// このアイテムで表示された種別+タイプを記録
if (is_array($opts) && !empty($opts['print'])) {
foreach ($opts['print'] as $p) {
$kind = isset($p['position']) ? (int)$p['position'] : null;
if (is_null($kind)) { continue; }
// Get print type for this kind
$printType = null;
switch ($kind) {
case 1: // シルクプリント
$printType = $p['print_type'] ?? null;
break;
case 4: // マジック
$printType = $p['magic_type'] ?? null;
break;
case 3: // 刺繍
$printType = $p['shishu_type'] ?? null;
break;
case 2: // デジタル転写
$printType = 'tensha';
break;
}
// Create unique key using createLotKey logic
$lotKey = $this->createLotKey($kind, $printType);
// このアイテムで有効な種別+タイプを記録
if ($this->ApplyLotAllowedKind[$kind] ?? false) {
$this->LotKindAlreadyShown[$lotKey] = true;
}
}
}
// ループ終端で常にリセット
$this->ApplyLotAllowedKind = [];
}
return [$Total, $Options];
}
protected function SetKatadai($type,$Price,$priceAfterYear = null){
#リピート注文ではない
if (!$this->RepeatDate){return $Price;}
$Day = new \DateTime($this->RepeatDate);
$Diff = $Day->diff(new \DateTime('now'));
$RepeteData= $this->CommonService->GetConfig('ESTIMATE_REPEAT');
$hikaku = 'under';
if ($Diff->days > $RepeteData['day']){$hikaku = 'orver';}
$Ritu = $RepeteData[$type][$hikaku];
$Price = $Price * $Ritu /100;
if($priceAfterYear && $hikaku == 'orver') {
$Price = $priceAfterYear;
}
return $Price;
}
protected function SetKatadaiType(){
#リピート注文ではない
if (!$this->RepeatDate){return null;}
$Day = new \DateTime($this->RepeatDate);
$Diff = $Day->diff(new \DateTime('now'));
$RepeteData= $this->CommonService->GetConfig('ESTIMATE_REPEAT');
$hikaku = 'under';
if ($Diff->days > $RepeteData['day']){$hikaku = 'orver';}
return $hikaku == 'under' ? 2 : 3;
}
private function getDelivery($productClassId, $Options)
{
if (!$productClassId) return self::DeliveryId;
$CartType = CartService::CartTypeEstimate;
if ($this->hasSusoage($productClassId) || $this->hasKyouei($productClassId) || $this->hasShishu($Options)) {
$CartType = CartService::CartTypeNormal;
}
$DeliverMap = $this->YamlService->GetYaml('DeliveryMapping,yaml');
$DeliveryId = $DeliverMap[$CartType] ?? 1;
$Delivery = $this->DeliveryRepository->findBy(['id' => $DeliveryId]);
return $Delivery ? $Delivery[0]->getId() : self::DeliveryId;
}
private function hasSusoage($productClassId)
{
return GoodsService::isSusoageExistInJanIdList([$productClassId]);
}
private function hasKyouei($productClassId)
{
return GoodsService::isKyoueiExistInJanIdList([$productClassId]);
}
private function hasShishu($Options)
{
$hasShishu = false;
if (isset($Options['print']) && is_array($Options['print'])) {
$prints = $Options['print'];
foreach ($prints as $print) {
if ($print['position'] == 3) {
$hasShishu = true;
}
}
}
return $hasShishu;
}
}