app/Plugin/OrderPlus42/Event/ShoppingEvent.php line 48

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : OrderPlus
  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\OrderPlus42\Event;
  12. use Eccube\Event\EccubeEvents;
  13. use Eccube\Event\EventArgs;
  14. use Eccube\Event\TemplateEvent;
  15. use Symfony\Component\DependencyInjection\ContainerInterface;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. class ShoppingEvent implements EventSubscriberInterface
  18. {
  19.     private $container;
  20.     public function __construct(
  21.             ContainerInterface $container
  22.             )
  23.     {
  24.         $this->container $container;
  25.     }
  26.     /**
  27.      * @return array
  28.      */
  29.     public static function getSubscribedEvents()
  30.     {
  31.         return [
  32.             'Shopping/index.twig' => 'onTemplateShoppingIndex',
  33.             EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_COMPLETE => ['hookFrontShoppingShippingMultipleComplete',-10],
  34.                ];
  35.     }
  36.     public function onTemplateShoppingIndex(TemplateEvent $event)
  37.     {
  38.         $twig '@OrderPlus42/default/datepicker_js.twig';
  39.         $event->addAsset($twig);
  40.     }
  41.     public function hookFrontShoppingShippingMultipleComplete(EventArgs $event)
  42.     {
  43.         $entityManager $this->container->get('doctrine.orm.entity_manager');
  44.         $form $event->getArgument('form');
  45.         $Order $event->getArgument('Order');
  46.         $data $form['shipping_multiple'];
  47.         foreach($Order->getShippings() as $Shipping){
  48.             foreach ($data as $multiples) {
  49.                 $OrderItem $multiples->getData();
  50.                 $orgShipping $OrderItem->getShipping();
  51.                 $orgShippingName $orgShipping->getShippingMultipleDefaultName();
  52.                 $shippingName $Shipping->getShippingMultipleDefaultName();
  53.                 if($orgShippingName == $shippingName){
  54.                     foreach($orgShipping->getShippingBridges() as $shippingBridge){
  55.                         $orgShipping->removeShippingBridge($shippingBridge);
  56.                         $Shipping->addShippingBridge($shippingBridge);
  57.                         $shippingBridge->setShipping($Shipping);
  58.                     }
  59.                 }
  60.             }
  61.             $entityManager->persist($Shipping);
  62.             $entityManager->flush($Shipping);
  63.         }
  64.     }
  65. }