Sfoglia il codice sorgente

Refactoring services

packProduct
Guillaume 3 anni fa
parent
commit
6dac73a22d
23 ha cambiato i file con 138 aggiunte e 78 eliminazioni
  1. +1
    -0
      Container/Merchant/MerchantContainer.php
  2. +1
    -1
      Container/Section/SectionContainer.php
  3. +11
    -1
      Container/Setting/MerchantSettingContainer.php
  4. +10
    -1
      Container/Setting/SectionSettingContainer.php
  5. +5
    -6
      Controller/AdminControllerTrait.php
  6. +1
    -1
      Controller/Credit/CreditHistoryAdminController.php
  7. +10
    -7
      Controller/Merchant/FavoriteMerchantController.php
  8. +5
    -1
      Controller/Merchant/SwitchMerchantController.php
  9. +2
    -3
      Controller/Newsletter/NewsletterAdminController.php
  10. +5
    -5
      Controller/Section/SectionAdminController.php
  11. +38
    -16
      Controller/Setting/SettingAdminController.php
  12. +2
    -1
      Controller/Site/NewsAdminController.php
  13. +1
    -1
      EventSubscriber/SettingEventSubscriber.php
  14. +3
    -2
      Factory/Newsletter/NewsletterFactory.php
  15. +5
    -1
      Factory/Section/OpeningFactory.php
  16. +3
    -2
      Factory/Site/NewsFactory.php
  17. +8
    -1
      Generator/OrderReferenceGenerator.php
  18. +0
    -8
      Model/Merchant/MerchantModel.php
  19. +0
    -3
      Model/Section/SectionModel.php
  20. +2
    -2
      Model/Site/NewsModel.php
  21. +2
    -1
      Model/Ticket/TicketModel.php
  22. +2
    -2
      Repository/Section/SectionStore.php
  23. +21
    -12
      Resolver/OpeningResolver.php

+ 1
- 0
Container/Merchant/MerchantContainer.php Vedi File

@@ -7,6 +7,7 @@ use Lc\CaracoleBundle\Factory\Merchant\MerchantFactory;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery;
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Solver\Setting\SettingSolver;

class MerchantContainer
{

+ 1
- 1
Container/Section/SectionContainer.php Vedi File

@@ -6,6 +6,7 @@ use Lc\CaracoleBundle\Factory\Section\SectionFactory;
use Lc\CaracoleBundle\Repository\Section\SectionRepositoryQuery;
use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Solver\Setting\SettingSolver;

class SectionContainer
{
@@ -45,5 +46,4 @@ class SectionContainer
{
return $this->store;
}

}

+ 11
- 1
Container/Setting/MerchantSettingContainer.php Vedi File

@@ -6,6 +6,7 @@ use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Factory\Setting\MerchantSettingFactory;
use Lc\CaracoleBundle\Repository\Setting\MerchantSettingRepositoryQuery;
use Lc\CaracoleBundle\Repository\Setting\MerchantSettingStore;
use Lc\SovBundle\Solver\Setting\SettingSolver;

class MerchantSettingContainer
{
@@ -13,16 +14,20 @@ class MerchantSettingContainer
protected MerchantSettingDefinition $definition;
protected MerchantSettingRepositoryQuery $repositoryQuery;
protected MerchantSettingStore $store;
protected SettingSolver $settingSolver;

public function __construct(
MerchantSettingFactory $factory,
MerchantSettingDefinition $definition,
MerchantSettingRepositoryQuery $repositoryQuery,
MerchantSettingStore $store
MerchantSettingStore $store,
SettingSolver $settingSolver
) {
$this->factory = $factory;
$this->definition = $definition;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->settingSolver = $settingSolver;
}

public function getFactory(): MerchantSettingFactory
@@ -45,4 +50,9 @@ class MerchantSettingContainer
return $this->store;
}

public function getSettingSolver(): SettingSolver
{
return $this->settingSolver;
}

}

+ 10
- 1
Container/Setting/SectionSettingContainer.php Vedi File

@@ -6,6 +6,7 @@ use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
use Lc\CaracoleBundle\Factory\Setting\SectionSettingFactory;
use Lc\CaracoleBundle\Repository\Setting\SectionSettingRepositoryQuery;
use Lc\CaracoleBundle\Repository\Setting\SectionSettingStore;
use Lc\SovBundle\Solver\Setting\SettingSolver;

