Преглед изворни кода

Système ouverture des commandes

packProduct
Guillaume пре 3 година
родитељ
комит
b5e2bc3eaf
22 измењених фајлова са 764 додато и 43 уклоњено
  1. +56
    -0
      Controller/Section/OpeningAdminController.php
  2. +3
    -0
      Controller/Section/SectionAdminController.php
  3. +72
    -0
      Definition/SectionSettingDefinition.php
  4. +42
    -0
      EventSubscriber/OpeningEventSubscriber.php
  5. +40
    -28
      EventSubscriber/SettingEventSubscriber.php
  6. +30
    -0
      Factory/Section/OpeningFactory.php
  7. +8
    -0
      Factory/Section/OpeningFactoryInterface.php
  8. +6
    -1
      Factory/Setting/MerchantSettingFactory.php
  9. +9
    -5
      Factory/Setting/SectionSettingFactory.php
  10. +3
    -0
      Form/Setting/BaseSettingType.php
  11. +17
    -0
      Model/Order/OrderShopModel.php
  12. +8
    -0
      Model/Section/OpeningInterface.php
  13. +115
    -0
      Model/Section/OpeningModel.php
  14. +36
    -0
      Model/Section/SectionModel.php
  15. +44
    -0
      Model/User/GroupUserModel.php
  16. +67
    -0
      ReferenceBuilder/OrderReferenceBuilder.php
  17. +15
    -0
      Repository/Section/OpeningRepository.php
  18. +14
    -0
      Repository/Section/OpeningRepositoryQuery.php
  19. +13
    -0
      Repository/Section/OpeningStore.php
  20. +141
    -0
      Resolver/OpeningResolver.php
  21. +14
    -1
      Resources/translations/admin.fr.yaml
  22. +11
    -8
      Twig/StoreTwigExtension.php

+ 56
- 0
Controller/Section/OpeningAdminController.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\Controller\Section;

use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TimeField;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\SovBundle\Controller\AbstractAdminController;

abstract class OpeningAdminController extends AbstractAdminController
{
use AdminControllerTrait;

public function configureFields(string $pageName): iterable
{
$fields = parent::configureFields($pageName);

return array_merge(
[
ChoiceField::new('day')
->setRequired(true)
->setChoices(
[
'Lundi' => 1,
'Mardi' => 2,
'Mercredi' => 3,
'Jeudi' => 4,
'Vendredi' => 5,
'Samedi' => 6,
'Dimanche' => 7,
]
),
TimeField::new('timeStart')
->setRequired(false)
->setFormat('H:mm'),
TimeField::new('timeEnd')
->setRequired(false)
->setFormat('H:mm'),
AssociationField::new('groupUser'),
],
$fields
);
}

public function configureCrud(Crud $crud): Crud
{
$crud = parent::configureCrud($crud);

$crud->setDefaultSort(['day' => 'ASC']);

return $crud;
}

}

+ 3
- 0
Controller/Section/SectionAdminController.php Прегледај датотеку

@@ -7,11 +7,14 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Form\Section\OpeningsFormType;
use Lc\CaracoleBundle\Model\Section\SectionModel;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\StatusField;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

