Bläddra i källkod

Switch merchant

feature/ticket
Guillaume 3 år sedan
förälder
incheckning
5064e2db5e
4 ändrade filer med 31 tillägg och 18 borttagningar
  1. +16
    -14
      Controller/Merchant/SwitchMerchantController.php
  2. +10
    -0
      Form/Merchant/SwitchMerchantFormType.php
  3. +1
    -1
      Resources/views/adminlte/layout.html.twig
  4. +4
    -3
      Twig/TwigExtension.php

+ 16
- 14
Controller/Merchant/SwitchMerchantController.php Visa fil

@@ -3,6 +3,7 @@
namespace Lc\CaracoleBundle\Controller\Merchant;

use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Doctrine\EntityManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@@ -11,25 +12,26 @@ use Symfony\Component\Security\Core\Security;
class SwitchMerchantController extends AbstractController
{

public function switchMerchant(Request $request, Security $security, EntityManager $em)
public function switchMerchant(Request $request)
{
$user = $security->getUser() ;
$form = $this->createForm(SwitchMerchantFormType::class);
$form->handleRequest($request);

if($user) {
$form = $this->createForm(SwitchMerchantFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$merchant = $form->get('merchants')->getData();
$context = $form->get('context')->getData();

if ($form->isSubmitted() && $form->isValid()) {
$merchant = $form->get('merchants')->getData();
$user->setFavoriteMerchant($merchant) ;
$em->update($user) ;
$em->flush() ;
if ($merchant) {
$url = $merchant->getMerchantConfig('url');

return $this->redirectToRoute('admin_dashboard') ;
}
}
else {
if($context == 'admin') {
$url .= 'admin' ;
}

if ($url) {
return $this->redirect($url);
}
}
}
}
}

+ 10
- 0
Form/Merchant/SwitchMerchantFormType.php Visa fil

@@ -9,6 +9,7 @@ use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

@@ -36,6 +37,14 @@ class SwitchMerchantFormType extends AbstractType
'data' => $options['current_merchant']
]
);

$builder->add(
'context',
HiddenType::class,
[
'data' => $options['context']
]
);
}

/**
@@ -45,6 +54,7 @@ class SwitchMerchantFormType extends AbstractType
{
$resolver->setDefaults(
[
'context' => 'frontend',
'current_merchant' => $this->merchantResolver->getCurrent(),
]
);

+ 1
- 1
Resources/views/adminlte/layout.html.twig Visa fil

@@ -13,7 +13,7 @@
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
{% set form_switch_merchant = carac_get_form_switch_merchhant() %}
{% set form_switch_merchant = carac_get_form_switch_merchant('admin') %}
{{ form_start(form_switch_merchant) }}
{{ form(form_switch_merchant) }}
{{ form_end(form_switch_merchant) }}

+ 4
- 3
Twig/TwigExtension.php Visa fil

@@ -41,7 +41,7 @@ class TwigExtension extends AbstractExtension
{
return array(
new TwigFunction('carac_get_sections', [$this, 'getSections']),
new TwigFunction('carac_get_form_switch_merchhant', [$this, 'getFormSwitchMerchant']),
new TwigFunction('carac_get_form_switch_merchant', [$this, 'getFormSwitchMerchant']),
);
}

@@ -55,14 +55,15 @@ class TwigExtension extends AbstractExtension
return $this->merchantRepository->findAll();
}

public function getFormSwitchMerchant()
public function getFormSwitchMerchant($context = 'front')
{
$form = $this->formFactory->create(
SwitchMerchantFormType::class,
null,
[
'action' => $this->urlGenerator->generate('carac_switch_merchant'),
'attr' => ['class' => 'switch-merchant']
'attr' => ['class' => 'switch-merchant'],
'context' => $context
]
);
return $form->createView();

Laddar…
Avbryt
Spara