class SectionSettingContainer
{
@@ -13,17 +14,20 @@ class SectionSettingContainer
protected SectionSettingDefinition $definition;
protected SectionSettingRepositoryQuery $repositoryQuery;
protected SectionSettingStore $store;
protected SettingSolver $settingSolver;

public function __construct(
SectionSettingFactory $factory,
SectionSettingDefinition $definition,
SectionSettingRepositoryQuery $repositoryQuery,
SectionSettingStore $store
SectionSettingStore $store,
SettingSolver $settingSolver
) {
$this->factory = $factory;
$this->definition = $definition;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->settingSolver = $settingSolver;
}

public function getFactory(): SectionSettingFactory
@@ -46,4 +50,9 @@ class SectionSettingContainer
return $this->store;
}

public function getSettingSolver(): SettingSolver
{
return $this->settingSolver;
}

}

+ 5
- 6
Controller/AdminControllerTrait.php Vedi File

@@ -72,7 +72,6 @@ use Lc\SovBundle\Factory\User\UserFactory;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\Response;


trait AdminControllerTrait
{

@@ -145,16 +144,16 @@ trait AdminControllerTrait
//TODO Gérer depuis les événements

if ($this->isInstanceOf(FilterMerchantInterface::class)) {
$queryBuilder->andWhereMerchant('entity', $this->get('merchant_resolver')->getCurrent());
$queryBuilder->andWhereMerchant('entity', $this->get(MerchantResolver::class)->getCurrent());
}

if ($this->isInstanceOf(FilterMultipleMerchantsInterface::class)) {
$queryBuilder->andWhere(':merchant MEMBER OF entity.merchants');
$queryBuilder->setParameter('merchant', $this->get('merchant_resolver')->getCurrent());
$queryBuilder->setParameter('merchant', $this->get(MerchantResolver::class)->getCurrent());
}

if ($this->isInstanceOf(FilterSectionInterface::class)) {
$queryBuilder->andWhereSection('entity', $this->get('section_resolver')->getCurrent());
$queryBuilder->andWhereSection('entity', $this->get(SectionResolver::class)->getCurrent());
}

return $queryBuilder;
@@ -325,7 +324,7 @@ trait AdminControllerTrait
{
$duplicateAction = Action::new(
'duplicateToOtherMerchant',
$this->get('translator_admin')->transAction('duplicateToOtherMerchant'),
$this->get(TranslatorAdmin::class)->transAction('duplicateToOtherMerchant'),
'fa fa-fw fa-copy'
)
->linkToCrudAction('duplicateToOtherMerchant')
@@ -338,7 +337,7 @@ trait AdminControllerTrait
{
$duplicateAction = Action::new(
'duplicateToOtherSection',
$this->get('translator_admin')->transAction('duplicateToOtherSection'),
$this->get(TranslatorAdmin::class)->transAction('duplicateToOtherSection'),
'fa fa-fw fa-copy'
)
->linkToCrudAction('duplicateToOtherSection')

+ 1
- 1
Controller/Credit/CreditHistoryAdminController.php Vedi File

@@ -88,7 +88,7 @@ abstract class CreditHistoryAdminController extends AbstractAdminController

public function configureFields(string $pageName): iterable
{
$translatorAdmin = $this->get('translator_admin');
$translatorAdmin = $this->get(TranslatorAdmin::class);
return [
IdField::new('id')->hideOnForm(),
// @TODO : transChoices

+ 10
- 7
Controller/Merchant/FavoriteMerchantController.php Vedi File

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

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -17,23 +18,25 @@ class FavoriteMerchantController extends AbstractController
*/
public function favoriteMerchant(Request $request, Security $security, EntityManagerInterface $entityManager)
{
$user = $security->getUser() ;
$user = $security->getUser();

if($user) {
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) ;
$entityManager->update($user) ;
$entityManager->flush() ;
$user->setFavoriteMerchant($merchant);
$entityManager->update($user);
$entityManager->flush();

// @TODO : à fignoler, hein gamin ?
$url = $merchant->getSettingValue(MerchantSettingDefinition::SETTING_URL).'admin';
$url = $this->get(MerchantContainer::class)->getSettingSolver()->getSettingValue(
$merchant,
MerchantSettingDefinition::SETTING_URL
) . 'admin';

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

+ 5
- 1
Controller/Merchant/SwitchMerchantController.php Vedi File

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

namespace Lc\CaracoleBundle\Controller\Merchant;

use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
@@ -24,7 +25,10 @@ class SwitchMerchantController extends AbstractController
$context = $form->get('context')->getData();

if ($merchant) {
$url = $merchant->getSettingValue(MerchantSettingDefinition::SETTING_URL);
$url = $this->get(MerchantContainer::class)->getSettingSolver()->getSettingValue(
$merchant,
MerchantSettingDefinition::SETTING_URL
);

if ($context == 'admin') {
$url .= 'admin';

+ 2
- 3
Controller/Newsletter/NewsletterAdminController.php Vedi File

@@ -3,8 +3,7 @@
namespace Lc\CaracoleBundle\Controller\Newsletter;

use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Factory\Newsletter\NewsletterFactory;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Container\Newsletter\NewsletterContainer;
use Lc\SovBundle\Controller\Newsletter\NewsletterAdminController as SovNewsletterAdminController;

@@ -16,7 +15,7 @@ abstract class NewsletterAdminController extends SovNewsletterAdminController
{
return $this->get(NewsletterContainer::class)
->getFactory()
->setMerchant($this->get(MerchantResolver::class)->getCurrent())
->setSection($this->get(SectionResolver::class)->getCurrent())
->create();
}
}

+ 5
- 5
Controller/Section/SectionAdminController.php Vedi File

@@ -30,15 +30,15 @@ abstract class SectionAdminController extends AbstractAdminController
[
FormField::addPanel('general'),
TextField::new('title'),
ChoiceField::new('cycle')
ChoiceField::new('cycleType')
->setRequired(true)
->hideOnIndex()
->setChoices(
[
'Jour' => SectionModel::CYCLE_DAY,
'Semaine' => SectionModel::CYCLE_WEEK,
'Mois' => SectionModel::CYCLE_MONTH,
'Année' => SectionModel::CYCLE_YEAR,
'Jour' => SectionModel::CYCLE_TYPE_DAY,
'Semaine' => SectionModel::CYCLE_TYPE_WEEK,
'Mois' => SectionModel::CYCLE_TYPE_MONTH,
'Année' => SectionModel::CYCLE_TYPE_YEAR,
]
),
TextField::new('color')

+ 38
- 16
Controller/Setting/SettingAdminController.php Vedi File

@@ -2,29 +2,51 @@

namespace Lc\CaracoleBundle\Controller\Setting;

use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
use Lc\CaracoleBundle\Container\Section\SectionContainer;
use Lc\CaracoleBundle\Container\Setting\MerchantSettingContainer;
use Lc\CaracoleBundle\Container\Setting\SectionSettingContainer;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Container\Setting\SiteSettingContainer;
use Lc\SovBundle\Container\Site\SiteContainer;
use Lc\SovBundle\Controller\Setting\SettingAdminController as SovSettingController;
use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
use Lc\CaracoleBundle\Form\Setting\MerchantSettingsFormType;
use Lc\CaracoleBundle\Form\Setting\SectionSettingsFormType;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\CaracoleBundle\Definition\SectionSettingDefinitionInterface;
use Lc\SovBundle\Definition\SiteSettingDefinition;
use Lc\SovBundle\Form\Setting\SiteSettingsFormType;
use Lc\SovBundle\Repository\Site\SiteRepository;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class SettingAdminController extends SovSettingController
{
protected MerchantResolver $merchantResolver;
protected SectionResolver $sectionResolver;
protected MerchantSettingContainer $merchantSettingContainer;
protected SectionSettingContainer $sectionSettingContainer;
protected SiteContainer $siteContainer;
protected SiteSettingContainer $siteSettingContainer;
protected TranslatorAdmin $translatorAdmin;

public function __construct(
EntityManagerInterface $entityManager,
MerchantResolver $merchantResolver,
SectionResolver $sectionResolver,
MerchantSettingContainer $merchantSettingContainer,
SectionSettingContainer $sectionSettingContainer,
SiteContainer $siteContainer,
SiteSettingContainer $siteSettingContainer,
TranslatorAdmin $translatorAdmin
) {
parent::__construct($entityManager);
$this->merchantResolver = $merchantResolver;
$this->sectionResolver = $sectionResolver;
$this->merchantSettingContainer = $merchantSettingContainer;
$this->sectionSettingContainer = $sectionSettingContainer;
$this->siteContainer = $siteContainer;
$this->siteSettingContainer = $siteSettingContainer;
$this->translatorAdmin = $translatorAdmin;
}

/**
* @Route("/admin/setting/merchant", name="carac_admin_setting_merchant")
*/
@@ -48,16 +70,16 @@ class SettingAdminController extends SovSettingController
$type
) {
$entity = null;
$entityManager = $this->get(EntityManagerInterface::class);
$entityManager = $this->entityManager;

if ($type == 'merchant') {
$resolver = $this->get(MerchantContainer::class)->getResolver();
$resolver = $this->merchantResolver;
$formClass = MerchantSettingsFormType::class;
$settingDefinition = $this->get(MerchantSettingContainer::class)->getDefinition();
$settingDefinition = $this->merchantSettingContainer->getDefinition();
} elseif ($type == 'section') {
$resolver = $this->get(SectionContainer::class)->getResolver();
$resolver = $this->sectionResolver;
$formClass = SectionSettingsFormType::class;
$settingDefinition = $this->get(SectionSettingContainer::class)->getDefinition();
$settingDefinition = $this->sectionSettingContainer->getDefinition();
}

$entity = $resolver->getCurrent();
@@ -91,7 +113,7 @@ class SettingAdminController extends SovSettingController
*/
public function manageGlobal(Request $request, EntityManagerInterface $entityManager)
{
$site = $this->get(SiteContainer::class)->getStore()->getOneByDevAlias('default');
$site = $this->siteContainer->getStore()->getOneByDevAlias('default');
$form = $this->createForm(SiteSettingsFormType::class, $site);

$form->handleRequest($request);
@@ -100,13 +122,13 @@ class SettingAdminController extends SovSettingController
$entityManager->update($site);
$entityManager->flush();

$this->addFlash('success', $this->get(TranslatorAdmin::class)->transFlashMessage('settings_saved'));
$this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved'));
}

return $this->render(
'@LcCaracole/admin/setting/edit_site.html.twig',
[
'setting_definition' => $this->siteSettingDefinition,
'setting_definition' => $this->siteSettingContainer->getDefinition(),
'form' => $form->createView()
]
);

+ 2
- 1
Controller/Site/NewsAdminController.php Vedi File

@@ -5,6 +5,7 @@ namespace Lc\CaracoleBundle\Controller\Site;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Factory\Site\NewsFactory;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Container\Site\NewsContainer;
use Lc\SovBundle\Controller\Site\NewsAdminController as SovNewsAdminController;

@@ -16,7 +17,7 @@ abstract class NewsAdminController extends SovNewsAdminController
{
return $this->get(NewsContainer::class)
->getFactory()
->setMerchant($this->get(MerchantResolver::class)->getCurrent())
->setSection($this->get(SectionResolver::class)->getCurrent())
->create();
}
}

+ 1
- 1
EventSubscriber/SettingEventSubscriber.php Vedi File

@@ -82,7 +82,7 @@ class SettingEventSubscriber implements EventSubscriberInterface
foreach ($entities as $entity) {
foreach ($settings as $category => $settingList) {
foreach ($settingList as $settingName => $setting) {
$entitySetting = $entity->getSetting($settingName);
$entitySetting = $this->settingSolver->getSetting($entity, $settingName);

if (!$entitySetting) {
// gestion du cas des SectionSetting spécifiques à une section

+ 3
- 2
Factory/Newsletter/NewsletterFactory.php Vedi File

@@ -3,18 +3,19 @@
namespace Lc\CaracoleBundle\Factory\Newsletter;

use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
use Lc\SovBundle\Factory\Newsletter\NewsletterFactory as SovNewsletterFactory;

class NewsletterFactory extends SovNewsletterFactory
{
use MerchantFactoryTrait;
use SectionFactoryTrait;

public function create(): NewsletterInterface
{
$newsletter = parent::create();

$newsletter->setMerchant($this->merchant);
$newsletter->setSection($this->section);

return $newsletter;
}

+ 5
- 1
Factory/Section/OpeningFactory.php Vedi File

@@ -21,7 +21,11 @@ class OpeningFactory extends AbstractFactory
$opening = new Opening();

$opening->setSection($section);
$opening->setDay($day);

if($day) {
$opening->setDay($day);
}

$opening->setTimeStart($timeStart);
$opening->setTimeEnd($timeEnd);
$opening->setGroupUser($groupUser);

+ 3
- 2
Factory/Site/NewsFactory.php Vedi File

@@ -3,19 +3,20 @@
namespace Lc\CaracoleBundle\Factory\Site;

use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\SovBundle\Factory\Site\NewsFactory as SovNewsFactory;
use Lc\SovBundle\Model\Site\NewsInterface;

class NewsFactory extends SovNewsFactory
{
use MerchantFactoryTrait;
use SectionFactoryTrait;

public function create(): NewsInterface
{
$news = parent::create();

$news->setMerchant($this->merchant);
$news->setSection($this->section);

return $news;
}

+ 8
- 1
Generator/OrderReferenceGenerator.php Vedi File

@@ -5,9 +5,16 @@ namespace Lc\CaracoleBundle\Generator;
use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Section\SectionModel;
use Lc\SovBundle\Solver\Setting\SettingSolver;

class OrderReferenceGenerator
{
protected SettingSolver $settingSolver;

public function __construct(SettingSolver $settingSolver)
{
$this->settingSolver = $settingSolver;
}

public function buildReference(OrderShopInterface $orderShop, \DateTime $distributionDate = null): string
{
@@ -56,7 +63,7 @@ class OrderReferenceGenerator

public function getPrefixReference(OrderShopInterface $orderShop): string
{
return $orderShop->getSection()->getSettingValue(SectionSettingDefinition::SETTING_REFERENCE_PREFIX);;
return $this->settingSolver->getSettingValue($orderShop->getSection(), SectionSettingDefinition::SETTING_REFERENCE_PREFIX);
}

public function numberPad($number, $length): string

+ 0
- 8
Model/Merchant/MerchantModel.php Vedi File

@@ -8,14 +8,8 @@ use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\Config\TaxRateInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface;
use Lc\SovBundle\Model\Setting\EntitySettingTrait;
use Lc\SovBundle\Model\Site\NewsInterface;
use Lc\SovBundle\Model\Site\PageInterface;
use Lc\SovBundle\Model\User\GroupUserInterface;
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;

@@ -25,8 +19,6 @@ use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
abstract class MerchantModel extends AbstractFullEntity
{

use EntitySettingTrait;

/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Config\TaxRateInterface")
* @ORM\JoinColumn(nullable=false)

+ 0
- 3
Model/Section/SectionModel.php Vedi File

@@ -12,7 +12,6 @@ use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface;
use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
use Lc\SovBundle\Model\Setting\EntitySettingTrait;
use Lc\SovBundle\Model\Site\NewsInterface;
use Lc\SovBundle\Model\Site\PageInterface;
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
@@ -22,8 +21,6 @@ use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
*/
abstract class SectionModel extends AbstractFullEntity implements FilterMerchantInterface
{
use EntitySettingTrait;

/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface", inversedBy="sections")
* @ORM\JoinColumn(nullable=false)

+ 2
- 2
Model/Site/NewsModel.php Vedi File

@@ -3,14 +3,14 @@
namespace Lc\CaracoleBundle\Model\Site;

use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Model\Site\NewsModel as SovNewsModel;

/**
* @ORM\MappedSuperclass()
*/
abstract class NewsModel extends SovNewsModel implements FilterMerchantInterface
abstract class NewsModel extends SovNewsModel implements FilterSectionInterface
{
/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", inversedBy="news")

+ 2
- 1
Model/Ticket/TicketModel.php Vedi File

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Model\Ticket;

use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Model\Ticket\TicketModel as SovTicketModel;
@@ -11,7 +12,7 @@ use Lc\SovBundle\Model\Ticket\TicketModel as SovTicketModel;
/**
* @ORM\MappedSuperclass()
*/
abstract class TicketModel extends SovTicketModel implements FilterMerchantInterface
abstract class TicketModel extends SovTicketModel implements FilterSectionInterface
{
const TYPE_PRODUCT_UNAVAILABLE = 'product-unavailable';
const TYPE_PRODUCT_ERROR = 'product-error';

+ 2
- 2
Repository/Section/SectionStore.php Vedi File

@@ -47,9 +47,9 @@ class SectionStore extends AbstractStore
}

// getSection
public function getOneByDevAlias(string $devAlias, bool $isOnline = true, $query = null): ?SectionInterface
public function getOneOnlineByDevAlias(string $devAlias, $query = null): ?SectionInterface
{
$section = parent::getOneByDevAlias($devAlias, $isOnline, $query);
$section = parent::getOneOnlineByDevAlias($devAlias, $query);

if (!$section) {
throw new NotFoundHttpException('La section ' . $devAlias . ' est introuvable');

+ 21
- 12
Resolver/OpeningResolver.php Vedi File

@@ -8,23 +8,30 @@ use Lc\CaracoleBundle\Model\Section\OpeningInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Symfony\Component\Security\Core\Security;

class OpeningResolver
{
const OPENING_CONTEXT_FRONTEND = 'frontend' ;
const OPENING_CONTEXT_BACKEND = 'backend' ;
const OPENING_CONTEXT_FRONTEND = 'frontend';
const OPENING_CONTEXT_BACKEND = 'backend';

protected array $messages = [];
protected SectionResolver $sectionResolver;
protected Security $security;
protected OrderShopStore $orderShopStore;

public function __construct(SectionResolver $sectionResolver, Security $security, OrderShopStore $orderShopStore)
{
protected SettingSolver $settingSolver;

public function __construct(
SectionResolver $sectionResolver,
Security $security,
OrderShopStore $orderShopStore,
SettingSolver $settingSolver
) {
$this->sectionResolver = $sectionResolver;
$this->security = $security;
$this->orderShopStore = $orderShopStore;
$this->settingSolver = $settingSolver;
}

public function isOpenSale(
@@ -41,7 +48,7 @@ class OpeningResolver
}

// État des prise de commande (voir configuration de section)
$orderState = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_STATE);
$orderState = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_STATE);

if ($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_OPEN) {
$this->addMessage('Les commandes sont ouvertes (configuration de la section).');
@@ -54,13 +61,13 @@ class OpeningResolver
}

// Nombre maximum de commandes par cycle (voir configuration de section)
if($this->isMaximumOrderCycleAchieved($section)) {
if ($this->isMaximumOrderCycleAchieved($section)) {
$this->addMessage('Le nombre maximum de commande a été atteint.');
return false;
}

// Période de fermeture des commandes issue de la configuration de la section (congés)
if($this->isClosingPeriod($section, $date)) {
if ($this->isClosingPeriod($section, $date)) {
$this->addMessage(
'Les commandes sont fermées (période de fermeture des commandes dans la configuration de la section).'
);
@@ -71,7 +78,9 @@ class OpeningResolver
$openings = $section->getOpenings();

foreach ($openings as $opening) {
if(!$opening->getGroupUser() || ($opening->getGroupUser() && $user && $user->getGroupUsers()->contains($opening->getGroupUser()))) {
if (!$opening->getGroupUser() || ($opening->getGroupUser() && $user && $user->getGroupUsers()->contains(
$opening->getGroupUser()
))) {
if ($this->isDateMatchWithOpening($date, $opening)) {
$this->addMessage('Les commandes sont ouvertes (périodes d\'ouverture classique des commandes).');
return true;
@@ -87,8 +96,8 @@ class OpeningResolver
// isHolidays
public function isClosingPeriod(SectionInterface $section, \DateTime $date)
{
$orderClosedStart = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_START);
$orderClosedEnd = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_END);
$orderClosedStart = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_CLOSED_START);
$orderClosedEnd = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_CLOSED_END);

if ($orderClosedStart && $orderClosedEnd && $date >= $orderClosedStart && $date <= $orderClosedEnd) {
return true;
@@ -101,7 +110,7 @@ class OpeningResolver
public function isMaximumOrderCycleAchieved(SectionInterface $section)
{
$countOrderShopCycle = $this->orderShopStore->countValidByCurrentCycle();
$orderMaximumPerCycle = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_MAXIMUM_PER_CYCLE);
$orderMaximumPerCycle = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_MAXIMUM_PER_CYCLE);
if ($orderMaximumPerCycle && $countOrderShopCycle >= $orderMaximumPerCycle) {
return true;
}

Loading…
Annulla
Salva