|
12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
-
- namespace Lc\CaracoleBundle\Controller\Merchant;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
- use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\Security\Core\Security;
-
- class FavoriteMerchantController extends AbstractController
- {
- public function favoriteMerchant(Request $request, Security $security, EntityManagerInterface $em)
- {
- $user = $security->getUser() ;
-
- if($user) {
- $form = $this->createForm(SwitchMerchantFormType::class);
- $form->handleRequest($request);
-
- if ($form->isSubmitted() && $form->isValid()) {
-
- $merchant = $form->get('merchant')->getData();
-
- if ($merchant) {
- $user->setFavoriteMerchant($merchant) ;
- $em->update($user) ;
- $em->flush() ;
-
- $url = $merchant->getSettingValue(MerchantSettingDefinition::SETTING_URL).'admin';
-
- if ($url) {
- return $this->redirect($url);
- }
- }
- }
- }
- }
- }
|