app/Plugin/CustomerPlus4/CustomerPlusEvent.php line 244

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\CustomerPlus4;
  12. use Eccube\Event\EccubeEvents;
  13. use Eccube\Event\RenderEvent;
  14. use Eccube\Event\TemplateEvent;
  15. use Eccube\Event\EventArgs;
  16. use Eccube\Form\Type\Shopping\CustomerAddressType;
  17. use Eccube\Service\OrderHelper;
  18. use Plugin\CustomerPlus4\Entity\CustomerItem;
  19. use Plugin\CustomerPlus4\Entity\CustomerData;
  20. use Plugin\CustomerPlus4\Entity\CustomerDataDetail;
  21. use Plugin\CustomerPlus4\Entity\CustomerCustom;
  22. use Plugin\CustomerPlus4\Entity\CustomerAddressCustom;
  23. use Plugin\CustomerPlus4\Entity\ShippingCustom;
  24. use Plugin\CustomerPlus4\Service\CustomerPlusService;
  25. use Symfony\Component\DependencyInjection\ContainerInterface;
  26. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  27. use Symfony\Component\Form\FormFactoryInterface;
  28. class CustomerPlusEvent implements EventSubscriberInterface
  29. {
  30.     private $container;
  31.     private $formFactory;
  32.     private $customerPlusService;
  33.     public function __construct(
  34.             ContainerInterface $container,
  35.             FormFactoryInterface $formFactory,
  36.             CustomerPlusService $customerPlusService
  37.             )
  38.     {
  39.         $this->container $container;
  40.         $this->formFactory $formFactory;
  41.         $this->customerPlusService $customerPlusService;
  42.     }
  43.     /**
  44.      * @return array
  45.      */
  46.     public static function getSubscribedEvents()
  47.     {
  48.         return [
  49.             '@admin/Customer/edit.twig' => 'onTemplateAdminCustomerEdit',
  50.             '@admin/Customer/delivery_edit.twig' => 'onTemplateAdminCustomerDeliveryEdit',
  51.             '@admin/Order/edit.twig' => 'onTemplateAdminOrderEdit',
  52.             '@admin/Order/search_customer.twig' => 'onTemplateAdminOrderSearchCustomer',
  53.             '@admin/Order/shipping.twig' => 'onTemplateAdminOrderShipping',
  54.             EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_COMPLETE => 'hookAdminOrderEditSearchCustomerByIdComplete',
  55.             'Shopping/index.twig' => 'onTemplateShoppingIndex',
  56.             'Shopping/nonmember.twig' => 'onTemplateShoppingNonmember',
  57.             EccubeEvents::FRONT_SHOPPING_NONMEMBER_COMPLETE => 'hookFrontShoppingNonmemberComplete',
  58.             EccubeEvents::FRONT_SHOPPING_SHIPPING_COMPLETE => 'hookFrontShoppingShippingComplete',
  59.             EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_INITIALIZE => 'hookFrontShoppingShippingEditInitialize',
  60.             EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_COMPLETE => 'hookFrontShoppingShippingEditComplete',
  61.             EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_COMPLETE => ['hookFrontShoppingShippingMultipleComplete',-10],
  62.             EccubeEvents::FRONT_CONTACT_INDEX_COMPLETE => 'hookFrontContactIndexComplete',
  63.             EccubeEvents::ADMIN_CUSTOMER_CSV_EXPORT => 'hookAdminCustomerCsvExport',
  64.             EccubeEvents::ADMIN_ORDER_CSV_EXPORT_ORDER => 'hookAdminOrderCsvExport',
  65.             'Entry/index.twig' => 'insertDatePickerJS',
  66.             'Mypage/change.twig' => 'insertDatePickerJS',
  67.             'Mypage/delivery_edit.twig' => 'insertDatePickerJS',
  68.             'Shopping/shipping_edit.twig' => 'insertDatePickerJS',
  69.             'Shopping/shipping_multiple_edit.twig' => 'insertDatePickerJS',
  70.             'Contact/index.twig' => 'insertDatePickerJS',
  71.         ];
  72.     }
  73.     public function onTemplateAdminCustomerEdit(TemplateEvent $event)
  74.     {
  75.         $parameters $event->getParameters();
  76.         $source $event->getSource();
  77.         $CustomerItems $this->customerPlusService->getEnabledCustomerPlusForm('customer');
  78.         $AdminCustomerItems $this->customerPlusService->getCustomerPlusForm('admin_customer');
  79.         foreach($CustomerItems as $key => $CustomerItem){
  80.             foreach($AdminCustomerItems as $AdminCustomerItem){
  81.                 if($CustomerItem->getId() == $AdminCustomerItem->getId())unset($CustomerItems[$key]);
  82.             }
  83.         }
  84.         if(preg_match('/\{\%\sfor\sf\sin\sform\sif\sf\.vars\.eccube\_form\_options\.auto\_render\s\%\}/',$source$result)){
  85.             $search $result[0];
  86.             $snippet file_get_contents($this->container->getParameter('plugin_realdir'). '/CustomerPlus4/Resource/template/admin/Customer/ext_edit.twig');
  87.             $replace $snippet $search;
  88.             $source str_replace($search$replace$source);
  89.         }
  90.         $event->setSource($source);
  91.         $parameters['CustomerItems'] = $CustomerItems;
  92.         $event->setParameters($parameters);
  93.         $this->insertDatePickerJSAdmin($event);
  94.     }
  95.     public function onTemplateAdminCustomerDeliveryEdit(TemplateEvent $event)
  96.     {
  97.         $parameters $event->getParameters();
  98.         $source $event->getSource();
  99.         $CustomerItems $this->customerPlusService->getEnabledCustomerPlusForm('shipping');
  100.         $AdminCustomerItems $this->customerPlusService->getCustomerPlusForm('admin_delivery');
  101.         foreach($CustomerItems as $key => $CustomerItem){
  102.             foreach($AdminCustomerItems as $AdminCustomerItem){
  103.                 if($CustomerItem->getId() == $AdminCustomerItem->getId())unset($CustomerItems[$key]);
  104.             }
  105.         }
  106.         if(preg_match('/\{\%\sfor\sf\sin\sform\sif\sf\.vars\.eccube\_form\_options\.auto\_render\s\%\}/',$source$result)){
  107.             $search $result[0];
  108.             $snippet file_get_contents($this->container->getParameter('plugin_realdir'). '/CustomerPlus4/Resource/template/admin/Customer/ext_edit.twig');
  109.             $replace $snippet $search;
  110.             $source str_replace($search$replace$source);
  111.         }
  112.         $event->setSource($source);
  113.         $parameters['CustomerItems'] = $CustomerItems;
  114.         $event->setParameters($parameters);
  115.         $this->insertDatePickerJSAdmin($event);
  116.     }
  117.     public function onTemplateAdminOrderEdit(TemplateEvent $event)
  118.     {
  119.         $parameters $event->getParameters();
  120.         $source $event->getSource();
  121.         $OrderCustomerItems $this->customerPlusService->getEnabledCustomerPlusForm('order');
  122.         $AdminCustomerItems $this->customerPlusService->getCustomerPlusForm('admin_order');
  123.         foreach($OrderCustomerItems as $key => $CustomerItem){
  124.             foreach($AdminCustomerItems as $AdminCustomerItem){
  125.                 if($CustomerItem->getId() == $AdminCustomerItem->getId())unset($OrderCustomerItems[$key]);
  126.             }
  127.         }
  128.         $ShippingCustomerItems $this->customerPlusService->getEnabledCustomerPlusForm('admin_delivery');
  129.         if(preg_match('/\{\{\sform\_errors\(form\.message\)\s\}\}[\n|\r\n|\r]\s*\<\/div\>[\n|\r\n|\r]\s*\<\/div\>[\n|\r\n|\r]\s*\<\/div\>[\n|\r\n|\r]\s*\<\/div\>/',$source$result)){
  130.             $search $result[0];
  131.             $snippet file_get_contents($this->container->getParameter('plugin_realdir'). '/CustomerPlus4/Resource/template/admin/Order/ext_order_edit.twig');
  132.             $replace $search $snippet;
  133.             $source str_replace($search$replace$source);
  134.         }
  135.         if(preg_match('/\{\{\sform\_errors\(form\.Shipping\.company_name\)\s\}\}[\n|\r\n|\r]\s*\<\/div\>[\n|\r\n|\r]\s*\<\/div\>[\n|\r\n|\r]\s*\<\/div\>/',$source$result)){
  136.             $search $result[0];
  137.             $snippet file_get_contents($this->container->getParameter('plugin_realdir'). '/CustomerPlus4/Resource/template/admin/Order/ext_shipping_edit.twig');
  138.             $replace $search $snippet;
  139.             $source str_replace($search$replace$source);
  140.         }
  141.         $event->setSource($source);
  142.         $parameters['OrderCustomerItems'] = $OrderCustomerItems;
  143.         $parameters['ShippingCustomerItems'] = $ShippingCustomerItems;
  144.         $event->setParameters($parameters);
  145.         $twig '@CustomerPlus4/admin/Order/copy_customer_js.twig';
  146.         $event->addSnippet($twig);
  147.         $this->insertDatePickerJSAdmin($event);
  148.     }
  149.     public function onTemplateAdminOrderSearchCustomer(TemplateEvent $event)
  150.     {
  151.         $parameters $event->getParameters();
  152.         $CustomerCustomerItems $this->customerPlusService->getEnabledCustomerPlusForm('admin_customer');
  153.         $source $event->getSource();
  154.         if(preg_match('/val\(data\[\'company_name\'\]\)\;/',$source$result)){
  155.             $search $result[0];
  156.             $snippet file_get_contents($this->container->getParameter('plugin_realdir'). '/CustomerPlus4/Resource/template/admin/Order/insert_customer_js.twig');
  157.             $replace $search $snippet;
  158.             $source str_replace($search$replace$source);
  159.         }
  160.         $event->setSource($source);
  161.         $parameters['CustomerCustomerItems'] = $CustomerCustomerItems;
  162.         $event->setParameters($parameters);
  163.     }
  164.     public function hookAdminOrderEditSearchCustomerByIdComplete(EventArgs $event)
  165.     {
  166.         $data $event->getArgument('data');
  167.         $Customer $event->getArgument('Customer');
  168.         $CustomerCustomerItems $this->customerPlusService->getEnabledCustomerPlusForm('admin_customer');
  169.         foreach($CustomerCustomerItems as $CustomerItem){
  170.             $data['customerplus_'.$CustomerItem->getId()] = '';
  171.             $value $Customer->getCustomData($CustomerItem->getId());
  172.             $data['customerplus_'.$CustomerItem->getId()] = $value;
  173.         }
  174.         $event->setArgument('data',$data);
  175.     }
  176.     public function onTemplateAdminOrderShipping(TemplateEvent $event)
  177.     {
  178.         $parameters $event->getParameters();
  179.         $source $event->getSource();
  180.         $ShippingCustomerItems $this->customerPlusService->getEnabledCustomerPlusForm('admin_delivery');
  181.         if(preg_match('/\{\{\sform\_errors\(shippingForm\.company\_name\)\s\}\}[\n|\r\n|\r]\s*\<\/div\>[\n|\r\n|\r]\s*\<\/div\>[\n|\r\n|\r]\s*\<\/div\>[\n|\r\n|\r]\s*\<\/div\>/',$source$result)){
  182.             $search $result[0];
  183.             $snippet file_get_contents($this->container->getParameter('plugin_realdir'). '/CustomerPlus4/Resource/template/admin/Order/ext_shipping.twig');
  184.             $replace $search $snippet;
  185.             $source str_replace($search$replace$source);
  186.         }
  187.         $event->setSource($source);
  188.         $parameters['ShippingCustomerItems'] = $ShippingCustomerItems;
  189.         $event->setParameters($parameters);
  190.         $this->insertDatePickerJSAdmin($event);
  191.     }
  192.     public function onTemplateShoppingIndex(TemplateEvent $event)
  193.     {
  194.         $source $event->getSource();
  195.         if(preg_match('/\$\(\'#customer\'\)\.click\(function\(\)\s\{/',$source$result)){
  196.             $search $result[0];
  197.             $snippet file_get_contents($this->container->getParameter('plugin_realdir'). '/CustomerPlus4/Resource/template/default/Shopping/insert_js.twig');
  198.             $replace $search $snippet;
  199.             $source str_replace($search$replace$source);
  200.         }
  201.         $event->setSource($source);
  202.     }
  203.     public function onTemplateShoppingNonmember(TemplateEvent $event)
  204.     {
  205.         $source $event->getSource();
  206.         $request $this->container->get('request_stack')->getCurrentRequest();
  207.         $session $request->getSession();
  208.         if($session->has(OrderHelper::SESSION_NON_MEMBER)){
  209.             if($session->get(OrderHelper::SESSION_NON_MEMBER)){
  210.                 if(preg_match('/url\(\'shopping_nonmember\'\)/',$source$result)){
  211.                     $search $result[0];
  212.                     $replace "url('shopping_customer_edit')";
  213.                     $source str_replace($search$replace$source);
  214.                 }
  215.                 if(preg_match('/url\(\'cart\'\)/',$source$result)){
  216.                     $search $result[0];
  217.                     $replace "url('shopping')";
  218.                     $source str_replace($search$replace$source);
  219.                 }
  220.                 if(preg_match('/\{\{\s\'次へ\'\|trans\s\}\}\<\/button\>/',$source$result)){
  221.                     $search $result[0];
  222.                     $replace "{{ '編集'|trans }}</button>";
  223.                     $source str_replace($search$replace$source);
  224.                 }
  225.             }
  226.         }
  227.         $event->setSource($source);
  228.         $this->insertDatePickerJS($event);
  229.     }
  230.     public function hookFrontShoppingNonmemberComplete(EventArgs $event)
  231.     {
  232.         $form $event->getArgument('form');
  233.         $request $this->container->get('request_stack')->getCurrentRequest();
  234.         $session $request->getSession();
  235.         $Customer $session->get(OrderHelper::SESSION_NON_MEMBER);
  236.         $CustomerItems $this->customerPlusService->getEnabledCustomerPlusForm('customer');
  237.         foreach($CustomerItems as $CustomerItem){
  238.             if($form->has('customerplus_'.$CustomerItem->getId())){
  239.                 $plgCustomer = new CustomerCustom();
  240.                 $plgCustomer->setCustomerItemId($CustomerItem->getId());
  241.                 $plgCustomer->setCustomer($Customer);
  242.                 $value $form->get('customerplus_'.$CustomerItem->getId())->getData();
  243.                 $value $this->customerPlusService->convRegistData($value$CustomerItem);
  244.                 $CustomerData = new CustomerData();
  245.                 if($CustomerItem->getInputType() == CustomerItem::CHECKBOX_TYPE){
  246.                     $arrValue explode(','$value);
  247.                 }else{
  248.                     $arrValue = [$value];
  249.                 }
  250.                 foreach($arrValue as $value){
  251.                     $detail = new CustomerDataDetail();
  252.                     $detail->setCustomerData($CustomerData);
  253.                     $disp_value $value;
  254.                     if($CustomerItem->getInputType() == CustomerItem::DATE_TYPE){
  255.                         if(!is_null($value)){
  256.                             $value = new \DateTime($value);
  257.                         }
  258.                         $detail->setDateValue($value);
  259.                     }
  260.                     if($CustomerItem->getInputType() >= CustomerItem::SELECT_TYPE){
  261.                         $detail->setNumValue(intval($value));
  262.                         foreach($CustomerItem->getOptions() as $Option){
  263.                             if($value == $Option->getId())$disp_value $Option->getText();
  264.                         }
  265.                     }
  266.                     $detail->setValue($disp_value);
  267.                     $CustomerData->setCustomerItem($CustomerItem);
  268.                     $CustomerData->addDetail($detail);
  269.                 }
  270.                 $plgCustomer->setCustomerData($CustomerData);
  271.                 $Customer->addCustomerCustom($plgCustomer);
  272.             }
  273.         }
  274.         $session->set(OrderHelper::SESSION_NON_MEMBER$Customer);
  275.     }
  276.     public function hookFrontShoppingShippingComplete(EventArgs $event)
  277.     {
  278.         $Shipping $event->getArgument('Shipping');
  279.         $Order $event->getArgument('Order');
  280.         $request $this->container->get('request_stack')->getCurrentRequest();
  281.         $builder $this->formFactory->createBuilder(CustomerAddressType::class, null, [
  282.             'customer' => $Order->getCustomer(),
  283.             'shipping' => $Shipping,
  284.         ]);
  285.         $form $builder->getForm();
  286.         $form->handleRequest($request);
  287.         if ($form->isSubmitted() && $form->isValid()) {
  288.             $CustomerAddress $form['addresses']->getData();
  289.             $this->setShippingFromCustomerAddress($Shipping,$CustomerAddress);
  290.         }
  291.     }
  292.     public function hookFrontShoppingShippingEditInitialize(EventArgs $event)
  293.     {
  294.         if(!$this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')){
  295.             $builder $event->getArgument('builder');
  296.             $Shipping $event->getArgument('Shipping');
  297.             $entityManager $this->container->get('doctrine.orm.entity_manager');
  298.             $CustomerItems $this->customerPlusService->getCustomerPlusForm('shipping_multiple_edit');
  299.             $plgShippings $Shipping->getShippingCustoms();
  300.             if(!is_null($plgShippings) && count($plgShippings) > 0){
  301.                 foreach($plgShippings as $plgShipping){
  302.                     $CustomerItem $plgShipping->getCustomerData()->getCustomerItem();
  303.                     if(in_array($CustomerItem,$CustomerItems)){
  304.                         $customer_item_id $CustomerItem->getId();
  305.                         $value $plgShipping->getValue();
  306.                         if($value){
  307.                             $value $this->customerPlusService->convSetData($value$customer_item_id'customerplus_Shipping_customerplus_');
  308.                             $builder->get('customerplus_'.$customer_item_id)->setData($value);
  309.                         }
  310.                     }
  311.                 }
  312.             }
  313.         }
  314.     }
  315.     public function hookFrontShoppingShippingEditComplete(EventArgs $event)
  316.     {
  317.         $form $event->getArgument('form');
  318.         $Shipping $event->getArgument('Shipping');
  319.         $CustomerAddress $event->getArgument('CustomerAddress');
  320.         if($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')){
  321.             $entityManager $this->container->get('doctrine.orm.entity_manager');
  322.             $customerDataRepository $entityManager->getRepository(CustomerData::class);
  323.             $CustomerItems $this->customerPlusService->getCustomerPlusForm('shipping_edit');
  324.             foreach($CustomerItems as $CustomerItem){
  325.                 if($form->has('customerplus_'.$CustomerItem->getId())){
  326.                     $plgCustomerAddress = new CustomerAddressCustom();
  327.                     $plgCustomerAddress->setCustomerItemId($CustomerItem->getId());
  328.                     $plgCustomerAddress->setCustomerAddress($CustomerAddress);
  329.                     $value $form->get('customerplus_'.$CustomerItem->getId())->getData();
  330.                     $value $this->customerPlusService->convRegistData($value$CustomerItem);
  331.                     $CustomerData = new CustomerData();
  332.                     $CustomerData $customerDataRepository->regist($CustomerData$CustomerItem$value);
  333.                     $plgCustomerAddress->setCustomerData($CustomerData);
  334.                     $CustomerAddress->addCustomerAddressCustom($plgCustomerAddress);
  335.                 }
  336.             }
  337.         }
  338.         $this->setShippingFromCustomerAddress($Shipping,$CustomerAddress);
  339.     }
  340.     public function hookFrontContactIndexComplete(EventArgs $event)
  341.     {
  342.         $form $event->getArgument('form');
  343.         $data $event->getArgument('data');
  344.         $CustomerItems $this->customerPlusService->getEnabledCustomerPlusForm('contact');
  345.         foreach($CustomerItems as $CustomerItem){
  346.             if($form->has('customerplus_'.$CustomerItem->getId())){
  347.                 $value $form->get('customerplus_'.$CustomerItem->getId())->getData();
  348.                 $input_type $CustomerItem->getInputType();
  349.                 if ($input_type == CustomerItem::DATE_TYPE) {
  350.                     if($value instanceof \DateTime){
  351.                         $value $value->format('Y-m-d');
  352.                     }
  353.                 } elseif($input_type >= CustomerItem::SELECT_TYPE) {
  354.                     $Options $CustomerItem->getOptions();
  355.                     if(!is_array($value))$value = [$value];
  356.                     $ret = [];
  357.                     foreach($value as $val){
  358.                         foreach($Options as $Option){
  359.                             if($Option->getId() == $val){
  360.                                 $ret[] = $Option->getText();
  361.                                 continue;
  362.                             }
  363.                         }
  364.                     }
  365.                     $value implode(','$ret);
  366.                 }
  367.                 $data['customerplus_'.$CustomerItem->getId()] = $value;
  368.             }
  369.         }
  370.         $event->setArgument('data',$data);
  371.     }
  372.     public function hookFrontShoppingShippingMultipleComplete(EventArgs $event)
  373.     {
  374.         $form $event->getArgument('form');
  375.         $Order $event->getArgument('Order');
  376.         $data $form['shipping_multiple'];
  377.         foreach ($data as $multiples) {
  378.             foreach ($multiples as $items) {
  379.                 foreach ($items as $item) {
  380.                     $CustomerAddress $item['customer_address']->getData();
  381.                     $customerAddressName $CustomerAddress->getShippingMultipleDefaultName();
  382.                     foreach($Order->getShippings() as $Shipping){
  383.                         $shippingName $Shipping->getShippingMultipleDefaultName();
  384.                         if($customerAddressName == $shippingName){
  385.                             if($customerAddressName == $Order->getShippingMultipleDefaultName()){
  386.                                 foreach($Order->getOrderCustoms() as $OrderCustom){
  387.                                     $CustomerAddressCustom = new CustomerAddressCustom();
  388.                                     $CustomerAddressCustom->setCustomerData($OrderCustom->getCustomerData())
  389.                                                           ->setCustomerItemId($OrderCustom->getCustomerItemId())
  390.                                                           ->setCustomerAddress($CustomerAddress);
  391.                                     $CustomerAddress->addCustomerAddressCustom($CustomerAddressCustom);
  392.                                 }
  393.                             }
  394.                             $this->setShippingFromCustomerAddress($Shipping,$CustomerAddress);
  395.                         }
  396.                     }
  397.                 }
  398.             }
  399.         }
  400.     }
  401.     public function hookAdminCustomerCsvExport(EventArgs $event)
  402.     {
  403.         $ExportCsvRow $event->getArgument('ExportCsvRow');
  404.         if ($ExportCsvRow->isDataNull()) {
  405.             $csvService $event->getArgument('csvService');
  406.             $Customer $event->getArgument('Customer');
  407.             $Csv $event->getArgument('Csv');
  408.             $csvEntityName str_replace('\\\\''\\'$Csv->getEntityName());
  409.             if($csvEntityName == 'Plugin\CustomerPlus4\Entity\CustomerCustom'){
  410.                 $data $Customer->getViewData($Csv->getFieldName());
  411.                 $ExportCsvRow->setData($data);
  412.             }
  413.         }
  414.     }
  415.     public function hookAdminOrderCsvExport(EventArgs $event)
  416.     {
  417.         $ExportCsvRow $event->getArgument('ExportCsvRow');
  418.         if ($ExportCsvRow->isDataNull()) {
  419.             $entityManager $this->container->get('doctrine.orm.entity_manager');
  420.             $shippingReposiory $entityManager->getRepository(ShippingCustom::class);
  421.             $csvService $event->getArgument('csvService');
  422.             $OrderItem $event->getArgument('OrderItem');
  423.             $Order $OrderItem->getOrder();
  424.             $Shipping $OrderItem->getShipping();
  425.             $Csv $event->getArgument('Csv');
  426.             $csvEntityName str_replace('\\\\''\\'$Csv->getEntityName());
  427.             $data null;
  428.             if($csvEntityName == 'Plugin\CustomerPlus4\Entity\OrderCustom'){
  429.                 $data $Order->getViewData($Csv->getFieldName());
  430.             }elseif($csvEntityName == 'Plugin\CustomerPlus4\Entity\ShippingCustom'){
  431.                 $results $shippingReposiory->findBy(['Shipping' => $Shipping'customer_item_id' =>  $Csv->getFieldName()]);
  432.                 if($results){
  433.                     $arrData = [];
  434.                     foreach($results as $result){
  435.                         $arrData[] = $result->getViewValue();
  436.                     }
  437.                     $data implode(','$arrData);
  438.                 }
  439.             }
  440.             $ExportCsvRow->setData($data);
  441.         }
  442.     }
  443.     public function insertDatePickerJS(TemplateEvent $event)
  444.     {
  445.         $twig '@CustomerPlus4/default/datepicker_js.twig';
  446.         $event->addAsset($twig);
  447.     }
  448.     private function insertDatePickerJSAdmin(TemplateEvent $event)
  449.     {
  450.         $twig '@CustomerPlus4/admin/datepicker_js.twig';
  451.         $event->addAsset($twig);
  452.     }
  453.     private function setShippingFromCustomerAddress($Shipping$CustomerAddress)
  454.     {
  455.         $entityManager $this->container->get('doctrine.orm.entity_manager');
  456.         $ShippingCustoms $Shipping->getShippingCustoms();
  457.         if(!is_null($ShippingCustoms) && count($ShippingCustoms) > 0){
  458.             foreach($ShippingCustoms as $ShippingCustom){
  459.                 $Shipping->removeShippingCustom($ShippingCustom);
  460.                 $entityManager->remove($ShippingCustom);
  461.             }
  462.         }
  463.         $entityManager->flush();
  464.         $CustomerAddressCustoms $CustomerAddress->getCustomerAddressCustoms();
  465.         if(!is_null($CustomerAddressCustoms)){
  466.             foreach($CustomerAddressCustoms as $CustomerAddressCustom){
  467.                 $CustomerItem $entityManager->getRepository(CustomerItem::class)->find($CustomerAddressCustom->getCustomerItemId());
  468.                 $CustomerData = new CustomerData();
  469.                 $CustomerData->setCustomerItem($CustomerItem);
  470.                 foreach($CustomerAddressCustom->getCustomerData()->getDetails() as $Detail){
  471.                     $shippingDetail = new CustomerDataDetail();
  472.                     $shippingDetail->setCustomerData($CustomerData)
  473.                                 ->setValue($Detail->getValue())
  474.                                 ->setDateValue($Detail->getDateValue())
  475.                                 ->setNumValue($Detail->getNumValue());
  476.                     $CustomerData->addDetail($shippingDetail);
  477.                 }
  478.                 $ShippingCustom = new ShippingCustom();
  479.                 $ShippingCustom->setCustomerData($CustomerData)
  480.                             ->setCustomerItemId($CustomerAddressCustom->getCustomerItemId())
  481.                             ->setShipping($Shipping);
  482.                 $Shipping->addShippingCustom($ShippingCustom);
  483.                 $entityManager->persist($CustomerData);
  484.                 $entityManager->persist($ShippingCustom);
  485.             }
  486.         }
  487.         $entityManager->flush();
  488.     }
  489. }