|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
-
- namespace Lc\CaracoleBundle\Controller\Merchant;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
- use Lc\CaracoleBundle\Controller\AbstractController;
- use Lc\CaracoleBundle\Definition\ActionDefinition;
- use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
- use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\Security\Core\Security;
- use Symfony\Component\Routing\Annotation\Route;
-
- class FavoriteMerchantAdminController extends AbstractController
- {
- /**
- * @Route("/admin/merchant/favorite", name="carac_merchant_favorite_admin")
- */
- public function favoriteMerchant(Request $request, Security $security, EntityManagerInterface $entityManager)
- {
- $form = $this->createForm(SwitchMerchantFormType::class);
- $form->handleRequest($request);
-
- if ($form->isSubmitted() && $form->isValid()) {
- $merchant = $form->get('merchant')->getData();
-
- if ($merchant) {
-
- $user = $security->getUser();
- if ($user) {
- $user->setFavoriteMerchant($merchant);
- $entityManager->update($user);
- $entityManager->flush();
- }
-
- $this->addFlashTranslator('success', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant', ['%merchant%' => $merchant->getTitle()]);
- }
-
- } else {
- $this->addFlashTranslator('error', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant');
- }
-
- return $this->redirect($request->headers->get('referer'));
- }
- }
|