abstract class SectionAdminController extends AbstractAdminController
{

+ 72
- 0
Definition/SectionSettingDefinition.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\Definition;

use Lc\SovBundle\Definition\AbstractSettingDefinition;

class SectionSettingDefinition extends AbstractSettingDefinition implements SectionSettingDefinitionInterface
{
const CATEGORY_GENERAL = 'general';

const SETTING_REFERENCE_PREFIX = 'orderReferencePrefix';
const SETTING_ORDER_STATE = 'orderState';
const SETTING_ORDER_CLOSED_START = 'orderClosedStart';
const SETTING_ORDER_CLOSED_END = 'orderClosedEnd';
const SETTING_ORDER_MAXIMUM_PER_CYCLE = 'orderMaximumPerCycle';

const VALUE_ORDER_STATE_DEFAULT = 'default';
const VALUE_ORDER_STATE_OPEN = 'open';
const VALUE_ORDER_STATE_CLOSED = 'closed';

public function __construct()
{
$this->addSettingText(
[
'name' => self::SETTING_REFERENCE_PREFIX,
'category' => self::CATEGORY_GENERAL,
]
);

$this->addSettingSelect(
[
'name' => self::SETTING_ORDER_STATE,
'category' => self::CATEGORY_GENERAL,
'choices' => [
'Suivant configuration ouvertures' => self::VALUE_ORDER_STATE_DEFAULT,
'Ouvertes' => self::VALUE_ORDER_STATE_OPEN,
'Fermées' => self::VALUE_ORDER_STATE_CLOSED,
],
'default' => self::VALUE_ORDER_STATE_DEFAULT
]
);

$this->addSettingDate(
[
'name' => self::SETTING_ORDER_CLOSED_START,
'category' => self::CATEGORY_GENERAL,
]
);

$this->addSettingDate(
[
'name' => self::SETTING_ORDER_CLOSED_END,
'category' => self::CATEGORY_GENERAL,
]
);

$this->addSettingText(
[
'name' => self::SETTING_ORDER_MAXIMUM_PER_CYCLE,
'category' => self::CATEGORY_GENERAL,
]
);
}

public function getCategories()
{
return [
self::CATEGORY_GENERAL,
];
}

}

+ 42
- 0
EventSubscriber/OpeningEventSubscriber.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\EventSubscriber;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
use Lc\CaracoleBundle\Factory\Setting\MerchantSettingFactory;
use Lc\CaracoleBundle\Factory\Setting\SectionSettingFactory;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Definition\SectionSettingDefinitionInterface;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
use Lc\CaracoleBundle\Repository\Section\OpeningRepositoryQuery;
use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;

class OpeningEventSubscriber implements EventSubscriberInterface
{
protected $entityManager;
protected $openingRepositoryQuery;

public function __construct(
EntityManagerInterface $entityManager,
OpeningRepositoryQuery $openingRepositoryQuery
) {
$this->entityManager = $entityManager;
$this->openingRepositoryQuery = $openingRepositoryQuery;
}

public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => ['initOpenings']
];
}

public function initOpenings()
{

}

}

+ 40
- 28
EventSubscriber/SettingEventSubscriber.php Прегледај датотеку

@@ -24,15 +24,14 @@ class SettingEventSubscriber implements EventSubscriberInterface
protected $sectionSettingFactory;

public function __construct(
EntityManagerInterface $em,
MerchantSettingDefinitionInterface $merchantSettingDefinition,
SectionSettingDefinitionInterface $sectionSettingDefinition,
MerchantRepository $merchantRepository,
SectionRepository $sectionRepository,
MerchantSettingFactory $merchantSettingFactory,
SectionSettingFactory $sectionSettingFactory
)
{
EntityManagerInterface $em,
MerchantSettingDefinitionInterface $merchantSettingDefinition,
SectionSettingDefinitionInterface $sectionSettingDefinition,
MerchantRepository $merchantRepository,
SectionRepository $sectionRepository,
MerchantSettingFactory $merchantSettingFactory,
SectionSettingFactory $sectionSettingFactory
) {
$this->em = $em;
$this->merchantRepository = $merchantRepository;
$this->sectionRepository = $sectionRepository;
@@ -45,26 +44,25 @@ class SettingEventSubscriber implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => ['initSettings']
KernelEvents::CONTROLLER => ['initSettings']
];
}

public function initSettings()
{
$this->initSettingsGeneric(
'merchant',
$this->merchantSettingDefinition->getSettings(),
$this->merchantRepository->findAll(),
$this->merchantSettingFactory
'merchant',
$this->merchantSettingDefinition->getSettings(),
$this->merchantRepository->findAll(),
$this->merchantSettingFactory
);

$this->initSettingsGeneric(
'section',
$this->sectionSettingDefinition->getSettings(),
$this->sectionRepository->findAll(),
$this->sectionSettingFactory
'section',
$this->sectionSettingDefinition->getSettings(),
$this->sectionRepository->findAll(),
$this->sectionSettingFactory
);

}

