<?php
/*
* Plugin Name : OrderPlus
*
* Copyright (C) BraTech Co., Ltd. All Rights Reserved.
* http://www.bratech.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\OrderPlus42\Event;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Event\TemplateEvent;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ShoppingEvent implements EventSubscriberInterface
{
private $container;
public function __construct(
ContainerInterface $container
)
{
$this->container = $container;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'Shopping/index.twig' => 'onTemplateShoppingIndex',
EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_COMPLETE => ['hookFrontShoppingShippingMultipleComplete',-10],
];
}
public function onTemplateShoppingIndex(TemplateEvent $event)
{
$twig = '@OrderPlus42/default/datepicker_js.twig';
$event->addAsset($twig);
}
public function hookFrontShoppingShippingMultipleComplete(EventArgs $event)
{
$entityManager = $this->container->get('doctrine.orm.entity_manager');
$form = $event->getArgument('form');
$Order = $event->getArgument('Order');
$data = $form['shipping_multiple'];
foreach($Order->getShippings() as $Shipping){
foreach ($data as $multiples) {
$OrderItem = $multiples->getData();
$orgShipping = $OrderItem->getShipping();
$orgShippingName = $orgShipping->getShippingMultipleDefaultName();
$shippingName = $Shipping->getShippingMultipleDefaultName();
if($orgShippingName == $shippingName){
foreach($orgShipping->getShippingBridges() as $shippingBridge){
$orgShipping->removeShippingBridge($shippingBridge);
$Shipping->addShippingBridge($shippingBridge);
$shippingBridge->setShipping($Shipping);
}
}
}
$entityManager->persist($Shipping);
$entityManager->flush($Shipping);
}
}
}