Browse Source

Paramètres : ajout des champs multiplyingFactor, dateBeginHoliday, dateEndHoliday, imageZones

reduction
Guillaume 4 years ago
parent
commit
6a30ea4d64
4 changed files with 103 additions and 21 deletions
  1. +9
    -15
      ShopBundle/Controller/Admin/AdminController.php
  2. +16
    -6
      ShopBundle/Controller/Admin/MerchantController.php
  3. +13
    -0
      ShopBundle/Form/MerchantConfigType.php
  4. +65
    -0
      ShopBundle/Repository/MerchantConfigRepository.php

+ 9
- 15
ShopBundle/Controller/Admin/AdminController.php View File

@@ -2,38 +2,28 @@

namespace Lc\ShopBundle\Controller\Admin;

use App\Entity\PointSale;
use App\Entity\ProductCategory;
use App\Entity\ProductFamily;
use Doctrine\DBAL\Types\TextType;
use Doctrine\ORM\EntityManager;
use App\Entity\MerchantConfig;
use Lc\ShopBundle\Context\AddressInterface;
use Lc\ShopBundle\Repository\MerchantConfigRepository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController;
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
use FOS\UserBundle\Model\UserManagerInterface;
use Lc\ShopBundle\Context\MerchantConfigInterface;
use Lc\ShopBundle\Context\MerchantInterface;
use Lc\ShopBundle\Context\ProductCategoryInterface;
use Lc\ShopBundle\Context\SortableInterface;
use Lc\ShopBundle\Context\StatusInterface;
use Lc\ShopBundle\Context\TaxRateInterface;
use Lc\ShopBundle\Context\TreeInterface;
use Lc\ShopBundle\Form\AbstractEditPositionType;
use Lc\ShopBundle\Form\ChoiceProductCategoryType;
use Lc\ShopBundle\Form\PriceType;
use Lc\ShopBundle\Form\ProductType;
use Lc\ShopBundle\Form\Widget\PriceWidgetType;
use Lc\ShopBundle\Repository\BaseRepository;
use Lc\ShopBundle\Repository\ProductCategoryRepository;
use Lc\ShopBundle\Services\Utils;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Security;

class AdminController extends EasyAdminController
@@ -43,7 +33,11 @@ class AdminController extends EasyAdminController
protected $em ;
protected $utils ;

public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, Utils $utils)
public function __construct(
Security $security,
UserManagerInterface $userManager,
EntityManagerInterface $em,
Utils $utils)
{
$this->security = $security;
$this->userManager = $userManager;

+ 16
- 6
ShopBundle/Controller/Admin/MerchantController.php View File

@@ -2,7 +2,7 @@

namespace Lc\ShopBundle\Controller\Admin;

use App\Entity\MerchantConfig;
use Lc\ShopBundle\Context\MerchantConfigInterface;
use Lc\ShopBundle\Context\MerchantInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -25,8 +25,10 @@ class MerchantController extends AdminController
public function createAvailableOptions($entity)
{
$merchantConfigs = $entity->getMerchantConfigs() ;
$availableOptions = MerchantConfig::getAvailableOptions() ;
$classMerchantConfig = $this->em->getClassMetadata(MerchantConfigInterface::class)->getName() ;
$availableOptions = $classMerchantConfig::getAvailableOptions() ;

$addConfig = false ;
foreach($availableOptions as $key => $option) {
$optionExist = false ;
foreach($merchantConfigs as $merchantConfig) {
@@ -35,13 +37,21 @@ class MerchantController extends AdminController
}
}
if(!$optionExist) {
$merchantConfig = new MerchantConfig();
$merchantConfig->setName($key)->setValue($merchantConfig->getOptionValue('default'))->setMerchant($entity) ;
$this->em->persist($merchantConfig);
$newMerchantConfig = new $classMerchantConfig ;
$newMerchantConfig
->setName($key)
->setMerchant($this->security->getUser()->getMerchant()) ;
if(isset($option['default'])) {
$newMerchantConfig->setValue($option['default']) ;
}
$addConfig = true ;
$this->em->persist($newMerchantConfig);
}
}

$this->em->flush() ;
if($addConfig) {
$this->em->flush() ;
}
}

public function editAction()

+ 13
- 0
ShopBundle/Form/MerchantConfigType.php View File

@@ -2,8 +2,10 @@

namespace Lc\ShopBundle\Form;

use CKSource\Bundle\CKFinderBundle\Form\Type\CKFinderFileChooserType;
use Lc\ShopBundle\Context\MerchantConfigInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Doctrine\ORM\EntityManagerInterface;
@@ -39,6 +41,17 @@ class MerchantConfigType extends AbstractType
'choices' => $merchantConfig->getChoices()
]);
}
elseif($merchantConfig->getFieldType() == 'date') {
$form->add('value', DateType::class, [
'label' => $merchantConfig->getLabel(),
'widget' => 'single_text',
]);
}
elseif($merchantConfig->getFieldType() == 'image') {
$form->add('value', CKFinderFileChooserType::class, [
'label' => $merchantConfig->getLabel(),
]);
}
else {
if($merchantConfig->getOption()) {
$form->add('value', TextType::class, [

+ 65
- 0
ShopBundle/Repository/MerchantConfigRepository.php View File

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

namespace Lc\ShopBundle\Repository;

use App\Entity\MerchantConfig;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManager;
use Lc\ShopBundle\Context\MerchantConfigInterface;
use Lc\ShopBundle\Repository\BaseRepository;
use Symfony\Component\Security\Core\Security;

/**
* @method MerchantConfig|null find($id, $lockMode = null, $lockVersion = null)
* @method MerchantConfig|null findOneBy(array $criteria, array $orderBy = null)
* @method MerchantConfig[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class MerchantConfigRepository extends BaseRepository
{
protected $security ;

public function __construct(EntityManager $entityManager, Security $security)
{
$this->security = $security ;
parent::__construct($entityManager, MerchantConfigInterface::class);
}

public function findAll()
{
return $this->createQueryBuilder('m')
->andWhere('m.merchant = :currentMerchant')
->setParameter('currentMerchant', $this->security->getUser()->getMerchant()->getId())
->getQuery()
->getResult();
}

// /**
// * @return MerchantConfig[] Returns an array of MerchantConfig objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('m')
->andWhere('m.exampleField = :val')
->setParameter('val', $value)
->orderBy('m.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/

/*
public function findOneBySomeField($value): ?MerchantConfig
{
return $this->createQueryBuilder('m')
->andWhere('m.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}

Loading…
Cancel
Save