public function initSettingsGeneric($type, $settings, $entities, $factory)
@@ -82,20 +80,34 @@ class SettingEventSubscriber implements EventSubscriberInterface
}

if ($createEntitySetting) {
$entitySetting = $factory->create(
[
$type => $entity,
'name' => $setting['name'],
$setting['field'] => isset($setting['default']) ? $setting['default'] : null,
]
);
if ($type == 'section') {
$factory->setSection($entity);
} elseif ($type == 'merchant') {
$factory->setMerchant($entity);
}

$text = null;
$date = null;
$file = null;

$fieldValue = isset($setting['default']) ? $setting['default'] : null;

if ($setting['field'] == 'text') {
$text = $fieldValue;
} elseif ($setting['field'] == 'date') {
$date = $fieldValue;
} elseif ($setting['field'] == 'file') {
$file = $fieldValue;
}

$entitySetting = $factory->create($setting['name'], $text, $date, $file);

$this->em->persist($entitySetting);
}
} else {
if ($entitySetting->getValue() === null
&& isset($setting['default'])
&& $setting['default'] !== null) {
&& isset($setting['default'])
&& $setting['default'] !== null) {
$methodSetValue = 'set' . ucfirst($setting['field']);
$entitySetting->$methodSetValue($setting['default']);
$this->em->update($entitySetting);

+ 30
- 0
Factory/Section/OpeningFactory.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\Factory\Section;

use App\Entity\Section\Opening;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\User\GroupUserInterface;

class OpeningFactory extends AbstractFactory implements OpeningFactoryInterface
{
use SectionFactoryTrait;

public function create(
int $day,
\DateTime $timeStart = null,
\DateTime $timeEnd = null,
GroupUserInterface $groupUser = null
): Opening {
$opening = new Opening();

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

return $opening;
}

}

+ 8
- 0
Factory/Section/OpeningFactoryInterface.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\Factory\Section;

interface OpeningFactoryInterface
{

}

+ 6
- 1
Factory/Setting/MerchantSettingFactory.php Прегледај датотеку

@@ -5,16 +5,21 @@ namespace Lc\CaracoleBundle\Factory\Setting;
use App\Entity\Setting\MerchantSetting;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\File\FileInterface;

class MerchantSettingFactory extends AbstractFactory
{
use MerchantFactoryTrait;

public function create()
public function create(string $name, string $text = null, \DateTime $date = null, FileInterface $file = null)
{
$merchantSetting = new MerchantSetting();

$merchantSetting->setMerchant($this->merchant);
$merchantSetting->setName($name);
$merchantSetting->setText($text);
$merchantSetting->setDate($date);
$merchantSetting->setFile($file);

return $merchantSetting;
}

+ 9
- 5
Factory/Setting/SectionSettingFactory.php Прегледај датотеку

@@ -3,20 +3,24 @@
namespace Lc\CaracoleBundle\Factory\Setting;

use App\Entity\Setting\SectionSetting;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\File\FileInterface;

class SectionSettingFactory extends AbstractFactory
{
use SectionFactoryTrait;

public function create()
public function create(string $name, string $text = null, \DateTime $date = null, FileInterface $file = null)
{
$sectionSetting = new SectionSetting();
$merchantSetting = new SectionSetting();

$sectionSetting->setSection($this->section);
$merchantSetting->setSection($this->section);
$merchantSetting->setName($name);
$merchantSetting->setText($text);
$merchantSetting->setDate($date);
$merchantSetting->setFile($file);

return $sectionSetting;
return $merchantSetting;
}
}

+ 3
- 0
Form/Setting/BaseSettingType.php Прегледај датотеку

@@ -68,6 +68,9 @@ abstract class BaseSettingType extends SovBaseSettingType
$label = 'setting_definition.'.$transCategory.'.settings.'.$settingName ;

if(isset($settingDefinition) && $settingDefinition) {



$this->buildFormSetting($label, $form, $settingDefinition, $settingEntity);
}
}

+ 17
- 0
Model/Order/OrderShopModel.php Прегледај датотеку

@@ -135,6 +135,11 @@ abstract class OrderShopModel extends AbstractLightEntity implements FilterMerch
*/
protected $section;

/**
* @ORM\Column(type="integer", nullable=true)
*/
protected $cycleId;

public function __construct()
{
$this->orderStatusHistories = new ArrayCollection();
@@ -615,4 +620,16 @@ abstract class OrderShopModel extends AbstractLightEntity implements FilterMerch
return $this;
}

public function getCycleId(): ?int
{
return $this->cycleId;
}

public function setCycleId(?int $cycleId): self
{
$this->cycleId = $cycleId;

return $this;
}

}

+ 8
- 0
Model/Section/OpeningInterface.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\Model\Section;

interface OpeningInterface
{

}

+ 115
- 0
Model/Section/OpeningModel.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\Model\Section;

use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Model\User\GroupUserInterface;

/**
* @ORM\MappedSuperclass()
*/
abstract class OpeningModel implements EntityInterface, OpeningInterface, FilterSectionInterface
{
/**
* @ORM\Column(type="integer")
*/
protected $day;

/**
* @ORM\Column(type="time", nullable=true)
*/
protected $timeStart;

/**
* @ORM\Column(type="time", nullable=true)
*/
protected $timeEnd;

/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", inversedBy="openings")
* @ORM\JoinColumn(nullable=false)
*/
protected $section;

/**
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\GroupUserInterface", inversedBy="openings")
*/
protected $groupUser;

public function __toString()
{
$toString = ''.$this->getDay();

if($this->getTimeStart()) {
$toString .= ' / Début : '.$this->getTimeStart()->format('H:i');
}

if($this->getTimeEnd()) {
$toString .= ' / Fin : '.$this->getTimeEnd()->format('H:i');
}

return $toString ;
}

public function getDay(): ?int
{
return $this->day;
}

public function setDay(int $day): self
{
$this->day = $day;

return $this;
}

public function getTimeStart(): ?\DateTimeInterface
{
return $this->timeStart;
}

public function setTimeStart(?\DateTimeInterface $timeStart): self
{
$this->timeStart = $timeStart;

return $this;
}

public function getTimeEnd(): ?\DateTimeInterface
{
return $this->timeEnd;
}

public function setTimeEnd(?\DateTimeInterface $timeEnd): self
{
$this->timeEnd = $timeEnd;

return $this;
}

public function getSection(): ?SectionInterface
{
return $this->section;
}

public function setSection(?SectionInterface $section): self
{
$this->section = $section;

return $this;
}

public function getGroupUser(): ?GroupUserInterface
{
return $this->groupUser;
}

public function setGroupUser(?GroupUserInterface $groupUser): self
{
$this->groupUser = $groupUser;

return $this;
}
}

+ 36
- 0
Model/Section/SectionModel.php Прегледај датотеку

@@ -74,10 +74,16 @@ abstract class SectionModel extends AbstractFullEntity implements FilterMerchant
*/
protected $settings;

/**
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Section\OpeningInterface", mappedBy="section", orphanRemoval=true)
*/
protected $openings;

public function __construct()
{
$this->productFamilies = new ArrayCollection();
$this->orderShops = new ArrayCollection();
$this->openings = new ArrayCollection();
}

public function __toString()
@@ -284,4 +290,34 @@ abstract class SectionModel extends AbstractFullEntity implements FilterMerchant

return $this;
}

