app/Plugin/SlnRegular4/SlnRegular4Event.php line 530

Open in your IDE?
  1. <?php
  2. namespace Plugin\SlnRegular4;
  3. use Plugin\SlnRegular4\Repository\SlnRegularPluginConfigRepository;
  4. use Plugin\SlnRegular4\Repository\SlnRegularOrderRepository;
  5. use Plugin\SlnRegular4\Repository\SlnRegularOrderToOrderRepository;
  6. use Plugin\SlnRegular4\Repository\SlnRegularSaleTypeRepository;
  7. use Plugin\SlnRegular4\Repository\SlnRegularDeliveryPriceRepository;
  8. use Plugin\SlnRegular4\Entity\ConfigSubData;
  9. use Plugin\SlnRegular4\Service\BasicItem;
  10. use Plugin\SlnRegular4\Service\RegularOrderService;
  11. use Plugin\SlnRegular4\Service\ShoppingService;
  12. use Eccube\Form\Type\PriceType;
  13. use Eccube\Entity\Master\CustomerStatus;
  14. use Eccube\Entity\Master\OrderStatus;
  15. use Eccube\Event\TemplateEvent;
  16. use Eccube\Event\EventArgs;
  17. use Eccube\Event\EccubeEvents;
  18. use Eccube\Service\CartService;
  19. use Eccube\Service\TaxRuleService;
  20. use Eccube\Common\Constant;
  21. use Eccube\Common\EccubeConfig;
  22. use Eccube\Repository\DeliveryRepository;
  23. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  24. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  25. use Symfony\Component\Validator\Constraints as Assert;
  26. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  27. use Doctrine\ORM\EntityManagerInterface;
  28. use Symfony\Component\DependencyInjection\ContainerInterface;
  29. class SlnRegular4Event implements EventSubscriberInterface
  30. {
  31.     /**
  32.      * @var EntityManagerInterface
  33.      */
  34.     private $entityManager;
  35.     /**
  36.      * @var EccubeConfig
  37.      */
  38.     protected $eccubeConfig;
  39.     /**
  40.      * @var CartService
  41.      */
  42.     private $cartService;
  43.     /**
  44.      * @var TaxRuleService
  45.      */
  46.     private $taxRuleService;
  47.     /**
  48.      * @var DeliveryRepository
  49.      */
  50.     protected $deliveryRepository;
  51.     /**
  52.      * @var SlnRegularPluginConfigRepository
  53.      */
  54.     protected $regularPluginConfigRepository;
  55.     /**
  56.      * @var SlnRegularOrderRepository
  57.      */
  58.     protected $regularOrderRepository;
  59.     /**
  60.      * @var SlnRegularOrderToOrderRepository
  61.      */
  62.     protected $regularOrderToOrderRepository;
  63.     /**
  64.      * @var SlnRegularSaleTypeRepository
  65.      */
  66.     protected $regularSaleTypeRepository;
  67.     /**
  68.      * @var SlnRegularDeliveryPriceRepository
  69.      */
  70.     protected $regularDeliveryPriceRepository;
  71.     /**
  72.      * @var BasiItem
  73.      */
  74.     protected $basicItem;
  75.     /**
  76.      * @var RegularOrderService
  77.      */
  78.     protected $regularOrderService;
  79.     /**
  80.      * @var ShoppingService
  81.      */
  82.     protected $shoppingService;
  83.     
  84.     /**
  85.      * @var ContainerInterface
  86.      */
  87.     private $container;
  88.     
  89.     /**
  90.      * @var EventDispatcherInterface
  91.      */
  92.     private $eventDispatcher;
  93.     /**
  94.      * コンストラクタ
  95.      */
  96.     public function __construct(
  97.         EntityManagerInterface $entityManager,
  98.         EccubeConfig $eccubeConfig,
  99.         CartService $cartService,
  100.         TaxRuleService $taxRuleService,
  101.         DeliveryRepository $deliveryRepository,
  102.         SlnRegularPluginConfigRepository $regularPluginConfigRepository,
  103.         SlnRegularOrderRepository $regularOrderRepository,
  104.         SlnRegularOrderToOrderRepository $regularOrderToOrderRepository,
  105.         SlnRegularSaleTypeRepository $regularSaleTypeRepository,
  106.         SlnRegularDeliveryPriceRepository $regularDeliveryPriceRepository,
  107.         BasicItem $basicItem,
  108.         RegularOrderService $regularOrderService,
  109.         ShoppingService $shoppingService,
  110.         ContainerInterface $container,
  111.         EventDispatcherInterface $eventDispatcher
  112.     ) {
  113.         $this->entityManager $entityManager;
  114.         $this->eccubeConfig $eccubeConfig;
  115.         $this->cartService $cartService;
  116.         $this->taxRuleService $taxRuleService;
  117.         $this->deliveryRepository $deliveryRepository;
  118.         $this->regularPluginConfigRepository $regularPluginConfigRepository;
  119.         $this->regularOrderRepository $regularOrderRepository;
  120.         $this->regularOrderToOrderRepository $regularOrderToOrderRepository;
  121.         $this->regularSaleTypeRepository $regularSaleTypeRepository;
  122.         $this->regularDeliveryPriceRepository $regularDeliveryPriceRepository;
  123.         $this->basicItem $basicItem;
  124.         $this->regularOrderService $regularOrderService;
  125.         $this->shoppingService $shoppingService;
  126.         $this->container $container;
  127.         $this->eventDispatcher $eventDispatcher;
  128.     }
  129.     /**
  130.      * リッスンしたいサブスクライバのイベント名の配列を返します。
  131.      * 配列のキーはイベント名、値は以下のどれかをしてします。
  132.      * - 呼び出すメソッド名
  133.      * - 呼び出すメソッド名と優先度の配列
  134.      * - 呼び出すメソッド名と優先度の配列の配列
  135.      * 優先度を省略した場合は0
  136.      *
  137.      * 例:
  138.      * - array('eventName' => 'methodName')
  139.      * - array('eventName' => array('methodName', $priority))
  140.      * - array('eventName' => array(array('methodName1', $priority), array('methodName2')))
  141.      *
  142.      * {@inheritdoc}
  143.      */
  144.     public static function getSubscribedEvents()
  145.     {
  146.         return [
  147.             '@admin/Order/edit.twig' => 'onAdminOrderEditTwig',
  148.             '@admin/Setting/Shop/delivery.twig' => 'onAdminSettingShopDeliveryTwig',
  149.             '@admin/Setting/Shop/shop_master.twig' => 'onAdminSettingShopShopMasterTwig',
  150.             EccubeEvents::ADMIN_SETTING_SHOP_SHOP_INDEX_INITIALIZE  => 'onAdminSettingShopInitialize',
  151.             EccubeEvents::ADMIN_SETTING_SHOP_SHOP_INDEX_COMPLETE => 'onAdminSettingShopComplete',
  152.             'Product/list.twig' => 'onProductListTwig',
  153.             'Product/detail.twig' => 'onProductDetailTwig',
  154.             'Shopping/login.twig' => 'onShoppingLoginTwig',
  155.             'Shopping/index.twig' => 'onShoppingIndexTwig',
  156.             'Shopping/confirm.twig' => 'onShoppingConfirmTwig',
  157.             'Mypage/index.twig' => 'onMypageTwig',
  158.             'Mypage/history.twig' => 'onMypageHistoryTwig',
  159.             'Mypage/favorite.twig' => 'onMypageTwig',
  160.             'Mypage/change.twig' => 'onMypageTwig',
  161.             'Mypage/change_complete.twig' => 'onMypageTwig',
  162.             'Mypage/delivery.twig' => 'onMypageTwig',
  163.             'Mypage/delivery_edit.twig' => 'onMypageTwig',
  164.             'Mypage/withdraw.twig' => 'onMypageTwig',
  165.             'Mypage/withdraw_confirm.twig' => 'onMypageTwig',
  166.             '@SlnPayment4/sln_edit_card.twig' => 'onMypageTwig'// 決済4.0用
  167.             '@SlnPayment41/sln_edit_card.twig' => 'onMypageTwig'// 決済4.1用
  168.             '@SlnRegular4/Mypage/regular_order.twig' => 'onMypageTwig',
  169.             '@SlnRegular4/Mypage/regular_history.twig' => 'onMypageTwig',
  170.             'sln.front.shopping.confirm.processing' => 'onSlnFrontShoppingConfirmProcessing',
  171.             'sln.payment.util.merchant_free' => 'onSlnPaymentUtilMerchantFree',
  172.             'sln.payment.shopping.add_mem' => 'onSlnPaymentShoppingAddMem',
  173.             'sln.payment.shopping.add_mem_view' => 'onSlnPaymentShoppingAddMemView',
  174.             EccubeEvents::ADMIN_CUSTOMER_EDIT_INDEX_INITIALIZE => 'onAdminCustomerEditIndexInitialize',
  175.             EccubeEvents::FRONT_MYPAGE_WITHDRAW_INDEX_COMPLETE => 'onFrontMypageWithdrawComplete',
  176.         ];
  177.     }
  178.     /**
  179.      * 管理画面 - 受注登録画面介入
  180.      */
  181.     public function onAdminOrderEditTwig(TemplateEvent $event) {
  182.         $Order $event->getParameter('Order');
  183.         $OrderToOrders $this->regularOrderToOrderRepository->findBy(['Order' => $Order]);
  184.         $RegularOrders = [];
  185.         foreach ($OrderToOrders as $OrderToOrder) {
  186.             $RegularOrders[] = $OrderToOrder->getRegularOrder();
  187.         }
  188.         if (count($RegularOrders)) {
  189.             $event->setParameter('RegularOrders'$RegularOrders);
  190.             $event->setParameter('terminalStatus'$this->basicItem->getRegularStatus());
  191.             $event->addSnippet('@SlnRegular4/admin/Order/edit.twig');
  192.         }
  193.     }
  194.     /**
  195.      * 管理画面 - 配送方法一覧画面介入
  196.      */
  197.     public function onAdminSettingShopDeliveryTwig(TemplateEvent $event) {
  198.         $slnSaleTypeFlagMap = [];
  199.         
  200.         $Deliveries $this->deliveryRepository->findBy([], ['sort_no' => 'DESC']);
  201.         
  202.         foreach ($Deliveries as $Delivery) {
  203.             $saleTypes $this->regularSaleTypeRepository->findBy([
  204.                 'saleTypeId' => $Delivery->getSaleType()->getId(),
  205.             ]);
  206.             $slnSaleTypeFlagMap[$Delivery->getId()] = !empty($saleTypes);
  207.         }
  208.         // 定期購入販売種別フラグマップの設定
  209.         $event->setParameter('sln_sale_type_flag_map'$slnSaleTypeFlagMap);
  210.         $event->addSnippet('@SlnRegular4/admin/delivery.twig');
  211.     }
  212.     /**
  213.      * 管理画面 - 店舗マスター編集画面介入
  214.      * @param TemplateEvent $event
  215.      */
  216.     public function onAdminSettingShopShopMasterTwig(TemplateEvent $event)
  217.     {
  218.         $event->addSnippet('@SlnRegular4/admin/shop_master.twig');
  219.     }
  220.     /**
  221.      * 管理画面 - 店舗マスター編集初期化
  222.      * @param EventArgs $event
  223.      */
  224.     public function onAdminSettingShopInitialize(EventArgs $event)
  225.     {
  226.         $price_len $this->eccubeConfig->get('eccube_price_len');
  227.         $builder $event->getArgument('builder');
  228.         // 送料設定
  229.         $builder->add('delivery_free_amount2'PriceType::class, array(
  230.             'label' => '定期二回目送料無料条件(金額)',
  231.             'required' => false,
  232.             'currency' => 'JPY',
  233.             'scale'  => 0,
  234.             'mapped' => false,
  235.             'constraints' => array(
  236.                 new Assert\Length(array(
  237.                     'max' => $price_len,
  238.                 )),
  239.                 new Assert\Regex(array(
  240.                     'pattern' => "/^\d+$/u",
  241.                     'message' => 'form.type.numeric.invalid'
  242.                 )),
  243.             ),
  244.         ))
  245.         ->add('delivery_free_quantity2'IntegerType::class, array(
  246.             'label' => '定期二回目送料無料条件(数量)',
  247.             'required' => false,
  248.             'mapped' => false,
  249.             'constraints' => array(
  250.                 new Assert\Regex(array(
  251.                     'pattern' => "/^\d+$/u",
  252.                     'message' => 'form.type.numeric.invalid'
  253.                 )),
  254.             ),
  255.         ));
  256.         
  257.         /* @var $configRepository \Plugin\SlnRegular\Repository\PlgSlnRegularPluginConfigRepository */
  258.         $configdata $this->regularPluginConfigRepository->getConfig();
  259.         
  260.         // 初期値を設定
  261.         $builder->get('delivery_free_amount2')->setData($configdata->getDeliveryFreeAmount2());
  262.         $builder->get('delivery_free_quantity2')->setData($configdata->getDeliveryFreeQuantity2());
  263.     }
  264.     
  265.     /**
  266.      * 管理画面 - 店舗マスター編集保存
  267.      * @param EventArgs $event
  268.      */
  269.     public function onAdminSettingShopComplete(EventArgs $event)
  270.     {
  271.         $form $event->getArgument('form');
  272.         //無料価格条件
  273.         $deliveryFreeAmount2 $form['delivery_free_amount2']->getData();
  274.         //無料個数条件
  275.         $deliveryFreeQuantity2 $form['delivery_free_quantity2']->getData();
  276.         /* @var $configRepository \Plugin\SlnRegular\Repository\PlgSlnRegularPluginConfigRepository */
  277.         $configdata $this->regularPluginConfigRepository->getConfig();
  278.         $configdata->setDeliveryFreeAmount2($deliveryFreeAmount2);
  279.         $configdata->setDeliveryFreeQuantity2($deliveryFreeQuantity2);
  280.         $this->regularPluginConfigRepository->saverConfig($configdatafalse);
  281.     }
  282.     /**
  283.      * 管理画面 - 商品編集画面介入
  284.      * @param TemplateEvent $event
  285.      */
  286.     public function onAdminProductTwig(TemplateEvent $event) {
  287.         $event->addSnippet('@SlnRegular4/admin/product.twig');
  288.     }
  289.     /**
  290.      * 管理画面 - 商品編集画面初期化
  291.      * @param EventArgs $event
  292.      */
  293.     public function onAdminProductEditInitialize(EventArgs $event)
  294.     {
  295.         /* @var $Product \Eccube\Entity\Product */
  296.         $Product $event->getArgument('Product');
  297.         $has_class $Product->hasProductClass();   //商品クラスが規格クラスを持っているかどうか
  298.         
  299.         if (!$has_class) {
  300.             
  301.             $builder $event->getArgument('builder')->get('class');
  302.             
  303.             $builder->add('price2'PriceType::class, array(
  304.                 'label' => '2回目以降の販売価格',
  305.                 'currency' => 'JPY',
  306.                 'scale' => 0,
  307.                 'mapped' => false,
  308.                 'constraints' => array(
  309.                     new Assert\Length(array(
  310.                         'max' => 10,
  311.                     )),
  312.                     new Assert\Regex(array(
  313.                         'pattern' => "/^\d+$/u",
  314.                         'message' => 'form.type.numeric.invalid'
  315.                     )),
  316.                 ),
  317.             ));
  318.             
  319.             // 初期値を設定
  320.             $productClasses $Product->getProductClasses();
  321.             $DeliveryPrice $this->regularDeliveryPriceRepository->findOrCreate($Product->getId(), $productClasses[0]->getId());
  322.             $builder->get('price2')->setData($DeliveryPrice->getPrice2());
  323.         }
  324.     }
  325.     /**
  326.      * 管理画面 - 商品編集画面初期化
  327.      * @param EventArgs $event
  328.      */
  329.     public function onAdminProductEditComplete(EventArgs $event)
  330.     {
  331.         /* @var $Product \Eccube\Entity\Product */
  332.         $Product $event->getArgument('Product');
  333.         $has_class $Product->hasProductClass();
  334.         
  335.         if (!$has_class) {//商品規格存在していない場合
  336.             $form $event->getArgument('form');
  337.             //定期購入二回目価格
  338.             $price2 $form->get('class')->get('price2')->getData();
  339.             
  340.             $productClasses $Product->getProductClasses();
  341.             $DeliveryPrice $this->regularDeliveryPriceRepository->findOrCreate($Product->getId(), $productClasses[0]->getId());
  342.             
  343.             $DeliveryPrice->setPrice2($price2);
  344.             
  345.             $this->entityManager->persist($DeliveryPrice);
  346.             $this->entityManager->flush();
  347.         }
  348.     }
  349.     /**
  350.      * フロント画面 - 商品一覧画面介入
  351.      */
  352.     public function onProductListTwig(TemplateEvent $event) {
  353.         $pagination $event->getParameter('pagination');
  354.         $hasPrice2Data = [];
  355.         $productData = [];
  356.         foreach ($pagination as $Product) {
  357.             $hasPrice2 false;
  358.             $productInfo = [];
  359.             $price2IncTaxs = [];
  360.             $price02IncTaxs = [];
  361.             foreach ($Product->getProductClasses() as $ProductClass) {
  362.                 $key $this->getProductClassKey($Product$ProductClass);
  363.                 if (!is_null($ProductClass->getSlnRegularPrice2()) && $this->regularSaleTypeRepository->isRegularProductClass($ProductClass)) {
  364.                     $hasPrice2 true;
  365.                     $price2IncTax $this->getPrice2IncTax($Product$ProductClass);
  366.                     $price2IncTaxs[$key] = $price2IncTax;
  367.                     
  368.                 }
  369.                 $price02IncTax $this->getPrice02IncTax($Product$ProductClass);
  370.                 $price02IncTaxs[$key] = $price02IncTax;
  371.             }
  372.             if (count($price2IncTaxs) > 0) {
  373.                 $productInfo['price2IncTaxMin'] = min($price2IncTaxs);
  374.                 $productInfo['price2IncTaxMax'] = max($price2IncTaxs);
  375.             }
  376.             $productInfo['price02IncTaxMin'] = min($price02IncTaxs);
  377.             $productInfo['price02IncTaxMax'] = max($price02IncTaxs);
  378.             if ($hasPrice2) {
  379.                 $hasClassCat1 count($Product->getClassCategories1()) > 0;
  380.                 $hasClassCat2 false;
  381.                 if ($hasClassCat1) {
  382.                     $hasClassCat2 $Product->getProductClasses()[0]->hasClassCategory2();
  383.                 }
  384.                 $productInfo['hasClassCat1'] = $hasClassCat1;
  385.                 $productInfo['hasClassCat2'] = $hasClassCat2;
  386.                 $productInfo['price2IncTaxs'] = $price2IncTaxs;
  387.                 $productInfo['price02IncTaxs'] = $price02IncTaxs;
  388.                 $productData[$Product->getId()] = $productInfo;
  389.             }
  390.             $hasPrice2Data[$Product->getId()] = $hasPrice2;
  391.         }
  392.         $event->setParameter('hasPrice2Data'$hasPrice2Data);
  393.         $event->setParameter('productData'$productData);
  394.         $event->addSnippet('@SlnRegular4/Product/list.twig');
  395.     }
  396.     public function getPrice2IncTax($Product$ProductClass) {
  397.         return $this->taxRuleService->getPriceIncTax($ProductClass->getSlnRegularPrice2(), $Product$ProductClass);
  398.     }
  399.     public function getPrice02IncTax($Product$ProductClass) {
  400.         return $this->taxRuleService->getPriceIncTax($ProductClass->getPrice02(), $Product$ProductClass);
  401.     }
  402.     public function getProductClassKey($Product$ProductClass) {
  403.         $key $Product->getId();
  404.         if ($ProductClass->hasClassCategory1()) {
  405.             $key $key '_' $ProductClass->getClassCategory1()->getId();
  406.             if ($ProductClass->hasClassCategory2()) {
  407.                 $key $key '_' $ProductClass->getClassCategory2()->getId();
  408.             }
  409.         }
  410.         return $key;
  411.     }
  412.     /**
  413.      * フロント画面 - 商品詳細画面介入
  414.      */
  415.     public function onProductDetailTwig(TemplateEvent $event) {
  416.         $Product $event->getParameter('Product');
  417.         $hasPrice2 false;
  418.         $productInfo = [];
  419.         $price2IncTaxs = [];
  420.         $price02IncTaxs = [];
  421.         foreach ($Product->getProductClasses() as $ProductClass) {
  422.             $key $this->getProductClassKey($Product$ProductClass);
  423.             if (!is_null($ProductClass->getSlnRegularPrice2()) && $this->regularSaleTypeRepository->isRegularProductClass($ProductClass)) {
  424.                 $hasPrice2 true;
  425.                 $price2IncTax $this->getPrice2IncTax($Product$ProductClass);
  426.                 $price2IncTaxs[$key] = $price2IncTax;
  427.                 $price02IncTax $this->getPrice02IncTax($Product$ProductClass);
  428.                 $price02IncTaxs[$key] = $price02IncTax;
  429.             }
  430.         }
  431.         if (count($price2IncTaxs) > 0) {
  432.             $productInfo['price2IncTaxMin'] = min($price2IncTaxs);
  433.             $productInfo['price2IncTaxMax'] = max($price2IncTaxs);
  434.         }
  435.         if ($hasPrice2) {
  436.             $hasClassCat1 count($Product->getClassCategories1()) > 0;
  437.             $hasClassCat2 false;
  438.             if ($hasClassCat1) {
  439.                 $hasClassCat2 $Product->getProductClasses()[0]->hasClassCategory2();
  440.             }
  441.             $event->setParameter('hasClassCat1'$hasClassCat1);
  442.             $event->setParameter('hasClassCat2'$hasClassCat2);
  443.             $event->setParameter('productInfo'$productInfo);
  444.             $event->setParameter('price2IncTaxs'$price2IncTaxs);
  445.             $event->setParameter('price02IncTaxs'$price02IncTaxs);
  446.             $event->addSnippet('@SlnRegular4/Product/detail.twig');
  447.         }
  448.     }
  449.     /**
  450.      * フロント画面 - 購入時ログイン画面介入
  451.      */
  452.     public function onShoppingLoginTwig(TemplateEvent $event) {
  453.         $Cart $this->cartService->getCart();
  454.         $CartItems $Cart->getCartItems();
  455.         foreach ($CartItems as $CartItem) {
  456.             $ProductClass $CartItem->getProductClass();
  457.             if ($ProductClass) {
  458.                 if ($this->regularSaleTypeRepository->isRegularProductClass($ProductClass)) {
  459.                     $event->addSnippet('@SlnRegular4/Shopping/login.twig');
  460.                     break;
  461.                 }
  462.             }
  463.         }
  464.     }
  465.     /**
  466.      * フロント画面 - 購入画面介入
  467.      */
  468.     public function onShoppingIndexTwig(TemplateEvent $event) {
  469.         $Order $event->getParameter('Order');
  470.         if ($this->regularSaleTypeRepository->isRegularOrder($Order)) {
  471.             $event->addSnippet('@SlnRegular4/Shopping/index.twig');
  472.         }
  473.     }
  474.     /**
  475.      * フロント画面 - 購入確認画面介入
  476.      */
  477.     public function onShoppingConfirmTwig(TemplateEvent $event) {
  478.         $Order $event->getParameter('Order');
  479.         $this->shoppingService->saveRegularOrder($Order'confirm');
  480.         if ($this->regularSaleTypeRepository->isRegularOrder($Order)) {
  481.             $event->setParameter('arrRegularTypeText'$this->basicItem->getRegularTypeText());
  482.             $event->setParameter('arrRegularDeliveryDateText'$this->basicItem->getRegularDeliveryDateText());
  483.             $event->addSnippet('@SlnRegular4/Shopping/confirm.twig');
  484.         }
  485.     }
  486.     /**
  487.      * フロント画面 - マイページ画面介入
  488.      */
  489.     public function onMypageTwig(TemplateEvent $event) {
  490.         $event->addSnippet('@SlnRegular4/Mypage/add_menu_item.twig');
  491.     }
  492.     /**
  493.      * フロント画面 - マイページ購入履歴詳細画面介入
  494.      */
  495.     public function onMypageHistoryTwig(TemplateEvent $event) {
  496.         $this->onMypageTwig($event);
  497.         $data $event->getParameters();
  498.         
  499.         /* @var $Order \Eccube\Entity\Order */
  500.         $Order $data['Order'];
  501.         $RegularOrders $this->regularOrderToOrderRepository
  502.                                     ->findBy(array('Order' => $Order));
  503.         if (count($RegularOrders)) {
  504.             /* @var $RegularOrder \Plugin\SlnRegular4\Entity\SlnRegularOrderToOrder */
  505.             foreach ($RegularOrders as $RegularOrder) {
  506.                 try {
  507.                     $data['regularOrders'][] = $RegularOrder;
  508.                 } catch (\Exception $e) {
  509.                 }
  510.             }
  511.         }
  512.         $event->setParameters($data);
  513.         if (count($RegularOrders)) {
  514.             $event->addSnippet('@SlnRegular4/Mypage/history.twig');
  515.         }
  516.     }
  517.     /**
  518.      * ソニー決済完了時
  519.      * @param EventArgs $event
  520.      */
  521.     public function onSlnFrontShoppingConfirmProcessing(EventArgs $event)
  522.     {
  523.         $Order $event->getArgument('Order');
  524.         
  525.         $this->entityManager->getConnection()->beginTransaction();
  526.         /* @var $RegularOrder \Plugin\SlnRegular\Entity\PlgSlnRegularOrder */
  527.         $RegularOrder $this->regularOrderRepository
  528.                                 ->findOneBy(array('createOrder' => $Order));
  529.         
  530.         if ($RegularOrder) {
  531.             if ($Order->getOrderStatus()->getId() == OrderStatus::PROCESSING || $Order->getOrderStatus()->getId() == OrderStatus::PENDING) {
  532.                 $RegularOrder->setTerminalStatus(5);
  533.             } else {
  534.                 $RegularOrder->setTerminalStatus(1);
  535.             }
  536.             $RegularOrder->setOrderDate($Order->getOrderDate());
  537.             
  538.             $this->entityManager->persist($RegularOrder);
  539.             $this->entityManager->flush();
  540.         }
  541.         $this->entityManager->getConnection()->commit();
  542.         
  543.         if ($RegularOrder) {//定期購入場合
  544.             //定期メールを送信する
  545.             $this->shoppingService->sendRegularOrderMail($RegularOrder$Order$event->getRequest()->getSession());
  546.         }
  547.     }
  548.     
  549.     /**
  550.      * 送信情報を変更する
  551.      * @param EventArgs $event
  552.      */
  553.     public function onSlnPaymentUtilMerchantFree(EventArgs $event)
  554.     {
  555.         /* @var $Order \Eccube\Entity\Order */
  556.         /* @var $Basic \Plugin\SlnPayment\Service\SlnAction\Content\Credit\Request\Auth */
  557.         $Order $event->getArgument('Order');
  558.         $Basic $event->getArgument('Basic');
  559.         
  560.         /* @var $RegularOrderToOrders \Plugin\SlnRegular\Entity\PlgSlnRegularOrderToOrder[] */
  561.         $RegularOrderToOrders $this->regularOrderToOrderRepository->findBy(array('Order' => $Order));
  562.         if (count($RegularOrderToOrders)) {
  563.             $ReIds = array();
  564.             foreach ($RegularOrderToOrders as $RegularOrderToOrder) {
  565.                 $ReIds[] = $RegularOrderToOrder->getRegularOrderId();
  566.             }
  567.           
  568.             if (count($ReIds)) {
  569.                 $Basic['MerchantFree2'] = sprintf("%s|%s|%s"join($ReIds','), Constant::VERSION$Order->getCustomer() ? $Order->getCustomer()->getId() : null);
  570.             }
  571.         }
  572.     }
  573.     
  574.     public function onSlnPaymentShoppingAddMemView(EventArgs $event)
  575.     {
  576.         /* @var $Order \Eccube\Entity\Order */
  577.         $Order $event->getArgument('Order');
  578.         
  579.         /* @var $RegularOrderToOrders \Plugin\SlnRegular\Entity\PlgSlnRegularOrderToOrder[] */
  580.         $RegularOrderToOrders $this->regularOrderToOrderRepository->findBy(array('Order' => $Order));
  581.         
  582.         if (count($RegularOrderToOrders)) {
  583.             $event->setArgument('IsAddMemView'false);
  584.         }
  585.     }
  586.     
  587.     /**
  588.      * 定期商品購入時にクレジットカードを登録する
  589.      * @param EventArgs $event
  590.      */
  591.     public function onSlnPaymentShoppingAddMem(EventArgs $event)
  592.     {
  593.         /* @var $Order \Eccube\Entity\Order */
  594.         $Order $event->getArgument('Order');
  595.         
  596.         /* @var $RegularOrderToOrders \Plugin\SlnRegular\Entity\PlgSlnRegularOrderToOrder[] */
  597.         $RegularOrderToOrders $this->regularOrderToOrderRepository->findBy(array('Order' => $Order));
  598.         
  599.         if (count($RegularOrderToOrders)) {
  600.             $AddMem $event->getArgument('AddMem');
  601.             $AddMem[0] = 1;
  602.             $event->setArgument('AddMem'$AddMem);
  603.         }
  604.     }
  605.     /**
  606.      * 会員退会時に定期受注のステータス変更処理(Admin/CustomerEditController)
  607.      */
  608.     public function onAdminCustomerEditIndexInitialize(EventArgs $event)
  609.     {
  610.         $form $event->getArgument("builder")->getForm();
  611.         $oldStatusId $form->getData()
  612.             ->getStatus()
  613.             ->getId();
  614.         // 削除完了時に実行
  615.         $this->eventDispatcher->addListener(EccubeEvents::ADMIN_CUSTOMER_EDIT_INDEX_COMPLETE, function (EventArgs $event) use ($oldStatusId) {
  616.             $form $event->getArgument("form");
  617.             $newStatusId $form->getData()
  618.                 ->getStatus()
  619.                 ->getId();
  620.             
  621.             if ($oldStatusId != $newStatusId && $newStatusId == CustomerStatus::WITHDRAWING) {
  622.                 $user $event->getArgument("Customer");
  623.                 $RegularOrders $this->regularOrderRepository->findBy(array('Customer' => $user));
  624.                 
  625.                 //削除失敗時は処理を実行しない
  626.                 if (count($RegularOrders) && $this->entityManager->isOpen()) {
  627.                     $this->entityManager->getConnection()->beginTransaction();
  628.                     
  629.                     foreach ($RegularOrders as $RegularOrder) {
  630.                         $RegularOrder->setTerminalStatus(3); // 解約
  631.                     }
  632.                     
  633.                     $this->entityManager->flush();
  634.                     $this->entityManager->getConnection()->commit();
  635.                 }
  636.             }
  637.         });
  638.     }
  639.     
  640.     /**
  641.      * 会員退会時に定期受注のステータス変更処理(Mypage/WithdrawController)
  642.      */
  643.     public function onFrontMypageWithdrawComplete(EventArgs $event){
  644.         $user $this->container->get('security.token_storage')->getToken()->getUser();
  645.         $RegularOrders $this->regularOrderRepository->findBy(array('Customer' => $user));
  646.         
  647.         //削除失敗時は処理を実行しない
  648.         if (count($RegularOrders) && $this->entityManager->isOpen()) {
  649.             $this->entityManager->getConnection()->beginTransaction();
  650.             
  651.             foreach ($RegularOrders as $RegularOrder) {
  652.                 $RegularOrder->setTerminalStatus(3); // 解約
  653.             }
  654.             
  655.             $this->entityManager->flush();
  656.             $this->entityManager->getConnection()->commit();
  657.         }
  658.     }
  659. }