app/Customize/Controller/CartController.php line 198

Open in your IDE?
  1. <?php
  2. /**
  3.  * @version EC-CUBE4系
  4.  * @copyright 株式会社 翔 kakeru.co.jp
  5.  *
  6.  * 2022年03月21日カスタマイズ
  7.  *
  8.  * app/Customize/Controller/CartController.php
  9.  *
  10.  *
  11.  * カート
  12.  *
  13.  *
  14.  *
  15.  *                                        ≡≡≡┏(^o^)┛
  16.  *****************************************************/
  17. namespace Customize\Controller;
  18. use Customize\Controller\LM\DataLayerTrait;
  19. use Customize\Event\LmEvents;
  20. use Customize\Service\EstimateCharacterizer;
  21. use Customize\Service\GoodsService;
  22. use Customize\Service\LmHelper;
  23. use Customize\Service\MobileDetector as LmMobileDetector;
  24. use Customize\Service\SampleService;
  25. use Eccube\Entity\BaseInfo;
  26. use Eccube\Entity\Customer;
  27. use Eccube\Entity\Layout;
  28. use Eccube\Entity\ProductClass;
  29. use Eccube\Event\EccubeEvents;
  30. use Eccube\Event\EventArgs;
  31. use Eccube\Repository\BaseInfoRepository;
  32. use Eccube\Repository\ProductClassRepository;
  33. use Customize\Service\CartService;
  34. use Customize\Service\OrderHelper;
  35. use Eccube\Service\PurchaseFlow\PurchaseContext;
  36. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  37. use Eccube\Service\PurchaseFlow\PurchaseFlowResult;
  38. use Symfony\Component\DependencyInjection\ContainerInterface;
  39. use Twig\Environment as Twig;
  40. use Lm\Engine\EC\Entity\GoodsWithRelated;
  41. use Lm\Engine\Zaiko\Entity\SkuExtended;
  42. use Lm\Entity\Goods;
  43. use Lm\Entity\GoodsColor;
  44. use Lm\Entity\GoodsPrice;
  45. use Lm\Entity\Jancode;
  46. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  47. use Symfony\Component\HttpFoundation\Request;
  48. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  49. use Symfony\Component\Routing\Annotation\Route;
  50. use Customize\Service\CommonService;
  51. use Customize\Service\CatalogService;
  52. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  53. use Symfony\Component\Validator\Validator\ValidatorInterface;
  54. use Customize\Validator as Assert;
  55. use Customize\Service\EstimateService;
  56. use Customize\Converter\OrderConverter;
  57. use Customize\Service\RecentGoodsService;
  58. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  59. class CartController extends \Eccube\Controller\CartController
  60. {
  61.     use DataLayerTrait {
  62.         DataLayerTrait::__construct as __dataLayerTraitConstruct;
  63.     }
  64.    const URL_NAME_AJAX   = [
  65.        CartService::ROUTE_ADD_NORMAL,
  66.        CartService::ROUTE_VALID_ESTIMATE,
  67.        CartService::ROUTE_ADD_SAMPLE,
  68.        CartService::ROUTE_ADD_LINE,
  69.    ];
  70.    const URL_NANE_SUBMIT = [
  71.        CartService::ROUTE_ADD_CATALOG,
  72.        CartService::ROUTE_ADD_ESTIMATE,
  73.        CartService::ROUTE_ADD_HYBRID,
  74.        CartService::ROUTE_ADD_REPEAT,
  75.    ];
  76.    const CartErrorMessage "front.cart_item_error%02d";
  77.     /**
  78.      * 「カートに入れる」フラグ - 商品をカートに追加しない
  79.      */
  80.    const ADD_PRODUCTS_NONE 0;
  81.     /**
  82.      * 「カートに入れる」フラグ - 商品を1つずつカートに追加する
  83.      */
  84.     const ADD_PRODUCTS_EACH 1;
  85.     /**
  86.      * 「カートに入れる」フラグ - 商品をまとめてカートに追加する
  87.      */
  88.     const ADD_PRODUCTS_BULK 2;
  89.     /**
  90.      * 「カートに入れる」フラグ - リピート注文
  91.      */
  92.     const ADD_PRODUCTS_REPEAT 3;
  93.     /**
  94.      * @var BaseInfo
  95.      */
  96.     protected $baseInfo;
  97.     protected $LmHelper;
  98.     protected $CommonService;
  99.     protected $CatalogService;
  100.     protected $Validator;
  101.     protected $Products;
  102.     protected $Errors = [];
  103.     protected $ItemNum 0;
  104.     protected $CartType;
  105.     protected $EstimateService;
  106.     protected $OrderConverter;
  107.     protected $session;
  108.     protected Twig $Twig;
  109.     /**
  110.      * @var EstimateCharacterizer
  111.      */
  112.     private $EstimateCharacterizer;
  113.     /**
  114.      * @var GoodsService
  115.      */
  116.     private $GoodsService;
  117.     /**
  118.      * @var LmMobileDetector
  119.      */
  120.     private $mobileDetector;
  121.     /**
  122.      * @var SampleService
  123.      */
  124.     private $SampleService;
  125.     /**
  126.      * CartController constructor.
  127.      *
  128.      * @param ProductClassRepository $productClassRepository
  129.      * @param CartService $cartService
  130.      * @param PurchaseFlow $cartPurchaseFlow
  131.      * @param BaseInfoRepository $baseInfoRepository
  132.      */
  133.     public function __construct(
  134.         ProductClassRepository $productClassRepository,
  135.         CartService            $cartService,
  136.         PurchaseFlow           $cartPurchaseFlow,
  137.         BaseInfoRepository     $baseInfoRepository,
  138.         CommonService          $CommonService,
  139.         CatalogService         $CatalogService,
  140.         ValidatorInterface     $Validator,
  141.         EstimateService        $EstimateService,
  142.         EstimateCharacterizer  $EstimateCharacterizer,
  143.         OrderConverter         $OrderConverter,
  144.         GoodsService           $GoodsService,
  145.         LmMobileDetector       $mobileDetector,
  146.         RecentGoodsService     $RecentGoodsService,
  147.         SampleService          $SampleService,
  148.         SessionInterface       $session,
  149.         ContainerInterface     $container,
  150.         Twig                   $Twig
  151.     )
  152.     {
  153.         //
  154.         parent::__construct($productClassRepository,  $cartService,  $cartPurchaseFlow,  $baseInfoRepository);
  155.         //
  156.         $this->baseInfo $baseInfoRepository->get();
  157.         $this->CommonService $CommonService;
  158.         $this->CatalogService $CatalogService;
  159.         $this->Validator $Validator;
  160.         $this->EstimateService $EstimateService;
  161.         $this->EstimateCharacterizer $EstimateCharacterizer;
  162.         $this->OrderConverter $OrderConverter;
  163.         $this->GoodsService $GoodsService;
  164.         $this->mobileDetector $mobileDetector;
  165.         $this->RecentGoodsService $RecentGoodsService;
  166.         $this->SampleService $SampleService;
  167.         $this->session $session;
  168.         $this->Container $container;
  169.         $this->Twig $Twig;
  170.         //
  171.         self::__dataLayerTraitConstruct($CommonService);
  172.     }
  173.     /**
  174.      * カート画面.
  175.      *
  176.      * @Route("/cart/", name="cart", methods={"GET"})
  177.      * @Template("Cart/index.twig")
  178.      */
  179.     public function index(Request $request)
  180.     {
  181.         if (!$this->session->get('referer')) {
  182.             if (($referer $request->headers->get('referer')) && strpos($referer"/cart") === false && strpos($referer"/estimate") === false && strpos($referer"/shopping") === false) {
  183.                 $this->session->set('referer'$referer);
  184.             }
  185.         }
  186.         if (
  187.             $this->cartService->getCartType() ==  CartService::CartTypeCatalog
  188.             && $request->get('from_url') != 'add_catalog'
  189.             && $request->get('_route') !== CartService::ROUTE_ADD_CATALOG
  190.             && empty($this->CommonService->GetLmOrderOption(CommonService::Lm_Option_Catalog))
  191.         ) {
  192.             $this->RemoveCart('catalog',null,'return');
  193.         }
  194.         $isYoyaku false;
  195.         //
  196.         $this->checkCartItemsAvailable();
  197.         //print_r( $_SESSION['data'] ?? []); unset( $_SESSION['data']);
  198.         // カートを取得して明細の正規化を実行
  199.         $Carts $this->cartService->getCarts();
  200.         $this->execPurchaseFlow($Carts);
  201.         list($this->CartTypeId$Products) = $this->cartService->MakeValidationData();
  202.         if ($this->CartTypeId != CartService::CartTypeSample) {
  203.             $this->AddCartValidation($Products,$this->cartService->GetCartType() ,false);
  204.         }
  205.         // TODO itemHolderから取得できるように
  206.         $least = [];
  207.         $isDeliveryFree = [];
  208.         $totalPrice 0;
  209.         $ProductTotal =0;
  210.         $totalQuantity $this->CommonService->calculateTotalQuantityForCarts($Carts);
  211.         $CatalogCartKey null;
  212.         $EstimateOptions = [];
  213.         $EstimatetTotal  0;
  214.         foreach ($Carts as $Cart) {
  215.             $isDeliveryFree[$Cart->getCartKey()] = false;
  216.             $OptionTotal $this->cartService->GetEstimateOptionData($Cart->getCartItems(),'cart');
  217.             list($ETotal,$EstimateOptions[$Cart->getCartKey()]) = $this->EstimateCharacterizer->SetEstimateOption($Cart->getCartItems(),$OptionTotal);
  218.             $EstimatetTotal += $ETotal;
  219.             $ProductTotal   += $Cart->getTotalPrice() + $EstimatetTotal;
  220.             if ($this->baseInfo->getDeliveryFreeAmount()) {
  221.                 if (!$isDeliveryFree[$Cart->getCartKey()] && $this->baseInfo->getDeliveryFreeAmount() <= $ProductTotal) {
  222.                     $isDeliveryFree[$Cart->getCartKey()] = true;
  223.                 } else {
  224.                     $least[$Cart->getCartKey()] = $this->baseInfo->getDeliveryFreeAmount() - $ProductTotal;
  225.                 }
  226.             }
  227.             $CatalogCartKey $Cart->getCartKey();
  228.             /**
  229.              * TODO: モジュール化
  230.              * 予約フラグ
  231.              */
  232.             foreach ($Cart->getCartItems() as $item) {
  233.                 //
  234.                 $janId $item->getProductClass()->getId();
  235.                 //
  236.                 if ($hoge $this->GoodsService->getGoodsReservation(nullnull$janId)) {
  237.                     //
  238.                     $isYoyaku true;
  239.                     break;
  240.                 }
  241.             }
  242.         }
  243.         $LargeDiscountRitu $this->EstimateCharacterizer->SetLargeDiscount($ProductTotal);
  244.         $LargeDiscount     $this->EstimateCharacterizer->GetLargeDiscount();
  245.         // カートが分割された時のセッション情報を削除
  246.         $request->getSession()->remove(OrderHelper::SESSION_CART_DIVIDE_FLAG);
  247.         list($CatalogDAta$CatalogCategoryLabel) = $this->GetCatalogData();
  248.         switch ($this->cartService->getCartType()) {
  249.             case CartService::CartTypeCatalog:
  250.                 $catalogOrderList $this->CommonService->GetLmOrderOption(CommonService::Lm_Option_Catalog);
  251.                 $totalQuantity is_array($catalogOrderList) ? count($catalogOrderList) : 0;
  252.                 $Title 'front.cart_catalog.title';
  253.                 $Twig 'Cart/Catalog.twig';
  254.                 break;
  255.             default:
  256.                 $Title 'front.cart.title';
  257.                 $Twig 'Cart/index.twig';
  258.                 break;
  259.         }
  260.         $Title trans($Title);
  261.         //LM仕様の商品表示順
  262.         $this->cartService->getLmCartItems();
  263.         // Get recent item
  264.         $cookies $this->RecentGoodsService->getRecentView();
  265.         $recentviews = array();
  266.         if (!empty($cookies)) {
  267.             $recentviews $this->RecentGoodsService->LM_getRecentViews2($cookies);
  268.         }
  269.         //
  270.         foreach ($this->cartService->getCarts() as $cart) {
  271.             foreach ($cart->getCartItems() as $cartItem) {
  272.                 //
  273.                 $id $cartItem->getProductClass()->getProduct()->getId();
  274.                 $quantity $cartItem->getQuantity();
  275.                 //
  276.                 $this->dataLayer['ydn']['yahoo_retargeting_items'][] = $this->CommonService->get_yahoo_retargeting_item($id$quantity);
  277.                 $this->dataLayer['criteo']['item'][] = [
  278.                     'id' => $id,
  279.                     'price' => $cartItem->getPriceIncTax(),
  280.                     'quantity' => $quantity,
  281.                 ];
  282.             }
  283.         }
  284.         // 在庫切れの商品が含まれていないかの確認用フラグ
  285.         $isItemsStockAvailable $this->cartService->isItemsStockAvailable();
  286.         if ($request->get('from_url') == CartService::ROUTE_ADD_REPEAT) {
  287.             $listSusoageChange = [];
  288.         } else {
  289.             $listSusoageChange $this->cartService->listSusoageChange();
  290.         }
  291.         //
  292.         return
  293.             $this->render($Twig, [
  294.                 'totalPrice' => $ProductTotal $LargeDiscount,
  295.                 'totalQuantity' => $totalQuantity,
  296.                 // 空のカートを削除し取得し直す
  297.                 'Carts' => $this->cartService->getCarts(true),
  298.                 'least' => $least,
  299.                 'is_delivery_free' => $isDeliveryFree,
  300.                 'title' => $Title,
  301.                 'h1_comment' => "{$this->baseInfo->getShopName()}{$Title}",
  302.                 'CatalogData' => $CatalogDAta,
  303.                 'CatalogCategoryLabel' => $CatalogCategoryLabel,
  304.                 'CatalogCartKey' => $CatalogCartKey,
  305.                 'SubWindoWData' => $this->CommonService->GetYaml('CatalogSubWindow.yaml'),
  306.                 'EstimateOptions' => $EstimateOptions,
  307.                 'EstimateTotla'   => $EstimatetTotal,
  308.                 'ProductTotal'    => $ProductTotal,
  309.                 'LargeDiscount'   => $LargeDiscount,
  310.                 'LargeDiscountRitu'=>$LargeDiscountRitu,
  311.                 'BreadCrumbs' =>[],
  312.                 'RepartData' =>$this->CommonService->GetLmOrderOption('repeat'),
  313.                 'isYoyaku' => $isYoyaku,
  314.                 'isMobile' => $this->mobileDetector->isMobile(),
  315.                 'recentviews' => $recentviews,
  316.                 'dataLayer' => $this->dataLayer,
  317.                 'isShowGlobalFooter' => false,
  318.                 'isItemsStockAvailable' => $isItemsStockAvailable,
  319.                 'isSusoageChange' => count($listSusoageChange) > 0,
  320.                 'listSusoageChange' => $listSusoageChange
  321.             ]);
  322.     }
  323.     /**
  324.      * @param $Carts
  325.      *
  326.      * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
  327.      */
  328.     protected function execPurchaseFlow($Carts)
  329.     {
  330.         /** @var PurchaseFlowResult[] $flowResults */
  331.         $flowResults array_map(function ($Cart) {
  332.             $purchaseContext = new PurchaseContext($Cart$this->getUser());
  333.             return $this->purchaseFlow->validate($Cart$purchaseContext);
  334.         }, $Carts);
  335.         // 復旧不可のエラーが発生した場合はカートをクリアして再描画
  336.         $hasError false;
  337.         foreach ($flowResults as $result) {
  338.             if ($result->hasError()) {
  339.                 $hasError true;
  340.                 foreach ($result->getErrors() as $error) {
  341.                     $this->addRequestError($error->getMessage());
  342.                 }
  343.             }
  344.         }
  345.         if ($hasError) {
  346.             $this->cartService->clear();
  347.             return $this->redirectToRoute('cart');
  348.         }
  349.         $this->cartService->save();
  350.         foreach ($flowResults as $index => $result) {
  351.             foreach ($result->getWarning() as $warning) {
  352.                 if ($Carts[$index]->getItems()->count() > 0) {
  353.                     $cart_key $Carts[$index]->getCartKey();
  354.                     $this->addRequestError($warning->getMessage(), "front.cart.${cart_key}");
  355.                 } else {
  356.                     // キーが存在しない場合はグローバルにエラーを表示する
  357.                     $this->addRequestError($warning->getMessage());
  358.                 }
  359.             }
  360.         }
  361.         return null;
  362.     }
  363.     /**
  364.      * カタログのDataを返す
  365.      *
  366.      *
  367.      */
  368.     protected function GetCatalogData()
  369.     {
  370.         if (CartService::CartTypeCatalog != $this->cartService->getCartType()) {
  371.             return [nullnullnull];
  372.         }
  373.         $Catatogs $this->CatalogService->GetCataLog();
  374.         $CatalogCategoryLabel $this->CommonService->GetYaml('catalog_category.yaml');
  375.         return [$Catatogs$CatalogCategoryLabel];
  376.     }
  377.     /**
  378.      * Check if current cart is type 3, 4 when repeat order
  379.      *
  380.      * @Route("/cart/check_mix_cart/", name="check_mix_cart", methods={"POST"} )
  381.      */
  382.     public function CheckMixCart(Request $request)
  383.     {
  384.         $CurrentCartType $this->cartService->GetCartType();
  385.         $showErrorModal $CurrentCartType === CartService::CartTypeSample || $CurrentCartType === CartService::CartTypeCatalog;
  386.         if ($showErrorModal) {
  387.             $this->Errors[] = $this->CommonService->GetExclusionControl(
  388.                 CartService::CartTypeNormal,
  389.                 trans('front.ExclusionControl.repeat_mixed_cart_type_' $CurrentCartType '_warning')
  390.             );
  391.             return $this->json([
  392.                 'status' => 'Error''Errors' => $this->Errors'show_error_modal' => $showErrorModal
  393.             ]);
  394.         } else {
  395.             return $this->json([
  396.                 'status' => 'ok''Errors' => '''show_error_modal' => $showErrorModal
  397.             ]);
  398.         }
  399.     }
  400.     /**
  401.      * カートに商品を追加・変更する
  402.      *
  403.      * @Route("/cart/add_Normal", name=CartService::ROUTE_ADD_NORMAL, methods={"GET","POST"} )
  404.      * @Route("/cart/valid_estimate", name=CartService::ROUTE_VALID_ESTIMATE, methods={"GET","POST"} )
  405.      * @Route("/cart/add_estimate", name=CartService::ROUTE_ADD_ESTIMATE, methods={"GET","POST"} )
  406.      * @Route("/cart/add_sample", name=CartService::ROUTE_ADD_SAMPLE, methods={"GET","POST"} )
  407.      * @Route("/cart/add_catalog", name=CartService::ROUTE_ADD_CATALOG, methods={"GET","POST"} )
  408.      * @Route("/cart/add_line", name=CartService::ROUTE_ADD_LINE, methods={"GET","POST"} )
  409.      * @Route("/cart/add_hybrid", name=CartService::ROUTE_ADD_HYBRID, methods={"GET","POST"} )
  410.      * @Route("/cart/add_repeat", name=CartService::ROUTE_ADD_REPEAT, methods={"GET","POST"} )
  411.       */
  412.     public function AddCart(Request $request)
  413.     {
  414.         $carts $this->cartService->getCarts();
  415.         $UrlName $request->get('_route');
  416.         //
  417.         $goodsId $request->get('goodsId');
  418.         $CartType $this->cartService->GetCartType();
  419.         $ExclusionControl null;
  420.         $showErrorModal false;
  421.         if ($Products $this->cartService->CartItemConv($request->get('product_matrix'))) {
  422.             // セット品番対応
  423.             $Products $this->cartService->convertProductsForSetPurchase($Products);
  424.             // 排他チェック
  425.             if (($checkMixCart $this->cartService->checkMixCart($UrlNamearray_keys($Products))) !== true) {
  426.                 $showErrorModal true;
  427.                 $messageId "front.ExclusionControl.mixed_cart_type_{$checkMixCart[0]}_add_{$checkMixCart[1]}_warning";
  428.                 $messageId.= isset($checkMixCart[2]) ? "_{$checkMixCart[2]}'';
  429.                 $messageId.= isset($checkMixCart[3]) ? "_{$checkMixCart[3]}'';
  430.                 $this->Errors[] = $this->CommonService->GetExclusionControl(
  431.                     CartService::CartTypeNormal,
  432.                     trans($messageId)
  433.                 );
  434.             }
  435.         }
  436. /* 一旦トークンを外す 2022/11/26
  437.         if ('add_catalog' != $UrlName) {
  438.             if ($this->CommonService->GetToken(CommonService::Matrix_Token) != $request->get('OlToken')) {
  439.                 if(in_array($UrlName,self::URL_NANE_SUBMIT)) {
  440.                     throw new NotFoundHttpException();
  441.                 }else{
  442.                    // $Token = $this->CommonService->ResetToken(CommonService::Matrix_Token);
  443.                     return $this->json(['status' => 'Error', 'Error' =>''],400);
  444.                 }
  445.             }
  446.         }
  447. */
  448.         #排他制御解除 カタログ
  449.          if(CartService::CartTypeCatalog == $this->cartService->GetCartType()){
  450.             if(!$this->CommonService->GetLmOrderOption('catalog')){
  451.                 $this->RemoveCart('catalog',null,'return');
  452.             }
  453.         }
  454.        #OrderOption 初期化
  455.         if(!$this->cartService->GetCartType()){
  456.             $this->CommonService->InitializeLmOrderOption();
  457.         }
  458.         $Errors = [];
  459.         $AddProductsFlg self::ADD_PRODUCTS_EACH//2 = オリジナル カートに追加を一気におこなう
  460.         //
  461.         $MaxEstimateId$this->cartService->getMaxEstimateId();
  462.         switch ($UrlName) {
  463.             case CartService::ROUTE_ADD_REPEAT:
  464.                 if(!$LmOrderId $request->get('order_id')){
  465.                     $ExclusionControl CartService::RepeatError01;
  466.                     break;
  467.                 }
  468.                 if(!$Datas $this->OrderConverter->GetCartFromLmOrderId($LmOrderId)){
  469.                     $ExclusionControl CartService::RepeatError01;
  470.                     break;
  471.                 }
  472.                 // 非表示商品のチェック
  473.                 if (!LmHelper::isSecret()) {
  474.                     foreach ($Datas['orderList'] as $index => $order) {
  475.                         if (($goods = new Goods($order['goodsId'])) && $goods->getGoodsStatus() === Goods::GOODS_STATUS_UNAVAIABLE) {
  476.                             //
  477.                             unset($Datas['orderList'][$index]);
  478.                             //
  479.                             $this->addRequestError('現在、ご購入頂けない商品が含まれていましたのでカートから削除しました。'"front.cart");
  480.                         }
  481.                     }
  482.                     $Datas['orderList'] = array_values($Datas['orderList']);
  483.                 }
  484.                 /**
  485.                  * TODO: Revert me.
  486.                  * @var Customer $user
  487.                  * @var int|null $LmOrderId
  488.                  */
  489.                 function _log_20230414_03(Customer $user$LmOrderId) {
  490.                     $lmCustomerId '';
  491.                     if (!empty($user)) {
  492.                         $lmCustomerId $user->getLmCustomerId();
  493.                     }
  494.                     log_info("[LM]/cart/add_repeat/ - \{ \$lmCustoerId: {$lmCustomerId}, \$lmOrderId: {$LmOrderId} \}");
  495.                 }
  496.                 _log_20230414_03($this->CommonService->getUser(), $LmOrderId);
  497.                 $ItemRepeatCartType $this->RepeatCartType($Datas['orderList']);
  498.                 $CurrentCartType $this->cartService->GetCartType();
  499.                 $filterRepeatOrderTypeEstimate array_filter($Datas['orderList'], function ($item) {
  500.                     return !empty($item['Options']);
  501.                 });
  502.                 if ($CurrentCartType == CartService::CartTypeSample || $CurrentCartType == CartService::CartTypeCatalog) {
  503.                     $ExclusionControl CartService::RepeatError03;
  504.                     break;
  505.                 }
  506.                 $CartType = ($ItemRepeatCartType == CartService::CartTypeEstimate ||
  507.                     $CurrentCartType == CartService::CartTypeEstimate) ?
  508.                     CartService::CartTypeEstimate :
  509.                     CartService::CartTypeNormal;
  510.                 $AddProductsFlg self::ADD_PRODUCTS_REPEAT;
  511.                 #カートタイプの登録
  512.                 $this->cartService->SetCartType($CartType);
  513.                 $this->CommonService->AddLmOrderOption('repeat',['ohid'=>$Datas['ohId']]);
  514.              break;
  515.             case CartService::ROUTE_ADD_LINE:
  516.                 $AddProductsFlg self::ADD_PRODUCTS_BULK;
  517.                 if ($Data $request->get('CartItem')) {
  518.                     list($Products$Errors) = $this->cartService->AddCartLine($Data);
  519.                     if (count($Errors) > 0) {
  520.                         foreach ($Errors as $Id => $ErrorId) {
  521.                             $this->SetCartError($ErrorId$Id);
  522.                         }
  523.                     }
  524.                     if ($CartType == CartService::CartTypeSample) {
  525.                         $this->SetSampleItemMax($Productsfalse);
  526.                     }
  527.                     $this->AddCartValidation($Products,$this->cartService->GetCartType() ,false);
  528.                 } else {
  529.                     $this->SetCartError(12);
  530.                 }
  531.                 break;
  532.             case CartService::ROUTE_ADD_CATALOG:
  533.                 $layoutId $this->mobileDetector->isMobile() ? 30 29;
  534.                 $em $this->Container->get('doctrine.orm.entity_manager');
  535.                 $Layout $em->getRepository(Layout::class)->find($layoutId);
  536.                 $this->Twig->addGlobal('Layout'$Layout);
  537.                 if ($this->cartService->getCartType()) {
  538.                     if (CartService::CartTypeCatalog != $this->cartService->getCartType()) {
  539.                         $ExclusionControl CartService::CartTypeCatalog;
  540.                         break;
  541.                     }
  542.                 }
  543.                 // 一旦 全てのカート商品を削除する
  544.                 $this->cartService->clear();
  545.                 #カートタイプの設定
  546.                 $this->cartService->SetCartType(CartService::CartTypeCatalog);
  547.                 $this->Products[$this->CommonService->GetConfig('CatalogProdctClassId')] = 1;
  548.                 break;
  549.             case CartService::ROUTE_ADD_SAMPLE:
  550.                 if ($this->cartService->getCartType()) {
  551.                     if (CartService::CartTypeSample != $this->cartService->getCartType()) {
  552.                         $cartType $this->cartService->getCartType();
  553.                         $showErrorModal true;
  554.                         $this->Errors[] = $this->CommonService->GetExclusionControl(
  555.                             CartService::CartTypeNormal,
  556.                             trans('front.ExclusionControl.mixed_cart_type_' $cartType '_add_' CartService::CartTypeSample '_warning')
  557.                         );
  558.                         break;
  559.                     }
  560.                 }
  561.                 #カートタイプの設定
  562.                 $this->cartService->SetCartType(CartService::CartTypeSample);
  563.                 $this->AddCartValidation($Products,CartService::CartTypeSample);
  564.                 $this->SetSampleItemMax($Products);
  565.                 break;
  566.             case CartService::ROUTE_VALID_ESTIMATE:
  567.                 if ($this->cartService->getCartType()) {
  568.                     if (CartService::CartTypeSample <= $this->cartService->getCartType()) {
  569.                         $cartType $this->cartService->getCartType();
  570.                         $showErrorModal true;
  571.                         $this->Errors[] = $this->CommonService->GetExclusionControl(
  572.                             CartService::CartTypeNormal,
  573.                             trans('front.ExclusionControl.mixed_cart_type_' $cartType '_add_' CartService::CartTypeEstimate '_warning')
  574.                         );
  575.                         break;
  576.                     }
  577.                 }
  578.                 $AddProductsFlg self::ADD_PRODUCTS_NONE#登録を行わない
  579.                 $this->AddCartValidation($Products,$this->cartService->getCartType());
  580.                 break;
  581.             case CartService::ROUTE_ADD_ESTIMATE:
  582.                 if ($this->cartService->getCartType()) {
  583.                     if (CartService::CartTypeSample <= $this->cartService->getCartType()) {
  584.                         $ExclusionControl CartService::CartTypeEstimate;
  585.                         break;
  586.                     }
  587.                 }
  588.                 $this->cartService->SetCartType(CartService::CartTypeEstimate);
  589.                 $this->cartService->SetEstimates($request->get('estimate'));
  590.                 $this->AddCartValidation($Products,$this->cartService->getCartType());
  591.                 break;
  592.             case CartService::ROUTE_ADD_HYBRID:
  593.                 if ($this->cartService->getCartType()) {
  594.                     if (CartService::CartTypeSample <= $this->cartService->getCartType()) {
  595.                         $ExclusionControl CartService::CartTypeEstimate;
  596.                         break;
  597.                     }
  598.                 }
  599.                 $AddProductsFlg self::ADD_PRODUCTS_NONE;
  600.                 $Hybrid $request->get('Hybrid');
  601.                 if ($CasrtItemIds $Hybrid['cart_item_ids'] ?? null) {
  602.                     $this->cartService->SetCartType(CartService::CartTypeEstimate);
  603.                     $this->cartService->SetEstimates($request->get('estimate'));
  604.                     $this->cartService->setPreOrderId(null);
  605.                     $this->cartService->SetHybrid($CasrtItemIds);
  606.                 }
  607.                 break;
  608.             case CartService::ROUTE_ADD_NORMAL:
  609.             default:
  610.                 if ($this->cartService->getCartType()) {
  611.                     if (CartService::CartTypeSample <= $this->cartService->getCartType()) {
  612.                         $cartType $this->cartService->getCartType();
  613.                         $showErrorModal true;
  614.                         $this->Errors[] = $this->CommonService->GetExclusionControl(
  615.                             CartService::CartTypeNormal,
  616.                             trans('front.ExclusionControl.mixed_cart_type_' $cartType '_add_' CartService::CartTypeNormal '_warning')
  617.                         );
  618.                         break;
  619.                     }
  620.                 }
  621.                 #カートタイプの設定
  622.                 if ($this->cartService->getCartType() == CartService::CartTypeEstimate) {
  623.                     $this->cartService->SetCartType(CartService::CartTypeComposite);
  624.                 } else {
  625.                     $this->cartService->SetCartType(CartService::CartTypeNormal);
  626.                 }
  627.                 //
  628.                 $cartItemIds = [];
  629.                 $cartItems $this->cartService->getAllCartsItems();
  630.                 if ($cartItems) {
  631.                     foreach ($cartItems as $cartItem) {
  632.                         $cartItemIds[] = $cartItem->getProductClass()->getId();
  633.                     }
  634.                 }
  635.                 if (!empty($goodsId)) {
  636.                     $goods = new GoodsWithRelated($goodsId);
  637.                     if ($goods->isGoodsSetPurchase()) {
  638.                         $productKeys array_keys($Products);
  639.                         $allKeysExist true;
  640.                         foreach ($productKeys as $key) {
  641.                             if (!in_array($key$cartItemIds)) {
  642.                                 $allKeysExist false;
  643.                                 break;
  644.                             }
  645.                         }
  646.                         if (!$allKeysExist) {
  647.                             $MaxEstimateId++;
  648.                         }
  649.                         $this->cartService->SetEstimateId($MaxEstimateId);
  650.                     }
  651.                 }
  652.                 $this->AddCartValidation($ProductsCartService::CartTypeNormal);
  653.                 break;
  654.         }
  655.         /** 排他モード */
  656.         if ($ExclusionControl) {
  657.             $this->session->set(CartService::Session_ExclusionControlFlg$ExclusionControl);
  658.             if(in_array($UrlName,self::URL_NANE_SUBMIT)) {
  659.                 return $this->redirectToRoute('cart');
  660.             }else{
  661.                 return $this->json(['status' => 'Error''Error' =>'排他制御エラーカートにリダイレクトしてください。'],400);
  662.             }
  663.         }
  664.         //$this->Errors[] = ['errid' => 1, 'message' => $AddProductsFlg ];
  665.         #エラーがある
  666.         if (count($this->Errors) > 0) {
  667.             $Token $this->CommonService->ResetToken(CommonService::Matrix_Token);
  668.             return $this->json([
  669.                 'status' => 'Error''OlToken' => $Token'Errors' => $this->Errors'show_error_modal' => $showErrorModal
  670.             ]);
  671.         }
  672.         try {
  673.             log_info("----AddProductsFlg: "$AddProductsFlg " Cart: ", [
  674.                 "CartType" => $this->cartService->GetCartType(),
  675.                 "request" => $request->request->all()
  676.             ]);
  677.         } catch (\Exception $exception) {
  678.             log_error("cart_error:AddProductsFlg " $exception->getMessage());
  679.         }
  680.         # EC-CUBE のデフォルトでは iSKU ごとの登録ですが 一挙に登録します
  681.         switch ($AddProductsFlg) {
  682.             case self::ADD_PRODUCTS_REPEAT:
  683.                 foreach ($Datas['orderList'] as $Data) {
  684.                     #見積もりシミュレーションの初期化
  685.                     $this->cartService->InitiarizeEstimate();
  686.                     $this->SetProduct($Data['Products']);
  687.                     if (count($Data['Options']) > 0) {
  688.                         $Options $Data['Options'][0] ?? $Data['Options'];
  689.                         $Options['repeat'] = $Datas['ohId'];
  690.                         $Options['product_class_id'] = array_key_first($this->Products);
  691.                         $this->cartService->SetEstimates($Options);
  692.                     }
  693.                     $MaxEstimateId++;
  694.                     $this->cartService->SetEstimateId($MaxEstimateId);
  695.                     $this->cartService->AddCartProduct($this->Products);
  696.                     $this->cartService->UpRepeatEstimateOption();
  697.                     $this->handleDispathEventAddProductToCart($Data['Products'], $Data['goodsId']);
  698.                 }
  699.                 break;
  700.             case self::ADD_PRODUCTS_BULK:
  701.                 $this->cartService->AddProducts();
  702.                 $this->cartService->save();
  703.                 $this->cartService->UpEstimateOption();
  704.                 break;
  705.             case self::ADD_PRODUCTS_EACH;
  706.                 #一つづつカートへ追加
  707.                 $this->cartService->AddCartProduct($this->Products);
  708.                /*foreach ($this->Products as $ClassId => $Quantity) {
  709.                     if (!$Quantity) {
  710.                         continue;
  711.                     }
  712.                     $ProductClass = $this->cartService->GetProductClass($ClassId) ?? $ClassId;
  713.                     $this->cartService->addProduct($ProductClass, $Quantity);
  714.                 }
  715.                 $this->cartService->save();*/
  716.                 break;
  717.         }
  718.         $this->session->set(LmEvents::SESSION_FRONT_PRODUCT_CARTtrue);
  719.         // use screen detail block matrix
  720.         if (!empty($goodsId)) {
  721.             $this->handleDispathEventAddProductToCart($Products$goodsId);
  722.         }
  723.         //
  724.         if ($returnUrl $request->get('returnUrl')) {
  725.             $this->session->set('referer'$returnUrl);
  726.         }
  727.         if ($UrlName === CartService::ROUTE_ADD_CATALOG) {
  728.             return $this->index($request);
  729.         } else if(in_array($UrlName,self::URL_NANE_SUBMIT)) {
  730.             return $this->redirectToRoute('cart', ['from_url' => $UrlName]);
  731.         }
  732.         $Token $this->CommonService->ResetToken(CommonService::Matrix_Token);
  733.         return $this->json(['status' => 'OK''data' => $Products'OlToken' => $Token]);
  734.     }
  735.     /**
  736.      * カートを削除する
  737.      *
  738.      * @Route("/cart/remove/{mode}/{Token}/{id}", name="remove_cart_item", methods={"GET"}, requirements={"mode" = "[a-z]+","Token" = "\w+","id" = "\d+"  })
  739.      */
  740.     public function RemoveCart($mode null$Token null$id null)
  741.     {
  742.         if (is_null($mode)) {
  743.             throw new NotFoundHttpException();
  744.         }
  745.         if (!$mode == 'all') {
  746.             if ($this->CommonService->GetToken(CommonService::RemoveCartItme) != $Token) {
  747.                 throw new NotFoundHttpException();
  748.             }
  749.             $this->CommonService->RemoveToken(CommonService::RemoveCartItme);
  750.         }
  751.         $Url 'homepage';
  752.         switch ($mode) {
  753.             case 'item':
  754.                 $cart $this->cartService->getCart();
  755.                 if (!empty($cart)) {
  756.                     foreach($cart->getItems() as $item ) {
  757.                         if ($item->getId() == $id) {
  758.                             $productId $item->getProductClass()->getProduct()->getId();
  759.                             $janId$item->getProductClass()->getId();
  760.                             $event = new EventArgs([
  761.                                 'deleted_item_id' => $productId,
  762.                                 'deleted_item_sku_id' => $janId
  763.                             ]);
  764.                             $this->eventDispatcher->dispatch($event,LmEvents::SESSION_FRONT_PRODUCT_CART_DELETE_PRODUCT );
  765.                             $this->session->set(LmEvents::SESSION_FRONT_PRODUCT_CARTtrue);
  766.                         }
  767.                     }
  768.                 }
  769.                 $this->cartService
  770.                     ->RemoveItem($id# $Param = CartItem ItemId
  771.                     ->UpEstimateOption()
  772.                 ;
  773.                 $Url 'cart';
  774.                 break;
  775.             case 'all':
  776.                 $Url 'cart';
  777.             case 'catalog':
  778.                 //全てのカート商品を削除する
  779.                 $this->cartService->clear();
  780.                 //LmOrderOption の削除
  781.                 $this->CommonService->InitializeLmOrderOption();
  782.                 if ($id=='return'){
  783.                     return [];
  784.                 }
  785.                 break;
  786.         }
  787.         return $this->redirectToRoute($Url);
  788.     }
  789.     /**
  790.      * カートをロック状態に設定し、購入確認画面へ遷移する.
  791.      *
  792.      * @Route("/cart/buystep/{cart_key}", name="cart_buystep", requirements={"cart_key" = "[a-zA-Z0-9]+[_][\x20-\x7E]+"}, methods={"POST","GET"})
  793.      */
  794.     public function buystep(Request $request$cart_key)
  795.     {
  796.         $Carts $this->cartService->getCart();
  797.         if (!is_object($Carts)) {
  798.             return $this->redirectToRoute('cart');
  799.         }
  800.         // FRONT_CART_BUYSTEP_INITIALIZE
  801.         $event = new EventArgs(
  802.             [],
  803.             $request
  804.         );
  805.         $this->eventDispatcher->dispatch($event,EccubeEvents::FRONT_CART_BUYSTEP_INITIALIZE );
  806.         #202203/31 カタログを追加する
  807.         if (CartService::CartTypeCatalog == $Carts->getCartType()) {
  808.             // CSRFトークンの検査
  809.             if (empty($token $request->get('OlToken')) || ($token !== $this->CommonService->GetToken('catalog'))) {
  810.                 //
  811.                 throw new AccessDeniedHttpException('[LM]CSRF token is invalid.');
  812.             }
  813.             //
  814.             $this->CommonService->RequestLmOrderOption();
  815.             $options $this->CommonService->GetLmOrderOption();
  816.             if (empty($options)) {
  817.                 return $this->redirectToRoute('cart', ['from_url' => 'add_catalog']);
  818.             }
  819.         }
  820.         $this->cartService->SetCartType($Carts->getCartType());
  821.         $this->cartService->setPrimary($cart_key);
  822.         $this->cartService->save();
  823.         // FRONT_CART_BUYSTEP_COMPLETE
  824.         $event = new EventArgs(
  825.             [],
  826.             $request
  827.         );
  828.         $this->eventDispatcher->dispatch($event,EccubeEvents::FRONT_CART_BUYSTEP_COMPLETE);
  829.         if ($event->hasResponse()) {
  830.             return $event->getResponse();
  831.         }
  832.         return $this->redirectToRoute($request->get('next_step''shopping'));
  833.     }
  834.     /**
  835.      * ポップアップ詳細見出し
  836.      * /catalog/detail/{id}
  837.      * ポップアップ詳細見出し catalog_detail_headline
  838.      *
  839.      * @Route("/catalog/detail/{id}/", name="catalog_ditail", methods={"GET"},requirements={"id" = "\d+"}))
  840.      * @Template("Cart/CatalogDetail.twig")
  841.      */
  842.     public function CatalogDitail(Request $request$id null)
  843.     {
  844.         $Data $this->CatalogService->GetCatalog(['id' => $id]);
  845.         if($Data && isset($Data['catalog_detail_uploaded_image_list'])){
  846.             $Data['image_lists'] = json_decode($Data['catalog_detail_uploaded_image_list'], true);
  847.         }else{
  848.             $Data['image_lists'] = null;
  849.         }
  850.         return [
  851.             'Data' => $Data,
  852.             'SubWindoWData' => $this->CommonService->GetYaml('CatalogSubWindow.yaml'),
  853.         ];
  854.     }
  855.     /**
  856.      * エラーを返す
  857.      * 1 X個以上
  858.      * 2 既にカートにある
  859.      * 3 在庫なし
  860.      * 4 数字以外
  861.      * 5 商品が削除されている
  862.      * 6 サンプルは1個までです
  863.      * 7 サンプルカートにある
  864.      * 8 個数を入れてくださお
  865.      * 0 11 サンプルMAX 
  866.      * 0 12 数量が入っていない
  867.      * 0 13 DATAが確認できないDATAあります
  868.      * 0 14 変更するDATAがありません。
  869.      */
  870.     public function AddCartValidation($Products$CartType ,$Flg true)
  871.     {
  872.         if (!is_array($Products)) {
  873.             return $this->SetCartError(14);
  874.         }
  875.         if (count($Products) < 1) {
  876.             return $this->SetCartError(14);
  877.         }
  878.         $Limit $CartType == CartService::CartTypeSample $this->CommonService->GetConfig('SampleLimit') : null;
  879.         #オブジェクトからエラーIDを取得する
  880.         $SetError = function ($ClassId$Error) {
  881.             if ($Error->count() < 1) {
  882.                 return null;
  883.             }
  884.             return $Error[0]->getMessage();
  885.         };
  886.         // 入力チェック
  887.         foreach ($Products as $ClassId => $Quantity) {
  888.             $this->ItemNum++;
  889.             $this->Products[$ClassId] = $Quantity;
  890.             if (!$ProductClass $this->cartService->GetProductClass($ClassId)) {
  891.                 $this->SetCartError(5);
  892.             } else {
  893.                 $ClassCategory1 $ProductClass->getClassCategory1();
  894.                 if ($ClassCategory1 && !$ClassCategory1->isVisible()) {
  895.                     $this->SetCartError(5);
  896.                 } else {
  897.                     $ClassCategory2 $ProductClass->getClassCategory2();
  898.                     if ($ClassCategory2 && !$ClassCategory2->isVisible()) {
  899.                         $this->SetCartError(5);;
  900.                     }
  901.                 }
  902.             }//Classの検証
  903.             if ($ErrId $SetError($ClassId$this->Validator->validate(
  904.                 $Quantity,
  905.                 [
  906.                     new Assert\Quantity(['ClassId' => $ClassId,
  907.                         'Limit' => $Limit,
  908.                         'StockLimit' => $this->CommonService->GetConfig('Stocklimit'),
  909.                         'Flg' => $Flg,
  910.                         'CartType' => $CartType,
  911.                     ])
  912.                 ]
  913.             ))
  914.             ) {
  915.                 $this->SetCartError($ErrId$ClassId$ProductClass$Flg);
  916.             }//ヴァり
  917.         }
  918.         return;
  919.     }
  920.     /**
  921.      * @param int error id
  922.      * @param int product_class_id
  923.      *
  924.      * @return string ErrorMessage
  925.      */
  926.     protected function SetCartError($ErrId$ClassId 0$Class null$Flg false$MessageParams = [])
  927.     {
  928.         $ClassName '';
  929.         if ($Flg) {
  930.             $Name1 '';
  931.             $Name2 '';
  932.             if ($Class) {
  933.                 if ($Classcategory1 $Class->getClassCategory1()){
  934.                     $Name1 $Classcategory1->getName();
  935.                 }
  936.                 if ($Classcategory2 $Class->getClassCategory2()){
  937.                     $Name2 $Classcategory2->getName();
  938.                 }
  939.                 $ClassName $Name1  ':' $Name2   ' ';
  940.             }
  941.         }
  942.         $Msg sprintf(self::CartErrorMessage$ErrId);
  943.         $Msg trans($Msg$MessageParams);
  944.         $Msg $this->CommonService->BaseInfo($Msg);
  945.         $Msg $ClassName $Msg;
  946.         switch ($ErrId) {
  947.             case :
  948.                 $Msg .= ' ClassId=' $ClassId;
  949.                 break;
  950.         }
  951.         $this->Errors[] = ['errid' => $ErrId'message' => $Msg'class_id' => $ClassId'add_lines' => $this->cartService->getAddlines($ClassId)];
  952.     }
  953.     protected function SetProduct($Products){
  954.         $this->Products null;
  955.         foreach ($Products as $Product){
  956.             $this->Products[$Product['product_class_id']] = $Product['quantity'];
  957.         }
  958.     }
  959.     protected function RepeatCartType($Datas){
  960.         $CartType CartService::CartTypeNormal;
  961.         foreach ($Datas as $i=> $Data){
  962.             if(count($Data['Options'])>0){
  963.                 $CartType CartService::CartTypeEstimate;
  964.             }
  965.         }
  966.         return $CartType;
  967.     }
  968.     protected function SetSampleItemMax($Products $Flg true)
  969.     {
  970.         $CartItemNum 0;
  971.         if($Flg){
  972.             foreach ($this->cartService->getCarts() as $Cart) {
  973.                 $CartItemNum += count($Cart->getCartItems());
  974.             }
  975.         }
  976.         $sampleLimit $this->SampleService->getSampleLimit();
  977.         if (!$sampleLimit) {
  978.             return true;
  979.         }
  980.         if ($sampleLimit['sl_quantity_limit'] < ($CartItemNum  +  count($Products))) {
  981.             return $this->SetCartError(150nullfalse, ['%sl_quantity_limit%' => $sampleLimit['sl_quantity_limit']]);
  982.         }
  983.         if (!$Customer $this->CommonService->getUser()) {
  984.             return true;
  985.         }
  986.         if ($this->SampleService->getOrderCountAfterPurchase($Customer->getLmCustomerId()) >= $sampleLimit['sl_no_purchase_limit']) {
  987.             return $this->SetCartError(160nullfalse, ['%sl_no_purchase_limit%' => $sampleLimit['sl_no_purchase_limit']]);
  988.         }
  989.         if ($sampleLimit['sl_number_limit'] == 0) {
  990.             return $this->SetCartError(17);
  991.         }
  992.         if ($this->SampleService->getOrderCountOfToday($Customer->getLmCustomerId()) >= $sampleLimit['sl_number_limit']) {
  993.             return $this->SetCartError(180nullfalse, ['%sl_number_limit%' => $sampleLimit['sl_number_limit']]);
  994.         }
  995.     }
  996.     protected function hasExitedGoodsSusoageOnCurrentCart()
  997.     {
  998.         $existSusoage false;
  999.         foreach ($this->cartService->getCarts() as $Cart) {
  1000.             foreach ($Cart->getCartItems() as $CartItem) {
  1001.                 $ProductCode $CartItem->getProductClass()->getCode();
  1002.                 $GoodsSusoage $this->GoodsService->getGoodsSusoageByHinban($ProductCode);
  1003.                 if ($GoodsSusoage == 1) {
  1004.                     $existSusoage true;
  1005.                     break;
  1006.                 }
  1007.             }
  1008.             if ($existSusoage) {
  1009.                 break;
  1010.             }
  1011.         }
  1012.         return $existSusoage;
  1013.     }
  1014.     protected function hasExitedGoodsSusoageOnRepeatItems(array $orderList)
  1015.     {
  1016.         $existSusoage false;
  1017.         foreach ($orderList as $item) {
  1018.             $GoodsSusoage $this->GoodsService->getGoodsSusoageById($item['goodsId']);
  1019.             if ($GoodsSusoage == 1) {
  1020.                 $existSusoage true;
  1021.                 break;
  1022.             }
  1023.         }
  1024.         return $existSusoage;
  1025.     }
  1026.     /***
  1027.      * Function use to dispath event Add product to Cart
  1028.      *
  1029.      * @param array $products
  1030.      * @param int|null $goodsId
  1031.      * @return void
  1032.      */
  1033.     private function handleDispathEventAddProductToCart(Array $products, ?int $goodsId)
  1034.     {
  1035.         $addedItemSkuId implode(','array_keys($products));
  1036.         $event = new EventArgs([
  1037.             'added_item_id' => $goodsId,
  1038.             'added_item_sku_id' => $addedItemSkuId
  1039.         ]);
  1040.         $this->eventDispatcher->dispatch($event,LmEvents::SESSION_FRONT_PRODUCT_CART_ADD_PRODUCT );
  1041.     }
  1042.     /**
  1043.     * #Route("/cart/remove_cart_items", methods={"DELETE"} )
  1044.     */
  1045.     public function removeCartItems(Request $request)
  1046.     {
  1047.         $cartItems $request->get('cartItems', []);
  1048.         if (!empty($cartItems)) {
  1049.             $this->cartService->removeCartItems($cartItems);
  1050.             return $this->json(['status' => 'OK']);
  1051.         }
  1052.         return $this->json(['status' => 'Error']);
  1053.     }
  1054.     /**
  1055.      * @return void
  1056.      * @throws \Exception
  1057.      */
  1058.     public function checkCartItemsAvailable()
  1059.     {
  1060.         //
  1061.         $cartItemIdsToBeRemoved = [];
  1062.         //
  1063.         foreach ($this->cartService->getCarts() as $Cart) {
  1064.             //
  1065.             foreach ($Cart->getCartItems() as $CartItem) {
  1066.                 /**
  1067.                  * @var SkuExtended $sku
  1068.                  */
  1069.                 $jancode = new Jancode($CartItem->getProductClass()->getId());
  1070.                 $sku SkuExtended::getInstance($jancode->getJanGoods(), $jancode->getJanId());
  1071.                 //
  1072.                 if ($sku->isNoDisplay() || $sku->getGclDisplayStatus() === GoodsColor::DISPLAY_STATUS_UNAVAILABLE || $sku->getGpDisplay() === GoodsPrice::DISPLAY_HIDDEN) {
  1073.                     //
  1074.                     $cartItemIdsToBeRemoved[] = $CartItem->getId();
  1075.                 }
  1076.             }
  1077.         }
  1078.         //
  1079.         if (!empty($cartItemIdsToBeRemoved)) {
  1080.             $this->cartService->removeCartItems($cartItemIdsToBeRemoved);
  1081.             $this->addRequestError('現在、ご購入頂けない商品が含まれていましたのでカートから削除されました。'"front.cart");
  1082.         }
  1083.     }
  1084. }