/**
* @return Collection|OpeningInterface[]
*/
public function getOpenings(): Collection
{
return $this->openings;
}

public function addOpening(OpeningInterface $opening): self
{
if (!$this->openings->contains($opening)) {
$this->openings[] = $opening;
$opening->setSection($this);
}

return $this;
}

public function removeOpening(OpeningInterface $opening): self
{
if ($this->openings->removeElement($opening)) {
// set the owning side to null (unless already changed)
if ($opening->getSection() === $this) {
$opening->setSection(null);
}
}

return $this;
}
}

+ 44
- 0
Model/User/GroupUserModel.php Прегледај датотеку

@@ -2,9 +2,12 @@

namespace Lc\CaracoleBundle\Model\User;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\OpeningInterface;
use Lc\SovBundle\Model\User\GroupUserModel as SovGroupUserModel;

/**
@@ -18,6 +21,17 @@ abstract class GroupUserModel extends SovGroupUserModel implements FilterMerchan
*/
protected $merchant;

/**
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Section\OpeningInterface", mappedBy="groupUser")
*/
protected $openings;

public function __construct()
{
parent::__construct();
$this->openings = new ArrayCollection();
}

public function getMerchant(): MerchantInterface
{
return $this->merchant;
@@ -30,4 +44,34 @@ abstract class GroupUserModel extends SovGroupUserModel implements FilterMerchan
return $this;
}

