選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

46 行
1.6KB

  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. }