app/Plugin/CustomerPlus42/Event/ContactEvent.php line 42

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : CustomerPlus4
  4. *
  5. * Copyright (C) BraTech Co., Ltd. All Rights Reserved.
  6. * http://www.bratech.co.jp/
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Plugin\CustomerPlus42\Event;
  12. use Eccube\Event\EccubeEvents;
  13. use Eccube\Event\EventArgs;
  14. use Plugin\CustomerPlus42\Entity\CustomerItem;
  15. use Plugin\CustomerPlus42\Event\AbstractEvent;
  16. use Plugin\CustomerPlus42\Service\CustomerPlusService;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. class ContactEvent extends AbstractEvent implements EventSubscriberInterface
  19. {
  20.     private $customerPlusService;
  21.     public function __construct(
  22.             CustomerPlusService $customerPlusService
  23.             )
  24.     {
  25.         $this->customerPlusService $customerPlusService;
  26.     }
  27.     /**
  28.      * @return array
  29.      */
  30.     public static function getSubscribedEvents()
  31.     {
  32.         return [
  33.             EccubeEvents::FRONT_CONTACT_INDEX_COMPLETE => 'hookFrontContactIndexComplete',
  34.         ];
  35.     }
  36.     public function hookFrontContactIndexComplete(EventArgs $event)
  37.     {
  38.         $form $event->getArgument('form');
  39.         $data $event->getArgument('data');
  40.         $CustomerItems $this->customerPlusService->getEnabledCustomerPlusForm('contact');
  41.         foreach($CustomerItems as $CustomerItem){
  42.             if($form->has('customerplus_'.$CustomerItem->getId())){
  43.                 $value $form->get('customerplus_'.$CustomerItem->getId())->getData();
  44.                 $input_type $CustomerItem->getInputType();
  45.                 if ($input_type == CustomerItem::DATE_TYPE) {
  46.                     if($value instanceof \DateTime){
  47.                         $value $value->format('Y-m-d');
  48.                     }
  49.                 } elseif($input_type >= CustomerItem::SELECT_TYPE) {
  50.                     $Options $CustomerItem->getOptions();
  51.                     if(!is_array($value))$value = [$value];
  52.                     $ret = [];
  53.                     foreach($value as $val){
  54.                         foreach($Options as $Option){
  55.                             if($Option->getId() == $val){
  56.                                 $ret[] = $Option->getText();
  57.                                 continue;
  58.                             }
  59.                         }
  60.                     }
  61.                     $value implode(','$ret);
  62.                 }
  63.                 $data['customerplus_'.$CustomerItem->getId()] = $value;
  64.             }
  65.         }
  66.         $event->setArgument('data',$data);
  67.     }
  68. }