/**
* @return Collection|OpeningInterface[]
*/
public function getOpenings(): Collection
{
return $this->openings;
}

public function addOpening(OpeningInterface $opening): self
{
if (!$this->openings->contains($opening)) {
$this->openings[] = $opening;
$opening->setGroupUser($this);
}

return $this;
}

public function removeOpening(OpeningInterface $opening): self
{
if ($this->openings->removeElement($opening)) {
// set the owning side to null (unless already changed)
if ($opening->getGroupUser() === $this) {
$opening->setGroupUser(null);
}
}

return $this;
}

}

+ 67
- 0
ReferenceBuilder/OrderReferenceBuilder.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\ReferenceBuilder;

use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Section\SectionModel;

class OrderReferenceBuilder
{

public function buildReference(OrderShopInterface $orderShop, \DateTime $distributionDate = null): string
{
switch ($orderShop->getSection()->getCycle()) {
case SectionModel::CYCLE_DAY:
return $this->buildReferenceCycleDay($orderShop);
case SectionModel::CYCLE_WEEK:
return $this->buildReferenceCycleWeek($orderShop, $distributionDate);
case SectionModel::CYCLE_MONTH:
return $this->buildReferenceCycleMonth($orderShop, $distributionDate);
case SectionModel::CYCLE_YEAR:
return $this->buildReferenceCycleYear($orderShop, $distributionDate);
}

return 'C' . $orderShop->getId();
}

public function buildReferenceCycleDay(OrderShopInterface $orderShop): string
{
return $this->getPrefixReference($orderShop) .
'C' . $this->numberPad($orderShop->getCycleId(), 3);
}

public function buildReferenceCycleWeek(OrderShopInterface $orderShop, \DateTime $distributionDate): string
{
return $this->getPrefixReference($orderShop) .
'S' . $distributionDate->format('W') .
'C' . $this->numberPad($orderShop->getCycleId(), 4) .
'A' . $distributionDate->format('y');
}

public function buildReferenceCycleMonth(OrderShopInterface $orderShop, \DateTime $distributionDate): string
{
return $this->getPrefixReference($orderShop) .
'M' . $distributionDate->format('m') .
'C' . $this->numberPad($orderShop->getCycleId(), 4) .
'A' . $distributionDate->format('y');
}

public function buildReferenceCycleYear(OrderShopInterface $orderShop, \DateTime $distributionDate): string
{
return $this->getPrefixReference($orderShop) .
'C' . $this->numberPad($orderShop->getCycleId(), 5) .
'A' . $distributionDate->format('y');
}

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

public function numberPad($number, $length): string
{
return str_pad($number, $length, "0", STR_PAD_LEFT);
}

}

+ 15
- 0
Repository/Section/OpeningRepository.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\Repository\Section;

use App\Entity\Section\Opening;
use Doctrine\Persistence\ManagerRegistry;
use Lc\SovBundle\Repository\AbstractRepository;

class OpeningRepository extends AbstractRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Opening::class);
}
}

