app/Plugin/CustomerPlus42/Event/AbstractEvent.php line 32

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\TemplateEvent;
  13. use Plugin\CustomerPlus42\Entity\CustomerItem;
  14. use Plugin\CustomerPlus42\Entity\CustomerData;
  15. use Plugin\CustomerPlus42\Entity\CustomerDataDetail;
  16. use Plugin\CustomerPlus42\Entity\ShippingCustom;
  17. use Symfony\Component\DependencyInjection\ContainerInterface;
  18. class AbstractEvent
  19. {
  20.     protected $container;
  21.     public function __construct(
  22.             ContainerInterface $container
  23.             )
  24.     {
  25.         $this->container $container;
  26.     }
  27.     public function insertDatePickerJS(TemplateEvent $event)
  28.     {
  29.         $twig '@CustomerPlus42/default/datepicker_js.twig';
  30.         $event->addAsset($twig);
  31.     }
  32.     public function insertDatePickerJSAdmin(TemplateEvent $event)
  33.     {
  34.         $twig '@CustomerPlus42/admin/datepicker_js.twig';
  35.         $event->addAsset($twig);
  36.     }
  37.     public function setShippingFromCustomerAddress($Shipping$CustomerAddress)
  38.     {
  39.         $entityManager $this->container->get('doctrine.orm.entity_manager');
  40.         $ShippingCustoms $Shipping->getShippingCustoms();
  41.         if(!is_null($ShippingCustoms) && count($ShippingCustoms) > 0){
  42.             foreach($ShippingCustoms as $ShippingCustom){
  43.                 $Shipping->removeShippingCustom($ShippingCustom);
  44.                 $entityManager->remove($ShippingCustom);
  45.             }
  46.         }
  47.         $entityManager->flush();
  48.         $CustomerAddressCustoms $CustomerAddress->getCustomerAddressCustoms();
  49.         if(!is_null($CustomerAddressCustoms)){
  50.             foreach($CustomerAddressCustoms as $CustomerAddressCustom){
  51.                 $CustomerItem $entityManager->getRepository(CustomerItem::class)->find($CustomerAddressCustom->getCustomerItemId());
  52.                 $CustomerData = new CustomerData();
  53.                 $CustomerData->setCustomerItem($CustomerItem);
  54.                 foreach($CustomerAddressCustom->getCustomerData()->getDetails() as $Detail){
  55.                     $shippingDetail = new CustomerDataDetail();
  56.                     $shippingDetail->setCustomerData($CustomerData)
  57.                                 ->setValue($Detail->getValue())
  58.                                 ->setDateValue($Detail->getDateValue())
  59.                                 ->setNumValue($Detail->getNumValue());
  60.                     $CustomerData->addDetail($shippingDetail);
  61.                 }
  62.                 $ShippingCustom = new ShippingCustom();
  63.                 $ShippingCustom->setCustomerData($CustomerData)
  64.                             ->setCustomerItemId($CustomerAddressCustom->getCustomerItemId())
  65.                             ->setShipping($Shipping);
  66.                 $Shipping->addShippingCustom($ShippingCustom);
  67.                 $entityManager->persist($CustomerData);
  68.                 $entityManager->persist($ShippingCustom);
  69.             }
  70.         }
  71.         $entityManager->flush();
  72.     }
  73. }