Parcourir la source

Formulaire des Merchant : heures/jours d'ouverture/fermeture des commandes + page paramètres pour les admins (édition du Merchant courant)

reduction
Guillaume il y a 4 ans
Parent
révision
8e15a7989f
3 fichiers modifiés avec 119 ajouts et 1 suppressions
  1. +30
    -0
      ShopBundle/Controller/Admin/MerchantController.php
  2. +88
    -0
      ShopBundle/Form/MerchantConfigType.php
  3. +1
    -1
      ShopBundle/Model/Merchant.php

+ 30
- 0
ShopBundle/Controller/Admin/MerchantController.php Voir le fichier

@@ -9,6 +9,36 @@ use Symfony\Component\HttpFoundation\Request;
class MerchantController extends AdminController
{

public function editAction()
{
// paramètres (admin)
$isSettings = $this->request->query->get('is_settings') ;
if($isSettings) {
$idMerchant = $this->security->getUser()->getMerchant()->getId() ;
$this->request->query->set('id', $idMerchant) ;
$easyadmin = $this->request->attributes->get('easyadmin');
$merchant = $this->getDoctrine()
->getRepository(MerchantInterface::class)
->find($idMerchant);
$easyadmin['item'] = $merchant;
$this->request->attributes->set('easyadmin', $easyadmin) ;

$response = parent::editAction() ;

if ($response instanceof RedirectResponse) {
$referer = $this->request->headers->get('referer');
return new RedirectResponse($referer);
}
else {
return $response ;
}
}
// édition des Merchant (super admin)
else {
return parent::editAction() ;
}
}

public function switchMerchantAction(Request $request): RedirectResponse
{
$em = $this->getDoctrine()->getManager();

+ 88
- 0
ShopBundle/Form/MerchantConfigType.php Voir le fichier

@@ -0,0 +1,88 @@
<?php

namespace Lc\ShopBundle\Form;

use Lc\ShopBundle\Context\MerchantConfigInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security;

class MerchantConfigType extends AbstractType
{
protected $em;

public function __construct(EntityManagerInterface $entityManager, Security $security)
{
$this->em = $entityManager;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{

$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$form = $event->getForm();
$merchantConfig = $event->getData();

if ($merchantConfig) {

switch ($merchantConfig->getName()) {
case 'order-open-day' :
$label = 'Jour d\'ouverture des commandes';
break;
case 'order-open-time' :
$label = 'Heure d\'ouverture des commandes';
break;
case 'order-close-day' :
$label = 'Jour de fermeture des commandes';
break;
case 'order-close-time' :
$label = 'Heure de fermeture des commandes';
break;
}

$choicesArray = [] ;

if (strpos($merchantConfig->getName(), 'time') !== false) {
for($i = 0; $i < 24 ; $i++) {
$choicesArray[$i.'h'] = $i.':00' ;
}
}

if (strpos($merchantConfig->getName(), 'day') !== false) {
$choicesArray = [
'Lundi' => 1,
'Mardi' => 2,
'Mercredi' => 3,
'Jeudi' => 4,
'Vendredi' => 5,
'Samedi' => 6,
'Dimanche' => 7,
] ;
}

$form->add('name', HiddenType::class)
->add('value', ChoiceType::class, [
'label' => $label,
'choices' => $choicesArray
]);
}
});

}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'label' => false,
'data_class' => $this->em->getClassMetadata(MerchantConfigInterface::class)->getName(),
]);
}
}


+ 1
- 1
ShopBundle/Model/Merchant.php Voir le fichier

@@ -34,7 +34,7 @@ abstract class Merchant extends AbstractDocumentEntity
protected $productFamilies;

/**
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\MerchantConfigInterface", mappedBy="merchant", orphanRemoval=true)
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\MerchantConfigInterface", mappedBy="merchant", orphanRemoval=true, cascade={"persist"})
*/
protected $merchantConfigs;


Chargement…
Annuler
Enregistrer