app/Plugin/SlnRegular4/SlnRegular4Event.php line 236

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