<?php
/*
* Plugin Name : CustomerPlus4
*
* 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\CustomerPlus42\Event;
use Eccube\Event\TemplateEvent;
use Plugin\CustomerPlus42\Entity\CustomerItem;
use Plugin\CustomerPlus42\Entity\CustomerData;
use Plugin\CustomerPlus42\Entity\CustomerDataDetail;
use Plugin\CustomerPlus42\Entity\ShippingCustom;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AbstractEvent
{
protected $container;
public function __construct(
ContainerInterface $container
)
{
$this->container = $container;
}
public function insertDatePickerJS(TemplateEvent $event)
{
$twig = '@CustomerPlus42/default/datepicker_js.twig';
$event->addAsset($twig);
}
public function insertDatePickerJSAdmin(TemplateEvent $event)
{
$twig = '@CustomerPlus42/admin/datepicker_js.twig';
$event->addAsset($twig);
}
public function setShippingFromCustomerAddress($Shipping, $CustomerAddress)
{
$entityManager = $this->container->get('doctrine.orm.entity_manager');
$ShippingCustoms = $Shipping->getShippingCustoms();
if(!is_null($ShippingCustoms) && count($ShippingCustoms) > 0){
foreach($ShippingCustoms as $ShippingCustom){
$Shipping->removeShippingCustom($ShippingCustom);
$entityManager->remove($ShippingCustom);
}
}
$entityManager->flush();
$CustomerAddressCustoms = $CustomerAddress->getCustomerAddressCustoms();
if(!is_null($CustomerAddressCustoms)){
foreach($CustomerAddressCustoms as $CustomerAddressCustom){
$CustomerItem = $entityManager->getRepository(CustomerItem::class)->find($CustomerAddressCustom->getCustomerItemId());
$CustomerData = new CustomerData();
$CustomerData->setCustomerItem($CustomerItem);
foreach($CustomerAddressCustom->getCustomerData()->getDetails() as $Detail){
$shippingDetail = new CustomerDataDetail();
$shippingDetail->setCustomerData($CustomerData)
->setValue($Detail->getValue())
->setDateValue($Detail->getDateValue())
->setNumValue($Detail->getNumValue());
$CustomerData->addDetail($shippingDetail);
}
$ShippingCustom = new ShippingCustom();
$ShippingCustom->setCustomerData($CustomerData)
->setCustomerItemId($CustomerAddressCustom->getCustomerItemId())
->setShipping($Shipping);
$Shipping->addShippingCustom($ShippingCustom);
$entityManager->persist($CustomerData);
$entityManager->persist($ShippingCustom);
}
}
$entityManager->flush();
}
}