Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

FavoriteMerchantAdminController.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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\ActionDefinition;
  7. use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
  8. use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Security\Core\Security;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class FavoriteMerchantAdminController extends AbstractController
  13. {
  14. /**
  15. * @Route("/admin/merchant/favorite", name="carac_merchant_favorite_admin")
  16. */
  17. public function favoriteMerchant(Request $request, Security $security, EntityManagerInterface $entityManager)
  18. {
  19. $form = $this->createForm(SwitchMerchantFormType::class);
  20. $form->handleRequest($request);
  21. if ($form->isSubmitted() && $form->isValid()) {
  22. $merchant = $form->get('merchant')->getData();
  23. if ($merchant) {
  24. $user = $security->getUser();
  25. if ($user) {
  26. $user->setFavoriteMerchant($merchant);
  27. $entityManager->update($user);
  28. $entityManager->flush();
  29. }
  30. $this->addFlashTranslator('success', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant', ['%merchant%' => $merchant->getTitle()]);
  31. }
  32. } else {
  33. $this->addFlashTranslator('error', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant');
  34. }
  35. return $this->redirect($request->headers->get('referer'));
  36. }
  37. }