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

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.             'Contact/index.twig' => 'insertDatePickerJS',
  34.             EccubeEvents::FRONT_CONTACT_INDEX_COMPLETE => 'hookFrontContactIndexComplete',
  35.         ];
  36.     }
  37.     public function hookFrontContactIndexComplete(EventArgs $event)
  38.     {
  39.         $form $event->getArgument('form');
  40.         $data $event->getArgument('data');
  41.         $CustomerItems $this->customerPlusService->getEnabledCustomerPlusForm('contact');
  42.         foreach($CustomerItems as $CustomerItem){
  43.             if($form->has('customerplus_'.$CustomerItem->getId())){
  44.                 $value $form->get('customerplus_'.$CustomerItem->getId())->getData();
  45.                 $input_type $CustomerItem->getInputType();
  46.                 if ($input_type == CustomerItem::DATE_TYPE) {
  47.                     if($value instanceof \DateTime){
  48.                         $value $value->format('Y-m-d');
  49.                     }
  50.                 } elseif($input_type >= CustomerItem::SELECT_TYPE) {
  51.                     $Options $CustomerItem->getOptions();
  52.                     if(!is_array($value))$value = [$value];
  53.                     $ret = [];
  54.                     foreach($value as $val){
  55.                         foreach($Options as $Option){
  56.                             if($Option->getId() == $val){
  57.                                 $ret[] = $Option->getText();
  58.                                 continue;
  59.                             }
  60.                         }
  61.                     }
  62.                     $value implode(','$ret);
  63.                 }
  64.                 $data['customerplus_'.$CustomerItem->getId()] = $value;
  65.             }
  66.         }
  67.         $event->setArgument('data',$data);
  68.     }
  69. }