+ 14
- 0
Repository/Section/OpeningRepositoryQuery.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\Repository\Section;

use Knp\Component\Pager\PaginatorInterface;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;

class OpeningRepositoryQuery extends AbstractRepositoryQuery
{
public function __construct(OpeningRepository $repository, PaginatorInterface $paginator)
{
parent::__construct($repository, 'r', $paginator);
}
}

+ 13
- 0
Repository/Section/OpeningStore.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\Repository\Section;

class OpeningStore
{
protected OpeningRepositoryQuery $query;

public function __construct(OpeningRepositoryQuery $query)
{
$this->query = $query;
}
}

+ 141
- 0
Resolver/OpeningResolver.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\Resolver;

use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
use Lc\CaracoleBundle\Model\Section\SectionInterface;

class OpeningResolver
{
protected ?bool $isOpenSale = null;
protected array $messages = [];

public function init()
{
$this->isOpenSale = false;
$this->messages = [];
}

public function isOpenSale(SectionInterface $section)
{
$this->init();

$now = new \DateTime();

// order state
$this->checkOrderState();
if(is_null($this->getIsOpenSale())) {
return $this->getIsOpenSale();
}

// order maximum per cycle
$countOrderShopCycle = 0 ;
$orderMaximumPerCycle = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_MAXIMUM_PER_CYCLE);
if($countOrderShopCycle >= $orderMaximumPerCycle) {
return false;
}

// période de fermeture des commandes
$orderClosedStart = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_START);
$orderClosedEnd = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_END);

if($orderClosedStart && $orderClosedEnd && $now >= $orderClosedStart && $now <= $orderClosedEnd) {
return false;
}

// commandes ouvertes
// ..

// par défaut
if(is_null($this->getIsOpenSale())) {
$this->setIsOpenSale(true);
}

return $this->getIsOpenSale();
}

public function checkOrderState(SectionInterface $section)
{
$orderState = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_STATE);

if($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_OPEN) {
$this->setIsOpenSale(true);
$this->addMessage('Les commandes sont ouvertes.');
}

if($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_CLOSED) {
$this->setIsOpenSale(false);
$this->addMessage('Les commandes sont fermées.');
}
}

public function getIsOpenSale()
{
return $this->isOpenSale;
}

public function setIsOpenSale(bool $isOpenSale)
{
$this->isOpenSale = $isOpenSale;
}

public function addMessage(string $message)
{
$this->messages[] = $message;
}

/*
public function isOpenSale($context = self::OPENSALE_CONTEXT_FRONTEND, $checkMaximumOrderWeek = true)
{
if($this->isOpenFullTime()) {
return true ;
}

$merchantCurrent = $this->merchantUtils->getMerchantCurrent();

$orderOpenDay = $merchantCurrent->getMerchantConfig('order-open-day');
$orderOpenTime = new \DateTime($merchantCurrent->getMerchantConfig('order-open-time'));
$orderOpenDayVip = $merchantCurrent->getMerchantConfig('order-open-day-vip');
$orderOpenTimeVip = new \DateTime($merchantCurrent->getMerchantConfig('order-open-time-vip'));
$orderCloseDay = $merchantCurrent->getMerchantConfig('order-close-day');
$orderCloseTime = new \DateTime($merchantCurrent->getMerchantConfig('order-close-time'));

if($orderOpenDayVip && $orderOpenTimeVip) {
if($context == self::OPENSALE_CONTEXT_BACKEND
|| ($context == self::OPENSALE_CONTEXT_FRONTEND
&& $this->userUtils->isUserInGroupVip())) {

if($orderOpenDayVip < $orderOpenDay) {
$orderOpenDay = $orderOpenDayVip ;
$orderOpenTime = $orderOpenTimeVip ;
}
elseif($orderOpenDayVip == $orderOpenDay) {
if($orderOpenTimeVip < $orderOpenTime) {
$orderOpenTime = $orderOpenTimeVip ;
}
}

}
}

$dayToday = date('N');
$now = new \DateTime();

$openDays = $this->getOpenDays($orderOpenDay, $orderCloseDay);

if( in_array($dayToday, $openDays)
&& !$this->isHolidays()
&& (!$checkMaximumOrderWeek || ($checkMaximumOrderWeek && !$this->isMaximumOrderWeekAchieved()))
&& in_array($dayToday, $openDays)
&& (($dayToday == $orderOpenDay && $dayToday == $orderCloseDay && $now >= $orderOpenTime && $now <= $orderCloseTime)
|| ($dayToday == $orderOpenDay && $dayToday != $orderCloseDay && $now >= $orderOpenTime)
|| ($dayToday == $orderCloseDay && $dayToday != $orderOpenDay && $now <= $orderCloseTime)
|| ($dayToday != $orderOpenDay && $dayToday != $orderCloseDay))
) {
return true;
}

return false;
}
*/
}

