app/Customize/Twig/Extension/ServiceExtension.php line 1187

Open in your IDE?
  1. <?php
  2. /**
  3.  * @version EC=CUBE4
  4.  * @copyright 株式会社 翔 kakeru.co.jp
  5.  * @author
  6.  * 2021年11月29日作成
  7.  *
  8.  * app\Customize\Twig\Extension\ServiceExtension.php
  9.  *
  10.  * TWIGからサービスの呼び出し
  11.  *
  12.  *
  13.  *
  14.  *                             C= C= C= ┌(;・_・)┘トコトコ
  15.  ******************************************************/
  16. namespace Customize\Twig\Extension;
  17. use Customize\Entity\CacheTrait;
  18. use Customize\Service\FavoriteService;
  19. use Customize\Service\GoodsPriceService;
  20. use Customize\Service\Google\ReCaptchaService;
  21. use Customize\Service\InventoryMatrixService;
  22. use Customize\Service\OrderService;
  23. use Customize\Service\Payment\PaymentService;
  24. use Customize\Service\SampleService;
  25. use DOMNamedNodeMap;
  26. use DOMNode;
  27. use Eccube\Entity\CartItem;
  28. use Eccube\Entity\OrderItem;
  29. use Eccube\Repository\ClassCategoryRepository;
  30. use Eccube\Repository\ProductRepository;
  31. use Lm\Engine\EC\Entity\GoodsWithRelated;
  32. use Lm\Engine\EC\Entity\Item\Item;
  33. use Lm\Engine\EC\Entity\OrderHeaderExtended;
  34. use Lm\Engine\InventoryMatrix\InventoryMatrix;
  35. use Lm\Engine\Zaiko\Yoyaku;
  36. use Lm\Entity\Goods;
  37. use Lm\Entity\OrderHeader;
  38. use Lm\Service\Cache\CacheService;
  39. use Lm\Util\Date;
  40. use Detection\MobileDetect as MobileDetector;
  41. use Symfony\Component\DependencyInjection\ContainerInterface;
  42. use Symfony\Component\DomCrawler\Crawler;
  43. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  44. use Symfony\Component\HttpFoundation\RequestStack;
  45. use Twig\Extension\AbstractExtension;
  46. use Twig\TwigFunction;
  47. use Twig\TwigFilter;
  48. use Twig\Environment as Twig;
  49. use Customize\Service\LmHelper;
  50. use Customize\Service\CustomerService;
  51. use Customize\Service\CommonService;
  52. use Eccube\Repository\ProductClassRepository;
  53. use Eccube\Repository\OrderRepository;
  54. use Eccube\Repository\Master\PrefRepository;
  55. use Eccube\Repository\Master\JobRepository;
  56. use Lm\Service\Db\SqlService;
  57. use Lm\Engine\NoukiKeisan\NoukiKeisan as NoukiEngine;
  58. use Customize\Service\CatalogService;
  59. use Customize\Service\CartService;
  60. use Customize\Service\GoodsService;
  61. use Customize\Service\MetaTagService;
  62. use Customize\Service\EstimateCharacterizer;
  63. use Eccube\Repository\Master\OrderItemTypeRepository;
  64. use Customize\Converter\OrderConverter;
  65. use Customize\Service\OrderHelper;
  66. use Customize\Service\AutoLoadService;
  67. use Customize\Service\MobileDetector as LmMobileDetector;
  68. use Lm\Engine\SokujitsuHassou\SokujitsuHassou;
  69. use Twig\TwigTest;
  70. use Customize\Converter\ProductConverter;
  71. class ServiceExtension extends AbstractExtension
  72. {
  73.     use CacheTrait;
  74.     const Cache1 'EstimateProductClassIds';
  75.     const MetatagTwig 'Common/MetaTags.twig';
  76.     const BreadCrumTwig 'Common/BreadCrumb.twig';
  77.     const EstimateTwig 'Common/Estimate.twig';
  78.     const ExclusionTwig 'Cart/Parts/Exclusion.twig';
  79.     const CartAddLineTwig 'Cart/Parts/Responsive/AddLine.twig';
  80.     const ShoppingEstimate 'Shopping/Parts/Estimate.twig';
  81.     const MobileShoppingEstimate 'Common/MobileEstimate.twig';
  82.     const MailEstimate 'Mail/Parts/Estimate.twig';
  83.     const JWeek = ['日''月''火''水''木''金''土'];
  84.     /**
  85.      * @var Container
  86.      */
  87.     protected $Container;
  88.     protected $Session;
  89.     protected $RequestStack;
  90.     protected $LmHelper;
  91.     protected $CustomerService;
  92.     protected $CommonService;
  93.     protected $PrefRepository;
  94.     protected $JobRepository;
  95.     protected $Router;
  96.     protected $Request;
  97.     protected $CatalogService;
  98.     protected $CartService;
  99.     protected $CatalogValue;
  100.     protected $GoodsService;
  101.     protected $Twig;
  102.     /**
  103.      * @var ProductRepository
  104.      */
  105.     private $ProductRepository;
  106.     protected $ProductClassRepository;
  107.     protected $Bank;
  108.     protected $CacheService;
  109.     protected $MetaTagService;
  110.     protected $EstimateCharacterizer;
  111.     protected $OrderItemTypeRepository;
  112.     protected $PaymentDetails = [];
  113.     protected $EstimateOptions = [];
  114.     protected $OrderConverter;
  115.     protected $OrderRepository;
  116.     protected $EstimateType;
  117.     protected $AutoLoadService;
  118.     protected $CartSortFlg;
  119.     
  120.     /**
  121.      * @var array
  122.      */
  123.     protected $EstimateOptionsByEstimateId = [];
  124.     
  125.     /**
  126.      * @var array
  127.      */
  128.     protected $ItemIdToEstimateId = [];
  129.     
  130.     /**
  131.      * @var array
  132.      */
  133.     protected $AllOrderItems = [];
  134.     /**
  135.      * @var MobileDetector
  136.      */
  137.     private $mobileDetector;
  138.     /**
  139.      * @var LmMobileDetector
  140.      */
  141.     private $LmMobileDetector;
  142.     /**
  143.      * @var FavoriteService
  144.      */
  145.     private $FavoriteService;
  146.     /**
  147.      * @var SampleService
  148.      */
  149.     private $SampleService;
  150.     /**
  151.      * @var OrderService
  152.      */
  153.     private $OrderService;
  154.     private $paymentService;
  155.     private $reCaptchaService;
  156.     private $productConverter;
  157.     public function __construct(ContainerInterface      $Container,
  158.                                 SessionInterface        $Session,
  159.                                 RequestStack            $RequestStack,
  160.                                 LmHelper                $LmHelper,
  161.                                 CustomerService         $CustomerService,
  162.                                 CommonService           $CommonService,
  163.                                 PrefRepository          $PrefRepository,
  164.                                 JobRepository           $JobRepository,
  165.                                 CatalogService          $CatalogService,
  166.                                 CartService             $CartService,
  167.                                 GoodsService            $GoodsService,
  168.                                 Twig                    $Twig,
  169.                                 ProductRepository       $productRepository,
  170.                                 ProductClassRepository  $ProductClassRepository,
  171.                                 ClassCategoryRepository $ClassCategoryRepository,
  172.                                 CacheService            $CacheService,
  173.                                 MetaTagService          $MetaTagService,
  174.                                 EstimateCharacterizer   $EstimateCharacterizer,
  175.                                 OrderItemTypeRepository $OrderItemTypeRepository,
  176.                                 OrderService            $orderService,
  177.                                 OrderConverter          $OrderConverter,
  178.                                 OrderRepository         $OrderRepository,
  179.                                 GoodsPriceService       $GoodsPriceService,
  180.                                 AutoLoadService         $AutoLoadService,
  181.                                 MobileDetector          $mobileDetector,
  182.                                 LmMobileDetector        $LmMobileDetector,
  183.                                 FavoriteService         $FavoriteService,
  184.                                 SampleService           $SampleService,
  185.                                 PaymentService          $paymentService,
  186.                                 InventoryMatrixService  $inventoryMatrixService,
  187.                                 ReCaptchaService        $reCaptchaService,
  188.                                 ProductConverter        $productConverter
  189.     )
  190.     {
  191.         $this->Container $Container;
  192.         $this->Session $Session;
  193.         $this->RequestStack $RequestStack;
  194.         $this->LmHelper $LmHelper;
  195.         $this->CustomerService $CustomerService;
  196.         $this->CommonService $CommonService;
  197.         $this->PrefRepository $PrefRepository;
  198.         $this->JobRepository $JobRepository;
  199.         $this->Router $Container->get('router');
  200.         $this->Request $RequestStack->getCurrentRequest();
  201.         $this->CatalogService $CatalogService;
  202.         $this->CartService $CartService;
  203.         $this->GoodsService $GoodsService;
  204.         $this->Twig $Twig;
  205.         $this->ProductRepository $productRepository;
  206.         $this->ProductClassRepository $ProductClassRepository;
  207.         $this->ClassCategoryRepository $ClassCategoryRepository;
  208.         $this->CacheService $CacheService;
  209.         $this->MetaTagService $MetaTagService;
  210.         $this->EstimateCharacterizer $EstimateCharacterizer;
  211.         $this->OrderItemTypeRepository $OrderItemTypeRepository;
  212.         $this->OrderService $orderService;
  213.         $this->OrderConverter $OrderConverter;
  214.         $this->OrderRepository $OrderRepository;
  215.         $this->GoodsPriceService $GoodsPriceService;
  216.         $this->AutoLoadService $AutoLoadService;
  217.         $this->mobileDetector $mobileDetector;
  218.         $this->LmMobileDetector $LmMobileDetector;
  219.         $this->FavoriteService $FavoriteService;
  220.         $this->SampleService $SampleService;
  221.         $this->paymentService $paymentService;
  222.         $this->inventoryMatrixService $inventoryMatrixService;
  223.         $this->reCaptchaService $reCaptchaService;
  224.         $this->productConverter $productConverter;
  225.     }
  226.     public function getFunctions()
  227.     {
  228.         return [
  229.             new TwigFunction('Service', function ($Service) {
  230.                 return new $Service($this->Container$this->RequestStack);
  231.             }, ['pre_escape' => 'html''is_safe' => ['html']]),
  232.             new TwigFunction('LmCssList', [$this'GetLmCssList']),
  233.             new TwigFunction('LmCartType', [$this'GetLmCartType']),
  234.             new TwigFunction('FristLogin', [$this'GetFirstLogin']),
  235.             new TwigFunction('AmazonLogin', [$this'GetAmazonLogin']),
  236.             new TwigFunction('GetPrefs', [$this'GetPrefs']),
  237.             new TwigFunction('GetLmCuatomer', [$this'GetLmCuatomer']),
  238.             new TwigFunction('GetJob', [$this'GetJob']),
  239.             new TwigFunction('GetPrivacy3', [$this'GetPrivacy3']),
  240.             new TwigFunction('OlToken', [$this'GetOlToken']),
  241.             new TwigFunction('RequestLmOrderOption', [$this->CommonService'RequestLmOrderOption']),
  242.             new TwigFunction('Survey', [$this->CommonService'SetSurvey']),
  243.             new TwigFunction('SurveyData', [$this->CommonService'SetSurveyData']),
  244.             new TwigFunction('RequestUri', [$this'GetRequestUri']),
  245.             new TwigFunction('CouponData', [$this'GetCouponData']),
  246.             new TwigFunction('InitiarizeLmOrederOption', [$this'SetInitiarizeLmOrederOption']),
  247.             new TwigFunction('DiscountName', [$this'SetDiscountName']),
  248.             new TwigFunction('SetReceipt', [$this'SetReceipt']),
  249.             new TwigFunction('Receipt', [$this'GetReceipt']),
  250.             new TwigFunction('LmOptionName', [$this'GetLmOptionName']),
  251.             new TwigFunction('CatalogLimit', [$this->CatalogService'GetLimit']),
  252.             new TwigFunction('CatalogLimitMessage', [$this'CatalogLimitMessage']),
  253.             new TwigFunction('CatalogValidation', [$this->CatalogService'CatalogValidation']),
  254.             new TwigFunction('CatalogChecked', [$this'GetCatalogChecked']),
  255.             new TwigFunction('ShoppingTitle', [$this'SetShoppingTitle']),
  256.             new TwigFunction('ShoppingConfirmBtn', [$this'ShoppingConfirmBtn']),
  257.             new TwigFunction('GetCatalogViews', [$this'GetCatalogViews']),
  258.             new TwigFunction('GetSampleCatalogs', [$this->CatalogService'GetSampleCatalogs']),
  259.             new TwigFunction('CartSumImage', [$this'GetCartSumImage']),
  260.             new TwigFunction('GoodsMainImage', [$this'GetGoodsMainImage']),
  261.             new TwigFunction('CartItemPullDown', [$this'GetCartItemPullDown']),
  262.             new TwigFunction('LoadStockLabel', [$this'getStockLabel']),
  263.             new TwigFunction('CartItemSizePullDown', [$this'GetCartItemSizePullDown']),
  264.             new TwigFunction('CartItemColorPullDown', [$this'GetCartItemColorPullDown']),
  265.             new TwigFunction('lm_tax', [$this'GetLmTax']),
  266.             new TwigFunction('Caet_item_stock', [$this'GetCartItmeStock']),
  267.             new TwigFunction('CartItemSameDayShippingFlg', [$this'GetCartItemSameDayShippingFlg']),
  268.             new TwigFunction('CartItemStockNumber', [$this'GetCartItemStockNumber']),
  269.             new TwigFunction('GetConfig', [$this'GetConfig']),
  270.             new TwigFunction('GetCartNextBtnText', [$this'GetCartNextBtnText']),
  271.             new TwigFunction('GetCartBackBtnText', [$this'GetCartBackBtnText']),
  272.             new TwigFunction('GetShoppingNextBtnText', [$this'GetShoppingNextBtnText']),
  273.             new TwigFunction('GetShoppingBackBtnText', [$this'GetShoppingBackBtnText']),
  274.             new TwigFunction('GetLmOrderOption', [$this'GetLmOrderOption']),
  275.             new TwigFunction('Bank', [$this'GetBank']),
  276.             new TwigFunction('JunctionMode', [$this->CommonService'GetJunctionMode']),
  277.             new TwigFunction('CartHybridBtn', [$this'SetCartHybridBtn']),
  278.             new TwigFunction('CartHybridBtnByCartItem', [$this'ShowCartHybridBtnByCartItem']),
  279.             new TwigFunction('ShowOrderItem', [$this'SetShowOrderItem']),
  280.             new TwigFunction('ExclusionControl', [$this'SetExclusionControl']),
  281.             new TwigFunction('SetMetaTags', [$this'SetMetaTags']),
  282.             new TwigFunction('HeaderH1', [$this'SetHeaderH1']),
  283.             new TwigFunction('SetBreadCrumb', [$this'SetBreadCrumb']),
  284.             new TwigFunction('EstimateCharaCart', [$this'SetEstimateCharaCart']),
  285.             new TwigFunction('ItemType', [$this'GetItemType']),
  286.             new TwigFunction('isSliderEnabled', [$this'isSliderEnabled']),
  287.             new TwigFunction('PaymentDetails', [$this'GetPaymentDetails']),
  288.             new TwigFunction('SetEstimateOptions', [$this'SetEstimateOptions']),
  289.             new TwigFunction('SetEstimateOptionsForGroup', [$this'SetEstimateOptionsForGroup']),
  290.             new TwigFunction('ResetEstimateOptions', [$this'ResetEstimateOptions']),
  291.             new TwigFunction('GetEstimateOption', [$this'GetEstimateOption']),
  292.             new TwigFunction('ShowEstimateOptions', [$this'ShowEstimateOptions']),
  293.             new TwigFunction('ShowEstimateMobileOptions', [$this'ShowEstimateMobileOptions']),
  294.             new TwigFunction('ShowEstimateOptionsMail', [$this'ShowEstimateOptionsMail']),
  295.             new TwigFunction('ZeusCardDatas', [$this'GetZeusCardDatas']),
  296.             new TwigFunction('ZeusCardError', [$this'GetZeusCardError']),
  297.             new TwigFunction('EstimateType', [$this'GetEstimateType']),
  298.             new TwigFunction('GetCustomerBangou', [$this'GetCustomerBangou']),
  299.             new TwigFunction('NariKawariSession', [$this->AutoLoadService'GetNariKawariSession']),
  300.             new TwigFunction('NariKawariFormData', [$this->AutoLoadService'GetNariKawariFormData']),
  301.             new TwigFunction('GetCatalogNoukiSchedule', [$this'getCatalogNoukiSchedule']),
  302.             new TwigFunction('CartSortFlg', [$this'GetCartSortFlg']),
  303.             new TwigFunction('CartAddLine', [$this'GetCartAddLine']),
  304.             new TwigFunction('PageType', [$this'getPageType']),
  305.             new TwigFunction('isMobile', [$this'isMobile']),
  306.             new TwigFunction('wannaSeePc', [$this'wannaSeePc']),
  307.             new TwigFunction('CartBackBtn', [$this'GetCartBackBtn']),
  308.             new TwigFunction('WithGetParams', [$this'WithGetParams']),
  309.             new TwigFunction('PageWithGetParams', [$this'PageWithGetParams']),
  310.             new TwigFunction('ShowSendScheduleDate', [$this'showSendScheduleDate']),
  311.             new TwigFunction('ShowSendScheduleMessage', [$this'showSendScheduleMessage']),
  312.             new TwigFunction('GetCategoryImageUrlById', [$this'getCategoryImageUrlById']),
  313.             new TwigFunction('EigyoubiCalendar', [$this->CommonService'EigyoubiCalendar']),
  314.             new TwigFunction('GetOrderPaymentId', [$this'getOrderPaymentId']),
  315.             new TwigFunction('GetShippingAddr03', [$this->CustomerService'getShippingAddr03']),
  316.             new TwigFunction('GetLandMarkCustomerInfo', [$this->CustomerService'GetLandMarkCustomerId']),
  317.             new TwigFunction('CalculateTotalQuantityForOrder', [$this->CommonService'calculateTotalQuantityForOrder']),
  318.             new TwigFunction('getMessageForPayment', [$this->paymentService'getMessage']),
  319.             new TwigFunction('GetFavoriteFlashMessage', [$this->FavoriteService'getFavoriteFlashMessage']),
  320.             new TwigFunction('GetFavoriteFlashGoods', [$this->FavoriteService'getFavoriteFlashGoods']),
  321.             new TwigFunction('FileUploadNotice', [$this'showFileSizeUpload']),
  322.             new TwigFunction('GetSampleLimitError', [$this->SampleService'getSampleLimitError']),
  323.             new TwigFunction('formatDataToJson', [$this'formatDataToJson']),
  324.             new TwigFunction('getCurrentBreadcrumb', [$this'getCurrentBreadcrumb']),
  325.             new TwigFunction('getCartSessionName', [$this'getCartSessionName']),
  326.             new TwigFunction('groupItemsHasSameProductId', [$this'groupItemsHasSameProductId']),
  327.             new TwigFunction('getColorRGBCode', [$this'getColorRGBCode']),
  328.             new TwigFunction('formatDate', [$this'formatDate']),
  329.             new TwigFunction('formatSendScheduleArrivalPeriod', [$this'formatSendScheduleArrivalPeriod']),
  330.             new TwigFunction('formatMonthAndDay', [$this'formatMonthAndDay']),
  331.             new TwigFunction('formatStockArrivalDate', [$this'formatStockArrivalDate']),
  332.             new TwigFunction('getToTraceParent', function () {
  333.                 return $this->RequestStack->getCurrentRequest()->attributes->get('toTraceParent');
  334.             }),
  335.             new TwigFunction('getTrackId', function () {
  336.                 return $this->RequestStack->getCurrentRequest()->attributes->get('toTrackId');
  337.             }),
  338.             new TwigFunction('getInventoryMatrix', [$this'getInventoryMatrixData']),
  339.             new TwigFunction('shouldProcessReCaptcha', [$this->reCaptchaService'shouldProcessReCaptcha']),
  340.             new TwigFunction('showYoyakuFlag', [$this'showYoyakuFlag']),
  341.             new TwigFunction('showSokujitsuHassouBannerIfSo', [$this'showSokujitsuHassouBannerIfSo']),
  342.         ];
  343.     }
  344.     /**
  345.      * Get inventory matrix via cache
  346.      *
  347.      * @param GoodsWithRelated $goods
  348.      * @param $color
  349.      * @param $size
  350.      * @return mixed|null
  351.      * @throws \Psr\Cache\InvalidArgumentException
  352.      */
  353.     public function getInventoryMatrixData(GoodsWithRelated $goods, &$color null, &$size null)
  354.     {
  355.         $cacheKey $this->LmHelper->getCacheKey("getInventoryMatrixData", [$goods$color$size]);
  356.         $id $goods->getGoodsId();
  357.         $stock $this->GoodsService->getGoodsStock($id1); // value of stock is not should cache
  358.         return $this->getCacheByKey($cacheKey, function () use ($goods$color$size$stock$id) {
  359.             // JAN情報(=product_class id)
  360.             list($jan$janColor) = $this->productConverter->getGoodsJanById($id);
  361.             // 色情報
  362.             $color $this->GoodsService->getGoodsColorSelectSql($id);
  363.             // サイズ情報
  364.             $size $this->GoodsService->getGoodsSizeListById($id);
  365.             // 商品即日情報
  366.             $sokujitsu $this->GoodsService->getGoodsSameDayShipping($id1);
  367.             // 商品在庫情報
  368.             // 商品予約情報
  369.             $yoyaku $this->GoodsService->getGoodsReservation($id1);
  370.             // 商品入荷予定日情報
  371.             $yoteibi $this->GoodsService->getGoodsStockDate($id1);
  372.             // カートマトリックス用のデータ生成
  373.             $matrixData = [];
  374.             $matrixData_cnt = [];
  375.             $line 0;
  376.             $sizeMax = ($this->LmMobileDetector->isMobile() ? 999 8);
  377.             $max 0;
  378.             foreach ($color as $v1) {
  379.                 $line++;
  380.                 $line2 0;
  381.                 $no 1;
  382.                 foreach ($size as $v2) {
  383.                     if ($line2 % ($sizeMax) === 0) {
  384.                         $no++;
  385.                     } else {
  386.                         $max $line2 % ($sizeMax);
  387.                     }
  388.                     $tmpYoteibi NULL;
  389.                     if (!empty($yoteibi[$v1["gcl_id"]][$v2["gp_id"]]) and $sokujitsu[$v1["gcl_id"]][$v2["gp_id"]] <= SokujitsuHassou::FLG_NONE) {
  390.                         $tmpYoteibi date("n月j日"strtotime($yoteibi[$v1["gcl_id"]][$v2["gp_id"]]));
  391.                     }
  392.                     $matrixData_cnt[$no] = $max;
  393.                     $matrixData[$no][$line][$line2] = [
  394.                         'line' => $line,
  395.                         'product_id' => $jan[$v1["gcl_id"]][$v2["gp_id"]],
  396.                         'shiire_color' => $janColor[$v1["gcl_id"]][$v2["gp_id"]],
  397.                         'color' => $v1,
  398.                         'size' => $v2,
  399.                         'stock' => $stock[$v1["gcl_id"]][$v2["gp_id"]],
  400.                         'yoyaku' => $yoyaku[$v1["gcl_id"]][$v2["gp_id"]],
  401.                         'yoteibi' => $tmpYoteibi,
  402.                         'sokujitsu' => $sokujitsu[$v1["gcl_id"]][$v2["gp_id"]],
  403.                     ];
  404.                     $line2++;
  405.                 }
  406.             }
  407.             return $matrixData;
  408.         });
  409.     }
  410.     public function getFilters()
  411.     {
  412.         return [
  413.             new TwigFilter('Base', [$this'BaseInfo']),
  414.             new TwigFilter('LmPrice', [$this'GetLmPrice']),
  415.             new TwigFilter('FormatPrice', [$this'FormatPrice']),
  416.             new TwigFilter('phone', [$this'SetPhone']),
  417.             new TwigFilter('post', [$this'SetPost']),
  418.             new TwigFilter('jweek', [$this'SetJWeek']),
  419.             new TwigFilter('AjaxPrice', [$this->GoodsPriceService'embedGoodsPrice']),
  420.             new TwigFilter('OrderId', [$this->LmHelper'convertOrderToOrderId']),
  421.             new TwigFilter('InventoryMatrix', [$this'showInventoryMatrix']),
  422.             new TwigFilter('LmWebTeika', [$this'filterLmWebTeika']),
  423.             new TwigFilter('LmWebPrice', [$this'filterLmWebPrice']),
  424.         ];
  425.     }
  426.     public function getTests()
  427.     {
  428.         return [
  429.             new TwigTest('numeric''is_numeric'),
  430.         ];
  431.     }
  432.     /**
  433.      * Master Job をゲットする
  434.      *
  435.      * @return obj Job
  436.      */
  437.     public function GetPrefs()
  438.     {
  439.         return $this->PrefRepository->finsBy([], ['sort_no' => 'asc']);
  440.     }
  441.     public function GetJob()
  442.     {
  443.         return $this->JobRepository->findBy([], ['sort_no' => 'asc']);
  444.     }
  445.     /**
  446.      * TWIG に LMカートタイプを返す
  447.      *   cart_type:
  448.      * 1 -- 購入(加工なし)
  449.      * 2 -- 購入(加工あり(加工なしとの混在含む))
  450.      * 3 -- 貸出サンプル
  451.      * 4 -- カタログ請求
  452.      */
  453.     public function GetLmCartType()
  454.     {
  455.         return $this->LmHelper->getCartType();
  456.     }
  457.     /**
  458.      * 初回ログイン
  459.      *
  460.      */
  461.     public function GetFirstLogin()
  462.     {
  463.         $Flg $this->CustomerService->GetFirstLoginFlg();
  464.         $this->CustomerService->SetFirstLoginFlg(null);
  465.         return $Flg;
  466.     }
  467.     public function GetLmCuatomer($Eail)
  468.     {
  469.         if (!$Lmcustomer $this->CustomerService->GetLandMarkCustomerEmail($Eail)) {
  470.             $Columns $this->CommonService->GetYaml('LmCustomer.yaml');
  471.             foreach ($Columns as $Column) {
  472.                 switch ($Column) {
  473.                     case 'address03':
  474.                         $Lmcustomer['customer_address3'] = '';
  475.                         break;
  476.                     case 'fax_number':
  477.                         $Lmcustomer['customer_fax'] = '';
  478.                         break;
  479.                     default:
  480.                         $Lmcustomer[$Column] = '';
  481.                         break;
  482.                 }
  483.             }
  484.         };
  485.         return $Lmcustomer;
  486.     }
  487.     /**
  488.      * アマゾンログイン
  489.      *
  490.      */
  491.     public function GetAmazonLogin()
  492.     {
  493.         return $this->CustomerService->GetAmazonLoginFlg();
  494.     }
  495.     /**
  496.      *  LMプライバシーポリシーの取得
  497.      *
  498.      * @return string admin_privacy3
  499.      */
  500.     public function GetPrivacy3()
  501.     {
  502.         $Sql = new SqlService;
  503.         $Data $Sql->Table('admin_table')
  504.             ->Find();
  505.         return $Data['admin_privacy3'] ?? '';
  506.     }
  507.     /**
  508.      * オリジナルトークンを返す
  509.      * @param string $Cd
  510.      * @param string $name 'token'
  511.      *
  512.      * @return string $Token
  513.      */
  514.     public function GetOlToken($Cd$Name 'token')
  515.     {
  516.         return $this->CommonService->ResetToken($Cd$Name);
  517.     }
  518.     /**
  519.      * クーポンの値引き時 リダイレクト先URIを返す
  520.      *
  521.      */
  522.     public function GetRequestUri()
  523.     {
  524.         return $this->Request->server->get('REQUEST_URI');
  525.     }
  526.     /**
  527.      * クーポンのData
  528.      *
  529.      */
  530.     public function GetCouponData()
  531.     {
  532.         return $this->CommonService->GetLmOrderOption(CommonService::Lm_Option_Coupon);
  533.     }
  534.     /**
  535.      * 領収書
  536.      *
  537.      */
  538.     public function SetReceipt($CompanyName$Name$Write)
  539.     {
  540.         $Receipt $this->CommonService->GetLmOrderOption(CommonService::Lm_Option_Receipt);
  541.         $Re $Receipt;
  542.         $Re['flg'] = [''''];
  543.         if (!$Receipt) {
  544.             $Re['name'] = $CompanyName $CompanyName $Name;
  545.             $Re['flg'][0] = 'checked="checked"';
  546.             $Re['write'] = $Write;
  547.             $Re['comment'] = '';
  548.         } else {
  549.             $Re['flg'][$Receipt['flg']] = 'checked="checked"';
  550.         }
  551.         return $Re;
  552.     }
  553.     public function GetReceipt()
  554.     {
  555.         if (!$Receipt $this->CommonService->GetLmOrderOption(CommonService::Lm_Option_Receipt)) {
  556.             return false;
  557.         }
  558.         return $Receipt['flg'] == false $Receipt;
  559.     }
  560.     public function GetLmOptionName($Name null)
  561.     {
  562.         switch ($Name) {
  563.             case 'catalog':
  564.                 $Re CommonService::Lm_Option_Catalog;
  565.                 break;
  566.             case 'receipt';
  567.             default:
  568.                 $Re CommonService::Lm_Option_Receipt;
  569.                 break;
  570.         }
  571.         return $Re;
  572.     }
  573.     /**
  574.      * LMOrderPption 初期化
  575.      *
  576.      */
  577.     public function SetInitiarizeLmOrederOption($OrderId)
  578.     {
  579.         $this->CommonService->SetInitiarizeLmOrederOption($OrderId);
  580.     }
  581.     public function SetShoppingTitle($Message$Num)
  582.     {
  583.         $Message trans($Message);
  584.         if (is_null($Num)) {
  585.             return $Message;
  586.         }
  587.         return $this->LmHelper->getCartType() <= CartService::CartTypeEstimate $Num '.' $Message $Message;
  588.     }
  589.     /**
  590.      * 確認気年のボタン
  591.      *
  592.      * @return string
  593.      */
  594.     public function ShoppingConfirmBtn()
  595.     {
  596.         $Message 'front.shopping.checkout';
  597.         switch ($this->LmHelper->getCartType()) {
  598.             case CartService::CartTypeCatalog:
  599.                 $Message 'front.Shopping_Button04';
  600.                 break;
  601.             case CartService::CartTypeNormal:
  602.             default:
  603.                 break;
  604.         }
  605.         return $Message;
  606.     }
  607.     public function GetCatalogChecked($Id$Name null)
  608.     {
  609.         $Checked = ['''checked="checked"'];
  610.         if ('Open' == $Name) {
  611.             $OpenCtalog $this->CommonService->GetLmOrderOption('OpenCatalog');
  612.             if (is_null($OpenCtalog) && $Id == 0) {
  613.                 return $Checked[1];
  614.             }
  615.             return $Id == $OpenCtalog $Checked[1] : $Checked[0];
  616.         }
  617.         if (!$this->CatalogValue) {
  618.             if ($Value $this->CommonService->GetLmOrderOption(CommonService::Lm_Option_Catalog)) {
  619.                 $this->CatalogValue array_flip($Value);
  620.             }
  621.         }
  622.         if (isset($this->CatalogValue[$Id])) {
  623.             return $Checked[1];
  624.         }
  625.         return $Checked[0];
  626.     }
  627.     public function GetLmOrderOption($name)
  628.     {
  629.         return $this->CommonService->GetLmOrderOption($name);
  630.     }
  631.     /**
  632.      * LMOrderPption クーポン
  633.      * ショッピング 表示
  634.      *
  635.      * @return string $name
  636.      */
  637.     public function SetDiscountName()
  638.     {
  639.         return $this->CommonService->GetLmOrderOption(CommonService::Lm_Option_Coupon) ? 'クーポン' trans('common.discount');
  640.     }
  641.     /**
  642.      * カタログの札数メッセージ
  643.      *
  644.      * @param int num
  645.      *
  646.      * @return string メッセージ
  647.      */
  648.     public function CatalogLimitMessage($Num)
  649.     {
  650.         return str_replace('@@'$Numtrans('front.cart_catalog.message09'));
  651.     }
  652.     public function CatalogValidation()
  653.     {
  654.         if (CartService::CartTypeCatalog != $this->CartService->getCartType()) {
  655.             return false;
  656.         }
  657.         return $this->CatalogService->CatalogValidation();
  658.     }
  659.     public function GetCatalogViews()
  660.     {
  661.         return $this->CatalogService->GetView();
  662.     }
  663.     /**
  664.      * カートにて サムネイルのURLを生成する
  665.      *
  666.      */
  667.     public function GetCartSumImage($ProductId)
  668.     {
  669.         $Dir substr($ProductId, -1);
  670.         return "/goods.img/{$Dir}/{$ProductId}/main_sum.jpg";
  671.     }
  672.     /**
  673.      * カートにて サムネイルのURLを生成する
  674.      *
  675.      */
  676.     public function GetGoodsMainImage($ProductId)
  677.     {
  678.         $Dir substr($ProductId, -1);
  679.         return "/goods.img/{$Dir}/{$ProductId}/main.jpg";
  680.     }
  681.     /**
  682.      * LMの価格に対して 税込価格を返す
  683.      *
  684.      */
  685.     public function GetLmTax($ProductClassId)
  686.     {
  687.         $ProductClass $this->ProductClassRepository->find($ProductClassId);
  688.         return $ProductClass->getPrice02IncTax();
  689.     }
  690.     /**
  691.      * LM在庫数を返す
  692.      *
  693.      * 0 ・・・ 在庫なし
  694.      * 1以上 ・・・ 在庫あり
  695.      * # null ・・・ 99(入荷予定)
  696.      * #  *   ・・・ 999
  697.      *`@param int ClassId
  698.      *
  699.      * @return string 在庫数
  700.      */
  701.     public function GetCartItmeStock($ProductClass)
  702.     {
  703.         $ClassId $ProductClass->getId();
  704.         $Stock $this->GoodsService->getValidationStock($ClassId);
  705.         $Re '';
  706.         switch (true) {
  707.             case is_null($Stock):
  708.                 $Re trans('front.cart_item.title10');
  709.                 break;
  710.             case $Stock == 0:
  711.                 $Re trans('front.cart_item.title11');;
  712.                 break;
  713.             default:
  714.                 $Text $this->CommonService->GetConfig('ESTIMATE_TEXT');
  715.                 $Re $Text['Text23'] . number_format($Stock) . $Text['Text04'];
  716.                 break;
  717.         }
  718.         return $Re;
  719.     }
  720.     public function GetCartItemSameDayShippingFlg($ProductClass$quantity null)
  721.     {
  722.         if ($ProductClass) {
  723.             $result $this->GoodsService->getGoodsSameDayShipping($ProductClass->getProduct()->getId(), 0$ProductClass->getId(), nullnull$quantity);
  724.             return $result;
  725.         }
  726.         return false;
  727.     }
  728.     public function GetCartItemStockNumber($productClass$sameShippingFlg)
  729.     {
  730.         $stock $this->GoodsService->getGoodsStock(nullfalse$productClass->getId());
  731.         if ($sameShippingFlg SokujitsuHassou::FLG_NONE) {
  732.             return $stock['stock_sokujitsu'];
  733.         } else {
  734.             return $stock['stock_total'];
  735.         }
  736.     }
  737.     public function GetCartNextBtnText()
  738.     {
  739.         switch ($this->GetLmCartType()) {
  740.             case CartService::CartTypeSample:
  741.                 return 'サンプル申込の手続きへ';
  742.             case CartService::CartTypeNormal:
  743.             case CartService::CartTypeEstimate:
  744.             default:
  745.                 return '次へ(レジへ進む)';
  746.         }
  747.     }
  748.     public function GetCartBackBtnText()
  749.     {
  750.         switch ($this->GetLmCartType()) {
  751.             case CartService::CartTypeSample:
  752.                 return '他にもサンプル申込商品を選ぶ';
  753.             case CartService::CartTypeNormal:
  754.             case CartService::CartTypeEstimate:
  755.             default:
  756.                 return '買い物を続ける';
  757.         }
  758.     }
  759.     public function GetShoppingNextBtnText()
  760.     {
  761.         switch ($this->GetLmCartType()) {
  762.             case CartService::CartTypeSample:
  763.                 return '同意して次へ';
  764.             case CartService::CartTypeCatalog:
  765.                 return '送信する';
  766.             case CartService::CartTypeNormal:
  767.             case CartService::CartTypeEstimate:
  768.             default:
  769.                 return '確認画面に進む';
  770.         }
  771.     }
  772.     public function GetShoppingBackBtnText()
  773.     {
  774.         switch ($this->GetLmCartType()) {
  775.             case CartService::CartTypeCatalog:
  776.                 return '入力画面に戻る';
  777.             case CartService::CartTypeNormal:
  778.             case CartService::CartTypeEstimate:
  779.             case CartService::CartTypeSample:
  780.             default:
  781.                 return 'カートに戻る';
  782.         }
  783.     }
  784.     public function GetConfig($key)
  785.     {
  786.         return $this->LmHelper->getConfig($key);
  787.     }
  788.     public function getColorRGBCode($productId)
  789.     {
  790.         $colors = [];
  791.         $goodColors $this->GoodsService->getGoodsColorSelectSql($productId);
  792.         if (is_array($goodColors) && count($goodColors) > 0) {
  793.             foreach ($goodColors as $goodColor) {
  794.                 if (!$goodColor['color_name']) {
  795.                     continue;
  796.                 }
  797.                 $id $this->LmHelper->convGclIdToClassCategory1Id($goodColor['gcl_id']);
  798.                 $colors[$id] = $goodColor['color_rgb'];
  799.             }
  800.         }
  801.         return $colors;
  802.     }
  803.     public function GetCartItemColorPullDown($ItemId$ProductId$classCategory1Id$EstimateId$EmptyOptionAsFirst false$isAjaxCart false$classCategory2Id null)
  804.     {
  805.         //
  806.         $Type 'color';
  807.         //
  808.         $Data = [];
  809.         $Value null;
  810.         $Id 0;
  811.         //
  812.         $kbn 1;
  813.         if ($classCategory1Id) {
  814.             $ClassCategory1 $this->ClassCategoryRepository->find($classCategory1Id);
  815.             $Value $ClassCategory1->getId();
  816.             $ClassName $ClassCategory1->getClassName();
  817.             $kbn $ClassName->getId();
  818.         }
  819.         foreach ($this->GoodsService->getGoodsColorSelectSql($ProductId) as $Val) {
  820.             if (!$Val['color_name']) {
  821.                 continue;
  822.             }
  823.             $Id $this->LmHelper->convGclIdToClassCategory1Id($Val['gcl_id']);
  824.             $Selected = !$EmptyOptionAsFirst && $Value == $Id 'selected="selected"' '';
  825.             $Rgb 'data-rgb=#' $Val['color_rgb'];
  826.             $disabled '';
  827.             if($isAjaxCart && $classCategory2Id){
  828.                 $estId =  $classCategory2Id;
  829.                 $estId $this->LmHelper->convClassCategory2IdToGpIdRe($estId);
  830.                 try {
  831.                     $result = (new SqlService())
  832.                         ->Select('*')
  833.                         ->Table('jancode_table')
  834.                         ->Set('jan_color'$Val['gcl_id'])
  835.                         ->Set('jan_price'$estId)
  836.                         ->Find();
  837.                     if($result){
  838.                         if((is_null($result['jan_stock']) || $result['jan_stock'] > )){
  839.                             $disabled '';
  840.                         }else if((isset($result['jan_stock3']) && $result['jan_stock3'] > )){
  841.                             $disabled '';
  842.                         }else if((isset($result['jan_stock4']) && $result['jan_stock4'] > )){
  843.                             $disabled '';
  844.                         }else{
  845.                             $disabled 'disabled';
  846.                         }
  847.                     }else {
  848.                         $disabled '';
  849.                     }
  850.                 } catch (\Throwable $th) {
  851.                     $disabled '';
  852.                 }
  853.             }
  854.             $name = ($disabled == 'disabled') ? $Val['color_name'] . ' - 在庫切れ' $Val['color_name'];
  855.             $Data[$Id] = [
  856.                 'name' => $name,
  857.                 'Selected' => $Selected,
  858.                 'disabled' => $disabled,
  859.                 'Data' => $Rgb
  860.             ];
  861.         };
  862.         //
  863.         return $this->GetCartItemPullDown($ItemId$ProductId$Type$Data$Value$EstimateId$EmptyOptionAsFirst);
  864.     }
  865.     public function GetCartItemSizePullDown($ItemId$ProductId$classCategory2Id$classCategory1Id$EstimateId$EmptyOptionAsFirst false)
  866.     {
  867.         //
  868.         $Type 'size';
  869.         //
  870.         $Data = [];
  871.         $Value null;
  872.         $Id 0;
  873.         //
  874.         $kbn 2;
  875.         if ($classCategory2Id) {
  876.             $ClassCategory2 $this->ClassCategoryRepository->find($classCategory2Id);
  877.             $Value $ClassCategory2->getId();
  878.             $ClassName $ClassCategory2->getClassName();
  879.             $kbn $ClassName->getId();
  880.         }
  881.         if ($classCategory1Id) {
  882.             //
  883.             $ClassCategory1 $this->ClassCategoryRepository->find($classCategory1Id);
  884.             $sizeList $this->GoodsService->getGoodsSizeListWithStockInfoByClassCategory1($ClassCategory1);
  885.         } else {
  886.             $sizeList $this->GoodsService->getGoodsSizeListById($ProductId);
  887.         }
  888.         foreach ($sizeList as $Val) {
  889.             if (!$Val['size_name']) {
  890.                 continue;
  891.             }
  892.             $Id $this->LmHelper->convGpIdToClassCategory2Id($Val['gp_id']);
  893.             $Selected = !$EmptyOptionAsFirst && $Value == $Id 'selected="selected"' '';
  894.             $disabled = (isset($Val['disabled']) && $Val['disabled'] === 1) ? 'disabled' '';
  895.             $Data[$Id] = [
  896.                 'name' => $Val['size_name'],
  897.                 'Selected' => $Selected,
  898.                 'disabled' => $disabled,
  899.                 'Data' => ''
  900.             ];
  901.         };
  902.         //
  903.         return $this->GetCartItemPullDown($ItemId$ProductId$Type$Data$Value$EstimateId$EmptyOptionAsFirst);
  904.     }
  905.     public function GetCartItemPullDown($ItemId$ProductId$Type$ItemDatas$Value$EstimateId$EmptyOptionAsFirst false)
  906.     {
  907.         //
  908.         $Re = [
  909.             'ItemId' => $ItemId,
  910.             'ProductId' => $ProductId,
  911.             'Type' => $Type,
  912.             'ItemDatas' => $ItemDatas,
  913.             'Value' => $Value,
  914.             'EstimateId' => $EstimateId,
  915.             'EmptyOptionAsFirst' => $EmptyOptionAsFirst
  916.         ];
  917.         //
  918.         return $this->Twig->render('Cart/Parts/PullDown.twig'$Re);
  919.     }
  920.     public function getStockLabel($ProductId$ClassCategory1Id$ClassCategory2Id)
  921.     {
  922.         //
  923.         $context = [
  924.             'ProductClass' => $this->ProductClassRepository->findOneBy([
  925.                 'Product' => $ProductId,
  926.                 'ClassCategory1' => $ClassCategory1Id,
  927.                 'ClassCategory2' => $ClassCategory2Id,
  928.             ]),
  929.         ];
  930.         //
  931.         return $this->Twig->render('Cart/Parts/StockLabel.twig'$context);
  932.     }
  933.     public function GetBank($Name$Bancode '')
  934.     {
  935.         if (!$this->Bank) {
  936.             $Banks $this->CommonService->GetYaml('Bank.yaml');
  937.             if ($Bancode) {
  938.                 $this->Bank $Banks[1];
  939.                 $this->Bank['account'] = $Bancode;
  940.             } else {
  941.                 $this->Bank $Banks[0];
  942.             }
  943.         }
  944.         return $this->Bank[$Name];
  945.     }
  946.     /**
  947.      * ハイブリッドボタンの設置
  948.      * 1 サンプルは出力しない
  949.      * 2 加工できない商品は出力しない
  950.      * 3 分割対応  2022/10/20
  951.      */
  952.     public function SetCartHybridBtn($ProductId$EstimateId$ItemId$btnName null)
  953.     {
  954.         #1
  955.         if ($this->CartService->getCartType() >= CartService::CartTypeSample) {
  956.             return;
  957.         }
  958.         #2
  959.         if (!$Type GoodsService::getEnableEstimateTypeById($ProductId)) {
  960.             return;
  961.         }
  962.         #3
  963.         if (CartService::CartTypeEstimate == $this->CartService->GetCartType() &&
  964.             $this->CommonService->GetConfig('BunkaruFlg') == false) {
  965.             $this->EstimateType $this->EstimateType ?? $this->CartService->GetEstimateType();
  966.         }
  967.         if (is_numeric($ItemId)) {
  968.             $Itemids $ItemId;
  969.         } else {
  970.             $Ids = [];
  971.             foreach ($ItemId as $Item) {
  972.                 if ($Item->getEstimateId() != $EstimateId) {
  973.                     continue;
  974.                 }
  975.                 $productItemId $Item->getProductClass()->getProduct()->getId();
  976.                 if (!GoodsService::getEnableEstimateTypeById($productItemId)) {
  977.                     continue;
  978.                 }
  979.                 $Ids[] = $Item->getId();
  980.             }
  981.             $Itemids implode(','$Ids);
  982.         }
  983.         $Re = [
  984.             'ItemIds' => $Itemids,
  985.             'Name' => $btnName ?? trans('front.cart_item_button04_' $Type),
  986.             'EstimateId' => $EstimateId,
  987.             'Type' => $ProductId,
  988.         ];
  989.         return $this->Twig->render('Cart/Parts/CartHybridBtn.twig'$Re);
  990.     }
  991.     /**
  992.      * @param CartItem $CartItem
  993.      * @return string
  994.      */
  995.     public function ShowCartHybridBtnByCartItem(CartItem $CartItem)
  996.     {
  997.         //
  998.         $ProductId $CartItem->getProductClass()->getProduct()->getId();
  999.         $EstimateId $CartItem->getEstimateId();
  1000.         // TODO: 旧・セット品番への対応
  1001.         // // $ItemId = array_filter(is_array($CartItems = $CartItem->getCart()->getCartItems()) ? $CartItems : $CartItems->toArray(), function ($CartItem) {
  1002.         // //     /**
  1003.         // //      * @var CartItem $CartItem
  1004.         // //      */
  1005.         // //     return !$this->CartService->isProductNoOptions($CartItem->getProductClass()->getProduct()->getId());
  1006.         // // });
  1007.         $ItemId $CartItem->getCart()->getCartItems();
  1008.         $btnName $CartItem->isSusoage() ? '裾上げ内容の変更' '加工内容の変更';
  1009.         //
  1010.         return $this->SetCartHybridBtn($ProductId$EstimateId$ItemId$btnName);
  1011.     }
  1012.     public function SetShowOrderItem($Order$Type)
  1013.     {
  1014.         $Item null;
  1015.         foreach ($Order->getOrderItems() as $OrderItem) {
  1016.             $OrderItemType $OrderItem->getOrderItemType();
  1017.             if ($Type == $OrderItemType->getId()) {
  1018.                 $Item $OrderItem;
  1019.             }
  1020.         };
  1021.         if (!$Item) {
  1022.             return '';
  1023.         }
  1024.         $Re = [
  1025.             'Item' => $Item,
  1026.             'Type' => $Item->getOrderItemType(),
  1027.         ];
  1028.         return $this->Twig->render('Shopping/Parts/OrderItem.twig'$Re);
  1029.     }
  1030.     /**
  1031.      * カート排他制御
  1032.      *
  1033.      */
  1034.     public function SetExclusionControl()
  1035.     {
  1036.         $Type '';
  1037.         if (!$Type $this->Session->get(CartService::Session_ExclusionControlFlg)) {
  1038.             return;
  1039.         };
  1040.         #2022/10/22 リピート注文特殊処理 Cartエラーで返せない
  1041.         switch ($Type) {
  1042.             case CartService::RepeatError01:
  1043.                 $Messages[] = trans('front.Cart.Repeat_message01');
  1044.                 break;
  1045.             case CartService::RepeatError02:
  1046.                 $Messages[] = trans('front.ExclusionControl.message04');
  1047.                 break;
  1048.             case CartService::RepeatError03:
  1049.                 $Messages[] = trans('front.ExclusionControl.message05');
  1050.                 break;
  1051.             default:
  1052.                 for ($i 1$i <= 2$i++) {
  1053.                     $Messages[] = $this->CommonService->SetExclusionControl($Type$i);
  1054.                 }
  1055.                 break;
  1056.         }
  1057.         $this->Session->set(CartService::Session_ExclusionControlFlgnull);
  1058.         return $this->Twig->render(self::ExclusionTwig,
  1059.             [
  1060.                 'Messages' => $Messages,
  1061.             ]);
  1062.     }
  1063.     public function SetMetaTags($Datas)
  1064.     {
  1065.         $Key array_key_first($Datas);
  1066.         $Data $Datas[$Key] ?? null;
  1067.         switch (true) {
  1068.             case $Key === 'item':
  1069.                 $this->MetaTagService->SetItem($Datas[$Key]);
  1070.                 $Image $this->LmHelper->getGoodsImageUrl($Data['goods_id'], 'main.jpg');
  1071.                 $this->MetaTagService->SetOpgs(4$Image);
  1072.                 break;
  1073.             case $Key === 'SubCategory':
  1074.             case $Key === 'Category':
  1075.                 $this->MetaTagService->SetCategory($Datas[$Key]);
  1076.                 $this->MetaTagService->SetOpgs();
  1077.                 break;
  1078.             case $Key === 'message':
  1079.                 $this->MetaTagService->SetMessage($Datas[$Key]);
  1080.                 $this->MetaTagService->SetOpgs();
  1081.                 break;
  1082.             case $Key === 'review':
  1083.                 $this->MetaTagService->SetReview($Datas[$Key]);
  1084.                 $this->MetaTagService->SetOpgs(4);
  1085.                 break;
  1086.             case $Key === 0:
  1087.                 $this->MetaTagService->SetMetaTags($Data); //
  1088.                 break;
  1089.             default:
  1090.                 $this->MetaTagService->SetMetaPages(); //
  1091.                 break;
  1092.         }
  1093.         return $this->Twig->render(self::MetatagTwig, [
  1094.             'Title' => $this->MetaTagService->GetTitle(),
  1095.             'MetaTags' => $this->MetaTagService->GetMetaTags(),
  1096.             'Opgs' => $this->MetaTagService->GetOpgs(),
  1097.             'UrlName' => $this->Request->get('_route'),
  1098.         ]);
  1099.     }
  1100.     public function SetHeaderH1()
  1101.     {
  1102.         return $this->MetaTagService->GetHeaderH1();
  1103.     }
  1104.     /**
  1105.      * パンクズを一括管理する
  1106.      * @param $BreadCrumbs  string | array none 非表示
  1107.      * 1 第一因子を TOPページとする 固定
  1108.      * 2 BreadCrumbsのKEYを1にすると 最後に ページ名を追加します
  1109.      * 3 配列の内容は、KEYが href' 'label' になります
  1110.      */
  1111.     public function SetBreadCrumb($BreadCrumbs)
  1112.     {
  1113.         $Type $BreadCrumbs[0] ?? null;
  1114.         if (!is_array($Type) && $Type == 'none') {
  1115.             return;
  1116.         }
  1117.         $this->getBreadCrumb('homepage');
  1118.         $Re[] = $this->getBreadCrumb('homepage');
  1119.         #第一因子 (0)
  1120.         $UrlName $this->Request->get('_route');
  1121.         if (count($BreadCrumbs) > 0) {
  1122.             foreach ($BreadCrumbs as $Key => $BreadCrumb) {
  1123.                 $BC['label'] = $BreadCrumb['label'] ?? '';
  1124.                 $BC['href'] = $BreadCrumb['href'] ?? '';
  1125.                 switch (array_key_first($BreadCrumbs)) {
  1126.                     case 1:
  1127.                         $Re[] = $BC;
  1128.                         $Re[] = $this->getBreadCrumb($UrlName);
  1129.                         break;
  1130.                     default:
  1131.                         $Re[] = $BC;
  1132.                 }
  1133.             }
  1134.         } else {
  1135.             $Re[] = $this->getBreadCrumb($UrlName);
  1136.         }
  1137.         return $this->Twig->render(self::BreadCrumTwig, [
  1138.             'BreadCrumbs' => $Re,
  1139.         ]);
  1140.     }
  1141.     protected function getBreadCrumb($UrlName)
  1142.     {
  1143.         $Name $this->CommonService->GetPagename($UrlName);
  1144.         switch ($UrlName) {
  1145.             case 'cart':
  1146.                 if ($this->LmHelper->getCartType() == 4) {
  1147.                     $MetaTags $this->CommonService->GetYaml(CommonService::MetaTagData);
  1148.                     $Name $MetaTags['catalog']['PageName'];
  1149.                 }
  1150.                 break;
  1151.             case 'shopping_login':
  1152.                 $Name "ログイン";
  1153.                 break;
  1154.             default:
  1155.                 break;
  1156.         }
  1157.         try {
  1158.             return [
  1159.                 'href' => $this->Router->generate($UrlName) ?? '',
  1160.                 'label' => $this->LmHelper->display_text($Name)
  1161.             ];
  1162.         } catch (\Throwable $e) {
  1163.             return $this->getBreadCrumb('homepage');
  1164.         } catch (\Exception $e) {
  1165.             return $this->getBreadCrumb('homepage');
  1166.         }
  1167.     }
  1168.     public function getCurrentBreadcrumb()
  1169.     {
  1170.         $Re[] = $this->getBreadCrumb('homepage');
  1171.         $UrlName $this->Request->get('_route');
  1172.         $Re[] = $this->getBreadCrumb($UrlName);
  1173.         return $Re;
  1174.     }
  1175.     /**
  1176.      * 見積もりシミュレーション文字化
  1177.      *
  1178.      */
  1179.     public function SetEstimateCharaCart($CartKey$EstimateId$Options$isDisplayOnSp false)
  1180.     {
  1181.         if (!$Option $Options[$CartKey][$EstimateId] ?? null) {
  1182.             return;
  1183.         }
  1184.         if ($isDisplayOnSp) {
  1185.             return $this->Twig->render('Common/EstimateMobile.twig', [
  1186.                 'Prints' => $Option['print'] ?? [],
  1187.                 'Susoage' => $Option['susoage'] ?? '',
  1188.                 'Lot' => $Option['lot'] ?? null,
  1189.             ]);
  1190.         }
  1191.         return $this->Twig->render(self::EstimateTwig, [
  1192.             'Prints' => $Option['print'] ?? [],
  1193.             'Susoage' => $Option['susoage'] ?? '',
  1194.             'Lot' => $Option['lot'] ?? null,
  1195.         ]);
  1196.     }
  1197.     public function GetItemType($Id$Flg null)
  1198.     {
  1199.         $ItemType $this->OrderItemTypeRepository->find($Id);
  1200.         return $ItemType->getName();
  1201.     }
  1202.     public function GetPaymentDetails($Param$Items)
  1203.     {
  1204.         foreach ($Items as $Item) {
  1205.             $Type $Item->getOrderItemTypeId();
  1206.             if ($Type == $Param) {
  1207.                 return $Item->getPrice();
  1208.             }
  1209.         }
  1210.         return null;
  1211.     }
  1212.     /**
  1213.      * Reset AllOrderItems for proper setLots calculation
  1214.      * @return void
  1215.      */
  1216.     public function ResetEstimateOptions()
  1217.     {
  1218.         $this->AllOrderItems = [];
  1219.         $this->EstimateOptionsByEstimateId = [];
  1220.     }
  1221.     /**
  1222.      * @param OrderItem[] $Items
  1223.      * @return void
  1224.      */
  1225.     public function SetEstimateOptions($Items)
  1226.     {
  1227.         foreach ($Items as $Item) {
  1228.             $this->AllOrderItems[] = $Item;
  1229.         }
  1230.         
  1231.         $this->EstimateOptions = [];
  1232.         $this->ItemIdToEstimateId = [];
  1233.         $EstimetIds = [];
  1234.         $Options = [];
  1235.         $I null;
  1236.         $Num 1;
  1237.         $ItemCount 0;
  1238.         foreach ($Items as $Item) {
  1239.             $ProductClass $Item->getProductClass();
  1240.             $Product $ProductClass->getProduct();
  1241.             $EstimetIds[$Product->getId()][$Item->getEstimateId()] = $Item->getId();
  1242.             $Options[$Item->getId()] = $Item->getOptions();
  1243.             $this->ItemIdToEstimateId[$Item->getId()] = is_object($Item->getEstimateId()) ? (int) (string) $Item->getEstimateId() : (int) $Item->getEstimateId();
  1244.             $L $Product->getId() . '-' $Item->getEstimateId();
  1245.             if ($I != $L) {
  1246.                 $this->CartSortFlg[$Product->getId()][$Item->getEstimateId()]['h'] = $Item->getId();
  1247.                 $this->CartSortFlg[$Product->getId()][$Item->getEstimateId()]['n'] = $Num;
  1248.                 $Num++;
  1249.                 $ItemCount 0;
  1250.             }
  1251.             $I $L;
  1252.             $ItemCount++;
  1253.             $this->CartSortFlg[$Product->getId()][$Item->getEstimateId()]['f'] = $Item->getId();
  1254.             $this->CartSortFlg[$Product->getId()][$Item->getEstimateId()]['ItemCount'] = $ItemCount;
  1255.         }
  1256.         foreach ($EstimetIds as $ProductId) {
  1257.             foreach ($ProductId as $Id) {
  1258.                 $this->EstimateOptions[$Id] = $Options[$Id];
  1259.             }
  1260.         }
  1261.         // Always recalculate EstimateOptionsByEstimateId to ensure proper setLots calculation
  1262.         // This ensures all items are considered together for lot calculation
  1263.         list($total$optionsByEstimateId) = $this->EstimateCharacterizer->SetEstimateOption($this->AllOrderItems, [], 'shopping');
  1264.         $this->EstimateOptionsByEstimateId $optionsByEstimateId;
  1265.     }
  1266.     /**
  1267.      * Set estimate options for a specific group of items (for split orders)
  1268.      * This calculates estimates separately for each group without affecting other groups
  1269.      * 
  1270.      * @param OrderItem[] $Items
  1271.      * @return void
  1272.      */
  1273.     public function SetEstimateOptionsForGroup($Items)
  1274.     {
  1275.         $EstimetIds = [];
  1276.         $Options = [];
  1277.         $I null;
  1278.         $Num 1;
  1279.         $ItemCount 0;
  1280.         
  1281.         foreach ($Items as $Item) {
  1282.             $ProductClass $Item->getProductClass();
  1283.             $Product $ProductClass->getProduct();
  1284.             $EstimetIds[$Product->getId()][$Item->getEstimateId()] = $Item->getId();
  1285.             $Options[$Item->getId()] = $Item->getOptions();
  1286.             $this->ItemIdToEstimateId[$Item->getId()] = is_object($Item->getEstimateId()) ? (int) (string) $Item->getEstimateId() : (int) $Item->getEstimateId();
  1287.             $L $Product->getId() . '-' $Item->getEstimateId();
  1288.             if ($I != $L) {
  1289.                 $this->CartSortFlg[$Product->getId()][$Item->getEstimateId()]['h'] = $Item->getId();
  1290.                 $this->CartSortFlg[$Product->getId()][$Item->getEstimateId()]['n'] = $Num;
  1291.                 $Num++;
  1292.                 $ItemCount 0;
  1293.             }
  1294.             $I $L;
  1295.             $ItemCount++;
  1296.             $this->CartSortFlg[$Product->getId()][$Item->getEstimateId()]['f'] = $Item->getId();
  1297.             $this->CartSortFlg[$Product->getId()][$Item->getEstimateId()]['ItemCount'] = $ItemCount;
  1298.         }
  1299.         
  1300.         // Bind merged options to the head item id per estimate
  1301.         foreach ($EstimetIds as $ProductId => $estimateMap) {
  1302.             foreach ($estimateMap as $estimateId => $headCandidateId) {
  1303.                 $headId $this->CartSortFlg[$ProductId][$estimateId]['h'] ?? $headCandidateId;
  1304.                 $this->EstimateOptions[$headId] = $Options[$headId] ?? null;
  1305.             }
  1306.         }
  1307.         // Calculate estimates separately for this group only
  1308.         list($total$optionsByEstimateId) = $this->EstimateCharacterizer->SetEstimateOption($Items, [], 'shopping');
  1309.         
  1310.         // Merge the results into the main EstimateOptionsByEstimateId
  1311.         foreach ($optionsByEstimateId as $estimateId => $options) {
  1312.             $this->EstimateOptionsByEstimateId[$estimateId] = $options;
  1313.         }
  1314.     }
  1315.     public function GetEstimateOption($Id$Page 'Shopping')
  1316.     {
  1317.         $estimateId $this->ItemIdToEstimateId[$Id] ?? null;
  1318.         
  1319.         if (!$estimateId || !isset($this->EstimateOptionsByEstimateId[$estimateId])) {
  1320.             return;
  1321.         }
  1322.         $EstimateOption $this->EstimateOptionsByEstimateId[$estimateId];
  1323.         return [
  1324.             'print' => $EstimateOption['print'] ?? [],
  1325.             'susoage' => $EstimateOption['susoage'] ?? '',
  1326.             'lot' => $EstimateOption['lot'] ?? null,
  1327.         ];
  1328.     }
  1329.     public function ShowEstimateOptions($Id)
  1330.     {
  1331.         $estimateId $this->ItemIdToEstimateId[$Id] ?? null;
  1332.         
  1333.         if (!$estimateId || !isset($this->EstimateOptionsByEstimateId[$estimateId])) {
  1334.             return;
  1335.         }
  1336.         $Option $this->EstimateOptionsByEstimateId[$estimateId];
  1337.         return $this->Twig->render(self::ShoppingEstimate, [
  1338.             'Prints' => $Option['print'] ?? [],
  1339.             'Susoage' => $Option['susoage'] ?? '',
  1340.             'Lot' => $Option['lot'] ?? null,
  1341.         ]);
  1342.     }
  1343.     public function ShowEstimateMobileOptions($item)
  1344.     {
  1345.         $estimateId $this->ItemIdToEstimateId[$item->getId()] ?? null;
  1346.         
  1347.         if (!$estimateId || !isset($this->EstimateOptionsByEstimateId[$estimateId])) {
  1348.             return;
  1349.         }
  1350.         $Option $this->EstimateOptionsByEstimateId[$estimateId];
  1351.         return $this->Twig->render(self::MobileShoppingEstimate, [
  1352.             'orderItem' => $item,
  1353.             'Prints' => $Option['print'] ?? [],
  1354.             'Susoage' => $Option['susoage'] ?? '',
  1355.             'Lot' => $Option['lot'] ?? null,
  1356.             'ProductClass' => $item->getProductClass(),
  1357.         ]);
  1358.     }
  1359.     public function ShowEstimateOptionsMail($Id$SubTotal)
  1360.     {
  1361.         $estimateId $this->ItemIdToEstimateId[$Id] ?? null;
  1362.         
  1363.         if (!$estimateId || !isset($this->EstimateOptionsByEstimateId[$estimateId])) {
  1364.             return;
  1365.         }
  1366.         $Option $this->EstimateOptionsByEstimateId[$estimateId];
  1367.         return $this->Twig->render(self::MailEstimate, [
  1368.             'Prints' => $Option['print'] ?? [],
  1369.             'Susoage' => $Option['susoage'] ?? '',
  1370.             'Lot' => $Option['lot'] ?? null,
  1371.             'kakouhi' => $Option['total'] ?? 0,
  1372.             'OptionSubTotal' => ($Option['total'] ?? 0) + ($Option['lot']['total'] ?? 0) + ($Option['product_total'] ?? 0),
  1373.         ]);
  1374.     }
  1375.     public function GetCartSortFlg($Item$Flg 'h')
  1376.     {
  1377.         $ProductClass $Item->getProductClass();
  1378.         $Product $ProductClass->getProduct();
  1379.         $ProductId $Product->getId();
  1380.         $EstimateId $Item->getEstimateId();
  1381.         $ItemId $Item->getId();
  1382.         switch ($Flg) {
  1383.             case 'f' :
  1384.                 return $this->CartSortFlg[$ProductId][$EstimateId][$Flg] == $ItemId true false;
  1385.                 break;
  1386.             case 'n':
  1387.                 return $this->CartSortFlg[$ProductId][$EstimateId][$Flg];
  1388.                 break;
  1389.             case 'ItemCount':
  1390.                 return $this->CartSortFlg[$ProductId][$EstimateId][$Flg];
  1391.             case 'h':
  1392.             default:
  1393.                 return $this->CartSortFlg[$ProductId][$EstimateId][$Flg] == $ItemId true false;
  1394.                 break;
  1395.         }
  1396.     }
  1397.     public function GetZeusCardDatas($Name$Order)
  1398.     {
  1399.         $Value '';
  1400.         switch ($Name) {
  1401.             case 'money':
  1402.                 $Value $this->OrderService->calculateCreditTotal($Order);
  1403.                 break;
  1404.             case 'sendid':
  1405.                 $Customer $Order->getCustomer();
  1406.                 $LmCustomer $this->CustomerService->GetLandMarkCustomerId($Customer->getLmCustomerId(), true);
  1407.                 $Value $LmCustomer['customer_bangou'];
  1408.                 break;
  1409.             case 'sendpoint':
  1410.                 $Value $Order->getZeusRequestData();
  1411.                 break;
  1412.             case 'telno':
  1413.                 $Value $Order->getPhoneNumber();
  1414.                 break;
  1415.             case 'email':
  1416.                 $Value $Order->getEmail();
  1417.                 break;
  1418.         }
  1419.         return $Value;
  1420.     }
  1421.     /**
  1422.      * ZeusCardError
  1423.      * カードエラーの場合表示する
  1424.      *
  1425.      */
  1426.     public function GetZeusCardError()
  1427.     {
  1428.         $CardError false;
  1429.         if ($OrderId $this->Session->get(OrderHelper::SESSION_ORDER_ID)) {
  1430.             $Order $this->OrderRepository->find($OrderId);
  1431.             $Paymenr $Order->getPayment();
  1432.             if ($this->CommonService->GetConfig('ZEUS_CARD_PAYMAET_ID') == $Paymenr->getId()) {
  1433.                 $CardError $Order->getLmOrderId();
  1434.             }
  1435.             $this->Session->get(OrderHelper::SESSION_ORDER_IDnull);
  1436.         }
  1437.         return $CardError;
  1438.     }
  1439.     public function GetEstimateType()
  1440.     {
  1441.         if ($this->CommonService->getConfig('BunkaruFlg')) {
  1442.             return 0;
  1443.         }
  1444.         switch ($this->CartService->GetCartType()) {
  1445.             case CartService::CartTypeEstimate:
  1446.                 return $this->CartService->getEstimateType();
  1447.                 break;
  1448.             case CartService::CartTypeNormal:
  1449.             default:
  1450.                 return 0;
  1451.                 break;
  1452.         }
  1453.     }
  1454.     public function GetCartAddLine($CartItem)
  1455.     {
  1456.         $Item $this->GetCartItemData($CartItem);
  1457.         $lineItemId $Item['EstimateId'] . '-' $Item['ProductId'];
  1458.         return $this->Twig->render(self::CartAddLineTwig, [
  1459.             'num' => $this->GetCartSortFlg($CartItem'n'),
  1460.             'ItemId' => $CartItem->getId(),
  1461.             'ProductId' => $Item['ProductId'],
  1462.             'ProductClass' => $Item['ProductClass'],
  1463.             'ClassCategory1Id' => $Item['ClassCategory1Id'],
  1464.             'ClassCategory2Id' => $Item['ClassCategory2Id'],
  1465.             'EstimateId' => $Item['EstimateId'],
  1466.             'lineItemId' => $lineItemId,
  1467.         ]);
  1468.     }
  1469.     protected function GetCartItemData($CartItem)
  1470.     {
  1471.         $ProductClass $CartItem->getProductClass();
  1472.         $Product $ProductClass->getProduct();
  1473.         $ClassCategory1 is_null($ProductClass) ? null $ProductClass->getClassCategory1();
  1474.         $ClassCategory1Id is_null($ClassCategory1) ? null $ClassCategory1->getId();
  1475.         $ClassCategory2 is_null($ProductClass) ? null $ProductClass->getClassCategory2();
  1476.         $ClassCategory2Id is_null($ClassCategory2) ? null $ClassCategory2->getId();
  1477.         return [
  1478.             'ProductClass' => $ProductClass,
  1479.             'Product' => $Product,
  1480.             'ProductId' => $Product->getId(),
  1481.             'ClassCategory1Id' => $ClassCategory1Id,
  1482.             'ClassCategory2Id' => $ClassCategory2Id,
  1483.             'EstimateId' => $CartItem->getEstimateId(),
  1484.         ];
  1485.     }
  1486.     public function GetCartBackBtn()
  1487.     {
  1488.         return $this->LmHelper->getBackUrl();
  1489.     }
  1490.     /********************************************************************************************************************* */
  1491.     /**
  1492.      * メッセージのbaseinfo config Messegeを 変換する
  1493.      * 例 
  1494.      *  {{BaseInfo.shop_name}}
  1495.      *  {{Config.Payment_Charge_free}}
  1496.      *  {{message.common.ResetPassward_messeg02}} or {{trans.common.ResetPassward_messeg02}}
  1497.      */
  1498.     public function BaseInfo($Text)
  1499.     {
  1500.         //     return $Text;
  1501.         return $this->CommonService->BaseInfo($Text);
  1502.     }
  1503.     /**
  1504.      * LMのプライス出力フォーマット
  1505.      * @param int $Price
  1506.      * @param string|false $yen
  1507.      */
  1508.     public function GetLmPrice($Price$yen '円')
  1509.     {
  1510.         if (!is_numeric($Price)) {
  1511.             return $Price;
  1512.         }
  1513.         if ($yen === false) {
  1514.             $yen '';
  1515.         }
  1516.         return number_format($Price) . $yen;
  1517.     }
  1518.     public function FormatPrice($Price)
  1519.     {
  1520.         if (!is_numeric($Price)) {
  1521.             return $Price;
  1522.         }
  1523.         return number_format($Price) . '<span class="prices-unit">円</span>';
  1524.     }
  1525.     /**
  1526.      * LMのプライス出力フォーマット
  1527.      *
  1528.      */
  1529.     public function SetPhone($Phone)
  1530.     {
  1531.         return $this->CommonService->GetPhoneNumber($Phonefalse);
  1532.     }
  1533.     public function SetPost($Post)
  1534.     {
  1535.         $Post str_replace('-'''$Post);
  1536.         if (strlen($Post) < 7) {
  1537.             return $Post;
  1538.         }
  1539.         return substr($Post03) . '-' substr($Post34);
  1540.     }
  1541.     public function SetJWeek($Da)
  1542.     {
  1543.         return \Lm\Util\Date::weekDay($Da\Lm\Util\Date::COUNTRY_JP);
  1544.     }
  1545.     public function GetLmCssList()
  1546.     {
  1547.         //
  1548.         $context = [];
  1549.         //
  1550.         $cssConfig $this->CommonService->GetConfig('Css');
  1551.         $cssRoot $cssConfig['Root'];
  1552.         $cssIndex $cssConfig['CssList'];
  1553.         $cssList = [];
  1554.         //
  1555.         $deviceType strtolower($this->CommonService->GetDevice(false$this->LmMobileDetector));
  1556.         //
  1557.         $pageTypeConfig $this->LmHelper->getPageType();
  1558.         $pageType $pageTypeConfig['type'];
  1559.         //
  1560.         $cssList array_merge($cssList$cssIndex[$deviceType]['common']);
  1561.         $cssList array_merge($cssList$cssIndex[$deviceType][$pageType]);
  1562.         //
  1563.         foreach ($cssList as $css) {
  1564.             $context['CssList'][] = [
  1565.                 'href' => "{$cssRoot}/{$deviceType}/{$css}",
  1566.             ];
  1567.         }
  1568.         //
  1569.         return $this->Twig->render('Common/CssList.twig'$context);
  1570.     }
  1571.     public function isSliderEnabled()
  1572.     {
  1573.         return $this->LmHelper->filterSliderEnabled();
  1574.     }
  1575.     public function GetCustomerBangou($lmCustomerId)
  1576.     {
  1577.         //
  1578.         $result = (new SqlService())
  1579.             ->Select('customer_bangou')
  1580.             ->Table('customer_table')
  1581.             ->Set('customer_id'$lmCustomerId)
  1582.             ->Find();
  1583.         //
  1584.         $customerBangou $result['customer_bangou'];
  1585.         //
  1586.         return $customerBangou;
  1587.     }
  1588.     public function getCatalogNoukiSchedule()
  1589.     {
  1590.         //
  1591.         return (new NoukiEngine())
  1592.             ->getCatalogSendDate();
  1593.     }
  1594.     public function getPageType()
  1595.     {
  1596.         return $this->LmHelper->getPageType();
  1597.     }
  1598.     /**
  1599.      * @param bool|false $strict
  1600.      * @return bool
  1601.      */
  1602.     public function isMobile($strict false)
  1603.     {
  1604.         if ($strict) {
  1605.             return $this->mobileDetector->isMobile();
  1606.         } else {
  1607.             return $this->LmMobileDetector->isMobile();
  1608.         }
  1609.     }
  1610.     /**
  1611.      * @return bool
  1612.      */
  1613.     public function wannaSeePc()
  1614.     {
  1615.         return !$this->isMobile() && $this->isMobile(true);
  1616.     }
  1617.     /**
  1618.      * @param array $paramsAdd
  1619.      * @param array $params
  1620.      * @return string
  1621.      */
  1622.     public function WithGetParams($paramsAdd$params = [])
  1623.     {
  1624.         if (is_array($params) && count($params) === 0) {
  1625.             $params $this->Request->query->all();
  1626.         }
  1627.         $params array_merge($params$paramsAdd);
  1628.         $result http_build_query($params);
  1629.         return $result;
  1630.     }
  1631.     /**
  1632.      * @param int $page
  1633.      * @return string
  1634.      */
  1635.     public function PageWithGetParams($page)
  1636.     {
  1637.         return $this->WithGetParams([
  1638.             'page' => $page,
  1639.         ]);
  1640.     }
  1641.     /**
  1642.      * @param OrderHeader|array|int $order
  1643.      * @return string|null
  1644.      * @throws \Exception
  1645.      */
  1646.     public function showSendScheduleDate($order)
  1647.     {
  1648.         try {
  1649.             /**
  1650.              * @var OrderHeader $orderHeader
  1651.              */
  1652.             if(!$order instanceof OrderHeaderExtended){
  1653.                 throw new \Exception('ERROR');
  1654.             }
  1655.             if ($orderHeader OrderHeader::factory($order)) {
  1656.                 //
  1657.                 return NoukiEngine::showSendScheduleByOrder($orderHeader);
  1658.             } else {
  1659.                 //
  1660.                 return null;
  1661.             }
  1662.         } catch (\Exception $e) {
  1663.             //
  1664.             if (is_string($order)) {
  1665.                 //
  1666.                 if (Date::validate($order'Y/m/d')) {
  1667.                     //
  1668.                     return NoukiEngine::showSendSchedule($order);
  1669.                 } else {
  1670.                     //
  1671.                     return $order;
  1672.                 }
  1673.             } else {
  1674.                 //
  1675.                 throw new \Exception('お届け予定日の計算処理に失敗しました'0$e);
  1676.             }
  1677.         }
  1678.     }
  1679.     /**
  1680.      * @param OrderHeader|array|int $order
  1681.      * @return string
  1682.      * @throws \Exception
  1683.      */
  1684.     public function showSendScheduleMessage($order$isMail false)
  1685.     {
  1686.         $orderHeader OrderHeader::factory($order);
  1687.         return $this->Twig->render(
  1688.             $isMail 'Common/SendScheduleDateMail.twig' 'Common/SendScheduleDate.twig',
  1689.             [
  1690.                 'orderHeader' => $orderHeader,
  1691.                 'isMobile' => $this->isMobile(),
  1692.                 'sendSchedule' => $this->showSendScheduleDate($order),
  1693.                 'paymentAtobarai' => [OrderHeader::PAYMENT_TYPE_ATOBARAIOrderHeader::PAYMENT_TYPE_ATOBARAI_MONTHLY],
  1694.             ]);
  1695.     }
  1696.     public function getOrderPaymentId($Order)
  1697.     {
  1698.         return !empty($Order->getPayment()) ? $Order->getPayment()->getId() : null;
  1699.     }
  1700.     public function getCategoryImageUrlById($categoryId)
  1701.     {
  1702.         return "/category_images/{$categoryId}.webp";
  1703.     }
  1704.     public function showFileSizeUpload($name 'default')
  1705.     {
  1706.         //
  1707.         $config $this->CommonService->GetConfig('FILE_UPLOAD');
  1708.         //
  1709.         if (!isset($config[$name])) {
  1710.             //
  1711.             throw new \Exception('Config name specified is invalid.');
  1712.         }
  1713.         //
  1714.         $FileUploadConfig $config[$name];
  1715.         //
  1716.         return $this->Twig->render('Common/FileUploadNotice.twig', [
  1717.             'FileUploadConfig' => $FileUploadConfig,
  1718.         ]);
  1719.     }
  1720.     public function showInventoryMatrix(GoodsWithRelated $goods)
  1721.     {
  1722.         //
  1723.         $id $goods->getGoodsId();
  1724.         $data $this->GoodsService->getGoodsById($id);
  1725.         $Product $this->ProductRepository->find($id);
  1726.         // $matrixData = $this->inventoryMatrixService->getInventoryMatrixData($goods, $color, $size);
  1727.         $inventoryMatrix = (new InventoryMatrix())
  1728.             ->getMatrixStock($goodsfalse$color$size)
  1729.         ;
  1730.         $colorCnt count($color);
  1731.         $sizeCnt count($size);
  1732.         $SellingColor $this->GoodsService->getSellingColorSql($idcount($color));
  1733.         $isShowMatrixButtonAbove = (($colorCnt * (intval(($sizeCnt 1) / 6) + 1)) >= 10);
  1734.         //
  1735.         return $this->Twig->render('Item/matrix.twig', [
  1736.             'isShowMatrixButtonAbove' => $isShowMatrixButtonAbove,
  1737.             'data' => $data,
  1738.             'goods' => $goods,
  1739.             // 'matrixData' => $matrixData,
  1740.             'Product' => $Product,
  1741.             'SellingColor' => $SellingColor,
  1742.             'inventoryMatrix' => $inventoryMatrix,
  1743.         ]);
  1744.     }
  1745.     /**
  1746.      * Handle format Object or array to json
  1747.      *
  1748.      * @param $data
  1749.      * @return string|null
  1750.      */
  1751.     public function formatDataToJson($data)
  1752.     {
  1753.         if (empty($data)) {
  1754.             return null;
  1755.         }
  1756.         return json_encode($dataJSON_UNESCAPED_UNICODE JSON_UNESCAPED_SLASHES);
  1757.     }
  1758.     public function getCartSessionName($key)
  1759.     {
  1760.         switch ($key) {
  1761.             case 'GROUP_1_NORMAL':
  1762.                 return '通常注文';
  1763.             case 'GROUP_2_RESERVATION':
  1764.                 return '予約注文';
  1765.             case 'GROUP_3_KYOUEI':
  1766.                 return 'メーカー「共栄-KYOEI」';
  1767.             default:
  1768.                 return '商品一覧';
  1769.         }
  1770.     }
  1771.     public function groupItemsHasSameProductId($items)
  1772.     {
  1773.         $result = [];
  1774.         foreach ($items as $item) {
  1775.             $productId $item->getProduct()->getId();
  1776.             if (!isset($result[$productId])) {
  1777.                 $result[$productId] = [];
  1778.             }
  1779.             $result[$productId][] = $item;
  1780.         }
  1781.         return $result;
  1782.     }
  1783.     /**
  1784.      * Get format date. Example: 2023/09/15 -> 2023年9月15日(金)
  1785.      *
  1786.      * @param string $date
  1787.      * @return string
  1788.      */
  1789.     public function formatDate(string $datebool $showDay true)
  1790.     {
  1791.         if (!empty($date) && strtotime($date) !== false) {
  1792.             $weekdays = [
  1793.                 => '月',
  1794.                 => '火',
  1795.                 => '水',
  1796.                 => '木',
  1797.                 => '金',
  1798.                 => '土',
  1799.                 => '日'
  1800.             ];
  1801.             $dateString date('Y年n月j日'strtotime($date));
  1802.             if ($showDay == false) {
  1803.                 return $dateString;
  1804.             }
  1805.             $dayOfWeek date('N'strtotime($date));
  1806.             $day $weekdays[$dayOfWeek];
  1807.             return $dateString '(' $day ')';
  1808.         }
  1809.         return $date;
  1810.     }
  1811.     /**
  1812.      * 日付を Common/SendScheduleDate.twig(arrivalPeriod)と同様の「n月上旬〜順次」表記にする.
  1813.      * formatDate と同様にまず strtotime、効かない文字列は「n月j日」パターンを試す。それ以外はそのまま返す.
  1814.      *
  1815.      * @param string|\DateTimeInterface|null $date
  1816.      */
  1817.     public function formatSendScheduleArrivalPeriod($date): string
  1818.     {
  1819.         if ($date === null || $date === '') {
  1820.             return '';
  1821.         }
  1822.         $monthDay $this->monthDayForJunPeriod($date);
  1823.         if ($monthDay !== null) {
  1824.             return $this->formatJunPeriodFromMonthDay($monthDay[0], $monthDay[1]);
  1825.         }
  1826.         return is_string($date) ? $date : (string) $date;
  1827.     }
  1828.     /**
  1829.      * @param string|\DateTimeInterface $date
  1830.      *
  1831.      * @return array{0: int, 1: int}|null
  1832.      */
  1833.     private function monthDayForJunPeriod($date): ?array
  1834.     {
  1835.         if ($date instanceof \DateTimeInterface) {
  1836.             return [(int) $date->format('n'), (int) $date->format('j')];
  1837.         }
  1838.         if (!is_string($date)) {
  1839.             return null;
  1840.         }
  1841.         if ($date !== '' && ($ts strtotime($date)) !== false) {
  1842.             return [(int) date('n'$ts), (int) date('j'$ts)];
  1843.         }
  1844.         if (preg_match('/(\d+)\s*月\s*(\d+)\s*日/u'$date$m)) {
  1845.             return [(int) $m[1], (int) $m[2]];
  1846.         }
  1847.         return null;
  1848.     }
  1849.     private function formatJunPeriodFromMonthDay(int $monthint $day): string
  1850.     {
  1851.         if ($day >= && $day <= 10) {
  1852.             return $month '月上旬〜順次';
  1853.         }
  1854.         if ($day >= 11 && $day <= 20) {
  1855.             return $month '月中旬〜順次';
  1856.         }
  1857.         return $month '月下旬〜順次';
  1858.     }
  1859.     public function formatMonthAndDay(string $datebool $showDay true$format "n/j")
  1860.     {
  1861.         if (!empty($date) && strtotime($date) !== false) {
  1862.             $weekdays = [
  1863.                 => '月',
  1864.                 => '火',
  1865.                 => '水',
  1866.                 => '木',
  1867.                 => '金',
  1868.                 => '土',
  1869.                 => '日'
  1870.             ];
  1871.             $dateString date($formatstrtotime($date));
  1872.             if ($showDay == false) {
  1873.                 return $dateString;
  1874.             }
  1875.             $dayOfWeek date('N'strtotime($date));
  1876.             $day $weekdays[$dayOfWeek];
  1877.             return $dateString '(' $day ')' ' 頃';
  1878.         }
  1879.         return $date;
  1880.     }
  1881.     /**
  1882.      * Format stock arrival date to a human-readable format
  1883.      *
  1884.      * @param string $date 入荷予定日 (YYYY-MM-DD または MM-DD 形式)
  1885.      * @return string 変換された入荷予定日(例: "3月上旬")
  1886.      * @throws \InvalidArgumentException 無効な日付形式の場合に例外をスロー
  1887.      */
  1888.     public function formatStockArrivalDate(string $date)
  1889.     {
  1890.         // 日付が `MM-DD` 形式でも許容する
  1891.         if (preg_match('/^(\d{1,2})[-\/](\d{1,2})$/'$date$matches)) {
  1892.             $month = (int)$matches[1];
  1893.             $day = (int)$matches[2];
  1894.         } elseif (strtotime($date) !== false) {
  1895.             $month = (int)date('n'strtotime($date));
  1896.             $day = (int)date('j'strtotime($date));
  1897.         } else {
  1898.             throw new \InvalidArgumentException('無効な日付形式です。MM-DD または YYYY-MM-DD 形式で入力してください。');
  1899.         }
  1900.         if ($day >= && $day <= 10) {
  1901.             return "{$month}月上旬〜順次";
  1902.         } elseif ($day >= 11 && $day <= 20) {
  1903.             return "{$month}月中旬〜順次";
  1904.         } else {
  1905.             return "{$month}月下旬〜順次";
  1906.         }
  1907.     }
  1908.     public function getDayOfWeek(string $date)
  1909.     {
  1910.         if (!empty($date) && strtotime($date) !== false) {
  1911.             $weekdays = [
  1912.                 => '月',
  1913.                 => '火',
  1914.                 => '水',
  1915.                 => '木',
  1916.                 => '金',
  1917.                 => '土',
  1918.                 => '日'
  1919.             ];
  1920.             $dayOfWeek date('N'strtotime($date));
  1921.             return $weekdays[$dayOfWeek];
  1922.         }
  1923.         return null;
  1924.     }
  1925.     /**
  1926.      * @param int $goodsId
  1927.      * @param int $janId
  1928.      * @return string
  1929.      */
  1930.     public function showYoyakuFlag($goodsId$janId)
  1931.     {
  1932.         //
  1933.         return Yoyaku::check($goodsIdfalse$janId) ? '(予約)' null;
  1934.     }
  1935.     /**
  1936.      * @param Item|Goods|int
  1937.      * @return string
  1938.      */
  1939.     public function filterLmWebTeika($item) {
  1940.         /**
  1941.          * @var Item $Item
  1942.          */
  1943.         $item Item::factory($item);
  1944.         //
  1945.         return $this->Twig->render('Common/LmWebPrice.twig', [
  1946.             'minPrice' => $item->getMinTeika(),
  1947.             'maxPrice' => $item->getMaxTeika(),
  1948.         ]);
  1949.     }
  1950.     /**
  1951.      * @param Item|Goods|int
  1952.      * @return string
  1953.      */
  1954.     public function filterLmWebPrice($item) {
  1955.         /**
  1956.          * @var Item $Item
  1957.          */
  1958.         $item Item::factory($item);
  1959.         //
  1960.         return $this->Twig->render('Common/LmWebPrice.twig', [
  1961.             'minPrice' => $item->getMinPrice(),
  1962.             'maxPrice' => $item->getMaxPrice(),
  1963.         ]);
  1964.     }
  1965.     /**
  1966.      * @param Goods $goods
  1967.      * @return string
  1968.      */
  1969.     public function showSokujitsuHassouBannerIfSo(Goods $goods)
  1970.     {
  1971.         /**
  1972.          * @var GoodsWithRelated $goods
  1973.          */
  1974.         $goods GoodsWithRelated::factory($goods);
  1975.         //
  1976.         return $this->Twig->render('Common/SokujitsuHassouBanner.twig', [
  1977.             'goods' => $goods,
  1978.         ]);
  1979.     }
  1980. }