您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

643 行
32KB

  1. <?php
  2. namespace Lc\ShopBundle\Controller\Backend;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Doctrine\ORM\EntityRepository;
  5. use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController;
  6. use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
  7. use FOS\UserBundle\Model\UserManagerInterface;
  8. use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface;
  9. use Lc\ShopBundle\Context\ImageInterface;
  10. use Lc\ShopBundle\Context\MerchantInterface;
  11. use Lc\ShopBundle\Context\ReminderInterface;
  12. use Lc\ShopBundle\Context\SeoInterface;
  13. use Lc\ShopBundle\Context\StatusInterface;
  14. use Lc\ShopBundle\Context\TreeInterface;
  15. use Lc\ShopBundle\Form\Backend\Common\AbstractEditPositionType;
  16. use Lc\ShopBundle\Form\Backend\Filters\ListFilterType;
  17. use Lc\ShopBundle\Model\User;
  18. use Lc\ShopBundle\Services\UtilsManager;
  19. use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
  20. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  21. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  22. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  23. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  24. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  25. use Symfony\Component\Form\Extension\Core\Type\TextType;
  26. use Symfony\Component\Form\FormEvent;
  27. use Symfony\Component\Form\FormEvents;
  28. use Symfony\Component\HttpFoundation\JsonResponse;
  29. use Symfony\Component\HttpFoundation\Response;
  30. use Symfony\Component\Security\Core\Security;
  31. use Symfony\Contracts\Translation\TranslatorInterface;
  32. class AdminController extends EasyAdminController
  33. {
  34. protected $security;
  35. protected $userManager;
  36. protected $em;
  37. protected $utils;
  38. protected $merchantUtils;
  39. protected $mailjetTransport;
  40. protected $orderUtils;
  41. protected $mailUtils ;
  42. protected $translator;
  43. protected $utilsProcess;
  44. protected $filtersForm = null;
  45. public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em,
  46. MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator)
  47. {
  48. $this->security = $security;
  49. $this->userManager = $userManager;
  50. $this->em = $em;
  51. $this->mailjetTransport = $mailjetTransport;
  52. $this->utils = $utilsManager->getUtils();
  53. $this->merchantUtils = $utilsManager->getMerchantUtils();
  54. $this->orderUtils = $utilsManager->getOrderUtils();;
  55. $this->mailUtils = $utilsManager->getMailUtils() ;
  56. $this->utilsProcess = $utilsManager->getUtilsProcess() ;
  57. $this->translator = $translator;
  58. }
  59. public function createCustomForm($class, $action, $parameters, $data = true)
  60. {
  61. $options = array();
  62. if ($data) $options['data'] = $parameters['entity'];
  63. $options['action'] = $this->generateUrl('easyadmin', array(
  64. 'action' => $action,
  65. 'entity' => $this->entity['name'],
  66. 'id' => $parameters['entity']->getId()
  67. ));
  68. return $this->createForm($class, null, $options);
  69. }
  70. public function autocompleteAction()
  71. {
  72. $entityName = $this->request->query->get('entity');
  73. $valueSearched = $this->request->query->get('q');
  74. $field = $this->request->query->get('field');
  75. $class = $this->entity['class'];
  76. $repo = $this->em->getRepository($class);
  77. $values = $repo->findByTerm($field, $valueSearched);
  78. $response = array();
  79. foreach ($values as $value) {
  80. $response[] = $value[$field];
  81. }
  82. return new JsonResponse($response);
  83. }
  84. /**
  85. * Réécriture de show action pr rediriger vers l'édition
  86. */
  87. public function showAction()
  88. {
  89. $id = $this->request->query->get('id');
  90. $entity = $this->request->query->get('entity');
  91. return $this->redirectToRoute('easyadmin', [
  92. 'action' => 'edit',
  93. 'entity' => $entity,
  94. 'id' => $id
  95. ]);
  96. }
  97. /**
  98. * Réécriture de removeEntity pour passer les status à -1
  99. */
  100. protected function removeEntity($entity)
  101. {
  102. if ($entity instanceof StatusInterface) {
  103. $entity->setStatus(-1);
  104. $this->em->persist($entity);
  105. $this->em->flush();
  106. } else {
  107. parent::removeEntity($entity);
  108. }
  109. }
  110. protected function commonDqlFilterQueryBuilder($entityClass, $dqlFilter)
  111. {
  112. if ($pos = strpos($dqlFilter, 'currentMerchant')) {
  113. $dqlFilter = sprintf(str_replace('currentMerchant', $this->getUser()->getMerchant()->getId(), $dqlFilter));
  114. }
  115. if (new $entityClass instanceof StatusInterface && strpos($dqlFilter, 'entity.status') === false) {
  116. if ($dqlFilter) $dqlFilter .= sprintf(' AND entity.status > = 0');
  117. else $dqlFilter .= sprintf(' entity.status > = 0');
  118. }
  119. return $dqlFilter;
  120. }
  121. protected function commonQueryFilter($entityClass, $queryBuilder)
  122. {
  123. if (new $entityClass instanceof FilterMultipleMerchantsInterface) {
  124. $queryBuilder->andWhere(':currentMerchant MEMBER OF entity.merchants')
  125. ->setParameter(':currentMerchant', $this->getUser()->getMerchant()->getId());
  126. }
  127. }
  128. protected function createSearchQueryBuilder($entityClass, $searchQuery, array $searchableFields, $sortField = null, $sortDirection = null, $dqlFilter = null)
  129. {
  130. $dqlFilter = $this->commonDqlFilterQueryBuilder($entityClass, $dqlFilter);
  131. $queryBuilder = parent::createSearchQueryBuilder($entityClass, $searchQuery, $searchableFields, $sortField, $sortDirection, $dqlFilter);
  132. $this->commonQueryFilter($entityClass, $queryBuilder);
  133. return $queryBuilder;
  134. }
  135. protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
  136. {
  137. $dqlFilter = $this->commonDqlFilterQueryBuilder($entityClass, $dqlFilter);
  138. $queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter);
  139. $this->commonQueryFilter($entityClass, $queryBuilder);
  140. $listFields = $this->entity['list']['fields'];
  141. $this->filtersForm = $this->createForm(ListFilterType::class, null, array(
  142. 'fields' => $listFields,
  143. 'method' => 'get',
  144. 'entity_name' => $this->entity['name'],
  145. //'entityClass' => $this->entity['class'],
  146. 'entity_class' => $this->entity['class']
  147. ));
  148. $this->filtersForm->handleRequest($this->request);
  149. if ($this->filtersForm->isSubmitted() && $this->filtersForm->isValid()) {
  150. foreach ($listFields as $field) {
  151. if ($this->filtersForm->has($field['property'])) {
  152. switch ($field['dataType']) {
  153. case 'option':
  154. case 'integer':
  155. case 'text':
  156. case 'string':
  157. case 'toggle':
  158. $filter = $this->filtersForm->get($field['property'])->getData();
  159. if ($filter !== null) {
  160. $queryBuilder->andWhere('entity.' . $field['property'] . ' LIKE :' . $field['property'] . '');
  161. $queryBuilder->setParameter($field['property'], '%' . $filter . '%');
  162. }
  163. break;
  164. case 'association' :
  165. $filter = $this->filtersForm->get($field['property'])->getData();
  166. if ($filter !== null) {
  167. if ($field['type_options']['multiple']) {
  168. $queryBuilder->andWhere(':' . $field['property'] . ' MEMBER OF entity.' . $field['property'] . '');
  169. } else {
  170. $queryBuilder->andWhere('entity.' . $field['property'] . ' = :' . $field['property'] . '');
  171. }
  172. if($filter instanceof TreeInterface && $filter->getParent() == null) {
  173. $queryBuilder->setParameter($field['property'], array_merge(array($filter), $filter->getChildrens()->toArray()));
  174. }else{
  175. $queryBuilder->setParameter($field['property'], $filter);
  176. }
  177. }
  178. break;
  179. case 'datetime':
  180. case 'date':
  181. $dateStart = $this->filtersForm->get($field['property'])->get('dateStart')->getData();
  182. $dateEnd = $this->filtersForm->get($field['property'])->get('dateEnd')->getData();
  183. if ($dateStart) $queryBuilder->andWhere('entity.' . $field['property'] . ' >= :dateStart')->setParameter('dateStart', $dateStart);
  184. if ($dateEnd) $queryBuilder->andWhere('entity.' . $field['property'] . ' <= :dateEnd')->setParameter('dateEnd', $dateEnd);
  185. }
  186. }
  187. }
  188. }
  189. return $queryBuilder;
  190. }
  191. public function renderTemplate($actionName, $templatePath, array $parameters = [])
  192. {
  193. $reminderRepo = $this->em->getRepository(ReminderInterface::class);
  194. $easyadmin = $this->request->attributes->get('easyadmin');
  195. $entityName = $easyadmin['entity']['name'];
  196. $id = null;
  197. if ($easyadmin['item']) $id = $easyadmin['item']->getId();
  198. $user = $this->security->getUser();
  199. $reminders = array('reminders' => $reminderRepo->findByEasyAdminConfigAndUser($actionName, $entityName, $user, $id));
  200. if ($actionName == 'list') {
  201. if ($this->filtersForm === null) {
  202. $options['fields'] = $parameters['fields'];
  203. $options['method'] = 'get';
  204. $this->filtersForm = $this->createForm(ListFilterType::class, null, $options);
  205. }
  206. $parameters = array_merge(
  207. $parameters,
  208. array(
  209. 'filters_form' => $this->filtersForm->createView()
  210. )
  211. );
  212. }
  213. $parameters = array_merge(
  214. $parameters,
  215. $this->getTwigExtraParameters(),
  216. $reminders
  217. );
  218. return parent::renderTemplate($actionName, $templatePath, $parameters);
  219. }
  220. public function getTwigExtraParameters()
  221. {
  222. $repositoryMerchant = $this->getDoctrine()->getRepository(MerchantInterface::class);
  223. $merchants = $repositoryMerchant->findAll();
  224. $user = $this->security->getUser();
  225. return [
  226. 'merchants' => $merchants,
  227. 'current_merchant' => ($user && $user->getMerchant()) ? $user->getMerchant() : null,
  228. ];
  229. }
  230. public function listChildrenAction()
  231. {
  232. $this->dispatch(EasyAdminEvents::PRE_LIST);
  233. $id = $this->request->query->get('id');
  234. $this->entity['list']['dql_filter'] = "entity.parent = " . $id;
  235. $easyadmin = $this->request->attributes->get('easyadmin');
  236. $entity = $easyadmin['item'];
  237. $fields = $this->entity['list']['fields'];
  238. $paginator = $this->findAll($this->entity['class'], $this->request->query->get('page', 1), $this->entity['list']['max_results'], $this->request->query->get('sortField'), $this->request->query->get('sortDirection'), $this->entity['list']['dql_filter']);
  239. $this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]);
  240. $parameters = [
  241. 'paginator' => $paginator,
  242. 'fields' => $fields,
  243. 'batch_form' => $this->createBatchForm($this->entity['name'])->createView(),
  244. 'delete_form_template' => $this->createDeleteForm($this->entity['name'], '__id__')->createView(),
  245. 'entity' => $entity,
  246. ];
  247. return $this->executeDynamicMethod('render<EntityName>Template', ['list', $this->entity['templates']['list'], $parameters]);
  248. }
  249. public function sortAction()
  250. {
  251. $this->dispatch(EasyAdminEvents::PRE_LIST);
  252. $entity = null;
  253. //Replace this with query builder function, do not use finAll of easyAdmin
  254. if ($this->request->query->get('id')) {
  255. $id = $this->request->query->get('id');
  256. $this->entity['list']['dql_filter'] = "entity.parent = " . $id;
  257. $easyadmin = $this->request->attributes->get('easyadmin');
  258. $entity = $easyadmin['item'];
  259. }
  260. if ($this->entity['list']['dql_filter']) $this->entity['list']['dql_filter'] .= sprintf(' AND entity.status = 1');
  261. else $this->entity['list']['dql_filter'] .= sprintf(' entity.status = 1');
  262. $fields = $this->entity['list']['fields'];
  263. $paginator = $this->findAll($this->entity['class'], $this->request->query->get('page', 1), 500, $this->request->query->get('sortField'), $this->request->query->get('sortDirection'), $this->entity['list']['dql_filter']);
  264. $this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]);
  265. $positionForm = $this->createFormBuilder(array('entities', $paginator->getCurrentPageResults()))
  266. ->add('entities', CollectionType::class, array(
  267. 'required' => true,
  268. 'allow_add' => true,
  269. 'entry_type' => AbstractEditPositionType::class,
  270. ))
  271. ->getForm();
  272. $positionForm->handleRequest($this->request);
  273. if ($positionForm->isSubmitted() && $positionForm->isValid()) {
  274. $class = $this->entity['class'];
  275. $repo = $this->em->getRepository($class);
  276. $latsPos = 0;
  277. foreach ($positionForm->get('entities')->getData() as $elm) {
  278. $this->dispatch(EasyAdminEvents::PRE_UPDATE, ['entity' => $entity]);
  279. $entity = $repo->find($elm['id']);
  280. $entity->setPosition($elm['position']);
  281. $this->em->persist($entity);
  282. $this->dispatch(EasyAdminEvents::POST_UPDATE, ['entity' => $entity]);
  283. $latsPos = $elm['position'];
  284. }
  285. //die();
  286. //die();
  287. //to do récupérer les élements hors ligne et incrémenter position
  288. /*foreach ($repo->findBy(array('status'=> false)) as $offlineEntity) {
  289. $latsPos++;
  290. $offlineEntity->setPosition($latsPos);
  291. $this->em->persist($offlineEntity);
  292. }*/
  293. $this->em->flush();
  294. $this->addFlash('success', 'Position modifié', array(), 'mweb');
  295. return $this->redirectToReferrer();
  296. }
  297. $parameters = [
  298. 'paginator' => $paginator,
  299. 'fields' => $fields,
  300. 'batch_form' => $this->createBatchForm($this->entity['name'])->createView(),
  301. 'delete_form_template' => $this->createDeleteForm($this->entity['name'], '__id__')->createView(),
  302. 'postion_form' => $positionForm->createView(),
  303. 'entity' => $entity,
  304. 'sortable' => true
  305. ];
  306. return $this->executeDynamicMethod('render<EntityName>Template', ['sortable', "@LcShop/backend/default/sortable.html.twig", $parameters]);
  307. }
  308. public function createEntityFormBuilder($entity, $view, $override = true)
  309. {
  310. $formBuilder = parent::createEntityFormBuilder($entity, $view);
  311. if ($override) $formBuilder = $this->overrideFormBuilder($formBuilder, $entity, $view);
  312. return $formBuilder;
  313. }
  314. public function overrideFormBuilder($formBuilder, $entity, $view)
  315. {
  316. $id = (null !== $entity->getId()) ? $entity->getId() : 0;
  317. if ($entity instanceof SeoInterface) {
  318. $formBuilder->add('metaTitle', TextType::class, array(
  319. 'required' => false,
  320. 'translation_domain' => 'lcshop'
  321. )
  322. );
  323. $formBuilder->add('metaDescription', TextareaType::class, array(
  324. 'required' => false,
  325. 'translation_domain' => 'lcshop'
  326. )
  327. );
  328. /*$formBuilder->add('oldUrls', TextareaType::class, array(
  329. 'required' => false,
  330. 'translation_domain' => 'lcshop'
  331. )
  332. );*/
  333. }
  334. if ($entity instanceof StatusInterface) {
  335. $formBuilder->add('status', ChoiceType::class, array(
  336. 'choices' => array(
  337. 'field.default.statusOptions.offline' => '0',
  338. 'field.default.statusOptions.online' => '1'
  339. ),
  340. 'expanded' => true,
  341. 'required' => true,
  342. 'translation_domain' => 'lcshop'
  343. )
  344. );
  345. }
  346. if ($entity instanceof TreeInterface) {
  347. $formBuilder->add('parent', EntityType::class, array(
  348. 'class' => $this->entity['class'],
  349. 'query_builder' => function (EntityRepository $repo) use ($id) {
  350. return $repo->createQueryBuilder('e')
  351. ->where('e.parent is NULL')
  352. ->andWhere('e.status >= 0')
  353. ->orderBy('e.status', "DESC");
  354. },
  355. 'required' => false,
  356. )
  357. );
  358. }
  359. $formBuilder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
  360. $form = $event->getForm();
  361. $childrens = $form->all();
  362. $this->loopFormField($form, $childrens);
  363. });
  364. return $formBuilder;
  365. }
  366. private function loopFormField($form, $childrens)
  367. {
  368. foreach ($childrens as $child) {
  369. $statusInterface = false;
  370. $treeInterface = false;
  371. $type = $child->getConfig()->getType()->getInnerType();;
  372. if ($type instanceof EntityType) {
  373. $passedOptions = $child->getConfig()->getOptions();
  374. $classImplements = class_implements($passedOptions['class']);
  375. $isFilterMerchantInterface = in_array('Lc\ShopBundle\Context\FilterMerchantInterface', $classImplements);
  376. $isFilterMultipleMerchantsInterface = in_array('Lc\ShopBundle\Context\FilterMultipleMerchantsInterface', $classImplements);
  377. if ($isFilterMerchantInterface || $isFilterMultipleMerchantsInterface) {
  378. if (in_array('Lc\ShopBundle\Context\StatusInterface', $classImplements)) {
  379. $statusInterface = true;
  380. }
  381. if (in_array('Lc\ShopBundle\Context\TreeInterface', $classImplements)) {
  382. $treeInterface = true;
  383. }
  384. $propertyMerchant = 'merchant';
  385. if ($isFilterMultipleMerchantsInterface) {
  386. $propertyMerchant .= 's';
  387. }
  388. $form->add($child->getName(), EntityType::class, array(
  389. 'class' => $this->em->getClassMetadata($passedOptions['class'])->getName(),
  390. 'label' => $passedOptions['label'],
  391. 'multiple' => isset($passedOptions['multiple']) ? $passedOptions['multiple'] : false,
  392. 'placeholder' => '--',
  393. 'translation_domain' => 'lcshop',
  394. 'query_builder' => function (EntityRepository $repo) use ($passedOptions, $propertyMerchant, $statusInterface, $treeInterface, $child) {
  395. $queryBuilder = $repo->createQueryBuilder('e');
  396. $propertyMerchant = 'e.' . $propertyMerchant;
  397. if ($passedOptions['class'] == 'App\Entity\PointSale') {
  398. $queryBuilder->where(':currentMerchant MEMBER OF ' . $propertyMerchant);
  399. } else {
  400. $queryBuilder->where($propertyMerchant . ' = :currentMerchant');
  401. }
  402. if ($statusInterface) {
  403. $queryBuilder->andWhere('e.status >= 0');
  404. }
  405. if ($treeInterface && $child->getName() == 'parent') {
  406. $queryBuilder->andWhere('e.parent is null');
  407. }
  408. $queryBuilder->setParameter(':currentMerchant', $this->getUser()->getMerchant()->getId());
  409. return $queryBuilder;
  410. },
  411. 'choice_label' => function ($choice) {
  412. if ($choice instanceof StatusInterface && $choice->getStatus() == 0) {
  413. return $choice . ' [hors ligne]';
  414. }
  415. return $choice;
  416. },
  417. 'required' => $passedOptions['required'],
  418. 'choice_attr' => $passedOptions['choice_attr'],
  419. )
  420. );
  421. }
  422. } else {
  423. $subChildrens = $child->all();
  424. if (count($subChildrens)) {
  425. $this->loopFormField($child, $subChildrens);
  426. }
  427. }
  428. }
  429. }
  430. protected function editAction()
  431. {
  432. $this->dispatch(EasyAdminEvents::PRE_EDIT);
  433. $id = $this->request->query->get('id');
  434. $easyadmin = $this->request->attributes->get('easyadmin');
  435. $entity = $easyadmin['item'];
  436. if ($this->request->isXmlHttpRequest() && $property = $this->request->query->get('property')) {
  437. $newValue = 'true' === mb_strtolower($this->request->query->get('newValue'));
  438. $fieldsMetadata = $this->entity['list']['fields'];
  439. if (!isset($fieldsMetadata[$property]) || 'toggle' !== $fieldsMetadata[$property]['dataType']) {
  440. throw new \RuntimeException(sprintf('The type of the "%s" property is not "toggle".', $property));
  441. }
  442. $this->updateEntityProperty($entity, $property, $newValue);
  443. $this->utils->addFlash('success', 'success.common.fieldChange');
  444. $response['flashMessages'] = $this->utils->getFlashMessages();
  445. return new Response(json_encode($response));
  446. }
  447. $fields = $this->entity['edit']['fields'];
  448. $editForm = $this->executeDynamicMethod('create<EntityName>EditForm', [$entity, $fields]);
  449. $deleteForm = $this->createDeleteForm($this->entity['name'], $id);
  450. $editForm->handleRequest($this->request);
  451. if ($editForm->isSubmitted() && $editForm->isValid()) {
  452. $this->processUploadedFiles($editForm);
  453. $this->dispatch(EasyAdminEvents::PRE_UPDATE, ['entity' => $entity]);
  454. $this->executeDynamicMethod('update<EntityName>Entity', [$entity, $editForm]);
  455. $this->dispatch(EasyAdminEvents::POST_UPDATE, ['entity' => $entity]);
  456. return $this->redirectToReferrer();
  457. }
  458. $this->dispatch(EasyAdminEvents::POST_EDIT);
  459. $parameters = [
  460. 'form' => $editForm->createView(),
  461. 'entity_fields' => $fields,
  462. 'entity' => $entity,
  463. 'delete_form' => $deleteForm->createView(),
  464. ];
  465. return $this->executeDynamicMethod('render<EntityName>Template', ['edit', $this->entity['templates']['edit'], $parameters]);
  466. }
  467. /* public function createNewEntity(){
  468. $idDuplicate = $this->request->query->get('duplicate', null);
  469. if($idDuplicate){
  470. $easyadmin = $this->request->attributes->get('easyadmin');
  471. $entity= $this->em->getRepository($easyadmin['entity']['class'])->find($idDuplicate);
  472. $newProductFamily = clone $entity ;
  473. $this->em->persist($newProductFamily) ;
  474. $this->em->flush() ;
  475. }else{
  476. $entityFullyQualifiedClassName = $this->entity['class'];
  477. return new $entityFullyQualifiedClassName();
  478. }
  479. }*/
  480. public function duplicateAction(){
  481. $id = $this->request->query->get('id');
  482. $refererUrl = $this->request->query->get('referer', '');
  483. $easyadmin = $this->request->attributes->get('easyadmin');
  484. $entity= $this->em->getRepository($easyadmin['entity']['class'])->find($id);
  485. $newEntity = $this->utilsProcess->duplicateEntity($entity);
  486. return $this->redirectToRoute('easyadmin', ['entity' => $easyadmin['entity']['name'], 'action' => 'edit', 'id' =>$newEntity->getId(), 'referer' =>$refererUrl ]) ;
  487. }
  488. public function duplicateOtherHubAction(){
  489. $id = $this->request->query->get('id');
  490. $hubAlias = $this->request->query->get('hub');
  491. $refererUrl = $this->request->query->get('referer', '');
  492. $user = $this->security->getUser() ;
  493. $easyadmin = $this->request->attributes->get('easyadmin');
  494. $entity= $this->em->getRepository($easyadmin['entity']['class'])->find($id);
  495. $hub= $this->em->getRepository(MerchantInterface::class)->findOneByDevAlias($hubAlias);
  496. $newEntity = $this->utilsProcess->duplicateEntityToOtherHub($entity,$hub);
  497. $user->setMerchant($hub);
  498. $this->em->persist($user);
  499. $this->em->flush();
  500. $redirectUrl = $this->generateUrl('easyadmin', ['entity' => $easyadmin['entity']['name'], 'action' => 'edit', 'id' =>$newEntity->getId(), 'referer' =>$refererUrl ]).'&hubredirection=true';
  501. return $this->redirectToOtherHub($hub, $redirectUrl) ;
  502. }
  503. public function redirectToOtherHub($hub, $url){
  504. if(strpos($_SERVER['HTTP_HOST'], 'localhost')!==false){
  505. return $this->redirect($url);
  506. }else{
  507. return $this->redirect($hub->getMerchantConfig('url').substr($url,1));
  508. }
  509. }
  510. }