+ 14
- 1
Resources/translations/admin.fr.yaml Прегледај датотеку

@@ -4,6 +4,7 @@ menu:
setting: Paramètres
setting_merchant: Marchand
setting_section: Section
section_openings: Ouvertures
admin: Administration
admin_merchant: Marchands
admin_section: Sections
@@ -26,6 +27,13 @@ setting_definition:
settings:
url: URL absolue

section:
settings:
orderReferencePrefix: Préfixe référence commandes
orderState: Statut d'ouverture des commandes
orderClosedStart: Période commandes fermées (début)
orderClosedEnd: Période commandes fermées (fin)
orderMaximumPerCycle: Nombre maximum de commande par cycle de vente

entity:
default:
@@ -109,7 +117,12 @@ entity:
wordingShort: Nom court
coefficient: Coefficient
unitReference: Unité de référence

Opening:
label: Ouverture
label_plurial: Ouvertures
fields:
timeStart: Heure d'ouverture
timeEnd: Heure de fermeture

form:
user_merchant:

+ 11
- 8
Twig/StoreTwigExtension.php Прегледај датотеку

@@ -6,6 +6,7 @@ use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery;
use Lc\CaracoleBundle\Repository\Reminder\ReminderStore;
use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface;
use Lc\CaracoleBundle\Repository\Section\SectionRepositoryQuery;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Twig\Extension\AbstractExtension;
@@ -13,8 +14,8 @@ use Twig\TwigFunction;

class StoreTwigExtension extends AbstractExtension
{
protected $merchantRepository;
protected $sectionRepository;
protected MerchantRepositoryQuery $merchantRepositoryQuery;
protected SectionRepositoryQuery $sectionRepositoryQuery;
protected ReminderStore $reminderStore;
protected MerchantResolver $merchantResolver;
protected SectionResolver $sectionResolver;
@@ -22,14 +23,14 @@ class StoreTwigExtension extends AbstractExtension
public function __construct(
MerchantResolver $merchantResolver,
SectionResolver $sectionResolver,
MerchantRepositoryQuery $merchantRepository,
SectionRepository $sectionRepository,
MerchantRepositoryQuery $merchantRepositoryQuery,
SectionRepositoryQuery $sectionRepositoryQuery,
ReminderStore $reminderStore
) {
$this->merchantResolver = $merchantResolver;
$this->sectionResolver = $sectionResolver;
$this->merchantRepository = $merchantRepository;
$this->sectionRepository = $sectionRepository;
$this->merchantRepositoryQuery = $merchantRepositoryQuery;
$this->sectionRepositoryQuery = $sectionRepositoryQuery;
$this->reminderStore = $reminderStore;
}

@@ -44,12 +45,14 @@ class StoreTwigExtension extends AbstractExtension

public function getSections()
{
return $this->sectionRepository->findAll();
return $this->sectionRepositoryQuery
->filterByMerchant($this->merchantResolver->getCurrent())
->find();
}

public function getMerchants()
{
return $this->merchantRepository->findAll();
return $this->merchantRepositoryQuery->find();
}

public function getReminders($params = [])

Loading…
Откажи
Сачувај