You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 line
1.2KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Merchant;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
  5. use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\Security\Core\Security;
  9. class FavoriteMerchantController extends AbstractController
  10. {
  11. public function favoriteMerchant(Request $request, Security $security, EntityManagerInterface $em)
  12. {
  13. $user = $security->getUser() ;
  14. if($user) {
  15. $form = $this->createForm(SwitchMerchantFormType::class);
  16. $form->handleRequest($request);
  17. if ($form->isSubmitted() && $form->isValid()) {
  18. $merchant = $form->get('merchant')->getData();
  19. if ($merchant) {
  20. $user->setFavoriteMerchant($merchant) ;
  21. $em->update($user) ;
  22. $em->flush() ;
  23. $url = $merchant->getSettingValue(MerchantSettingDefinition::SETTING_URL).'admin';
  24. if ($url) {
  25. return $this->redirect($url);
  26. }
  27. }
  28. }
  29. }
  30. }
  31. }