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

FavoriteMerchantAdminController.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Merchant;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
  5. use Lc\CaracoleBundle\Controller\AbstractController;
  6. use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
  7. use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Security\Core\Security;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class FavoriteMerchantAdminController extends AbstractController
  12. {
  13. /**
  14. * @Route("/admin/merchant/favorite", name="carac_merchant_favorite_admin")
  15. */
  16. public function favoriteMerchant(Request $request, Security $security, EntityManagerInterface $entityManager)
  17. {
  18. $form = $this->createForm(SwitchMerchantFormType::class);
  19. $form->handleRequest($request);
  20. if ($form->isSubmitted() && $form->isValid()) {
  21. $merchant = $form->get('merchant')->getData();
  22. if ($merchant) {
  23. $user = $security->getUser();
  24. if($user) {
  25. $user->setFavoriteMerchant($merchant);
  26. $entityManager->update($user);
  27. $entityManager->flush();
  28. }
  29. // @TODO : à fignoler, hein gamin ?
  30. $url = $this->getSettingSolver()->getSettingValue(
  31. $merchant,
  32. MerchantSettingDefinition::SETTING_URL
  33. ) . 'admin';
  34. if ($url) {
  35. return $this->redirect($url);
  36. }
  37. }
  38. }
  39. }
  40. }