浏览代码

OpeningResolver

packProduct
Guillaume 3 年前
父节点
当前提交
62b4b1861c
共有 1 个文件被更改,包括 94 次插入93 次删除
  1. +94
    -93
      Resolver/OpeningResolver.php

+ 94
- 93
Resolver/OpeningResolver.php 查看文件

@@ -3,139 +3,140 @@
namespace Lc\CaracoleBundle\Resolver;

use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
use Lc\CaracoleBundle\Model\Section\OpeningInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Model\User\UserInterface;
use Symfony\Component\Security\Core\Security;

class OpeningResolver
{
protected ?bool $isOpenSale = null;
protected array $messages = [];
protected SectionResolver $sectionResolver;
protected Security $security;

public function init()
public function __construct(SectionResolver $sectionResolver, Security $security)
{
$this->isOpenSale = false;
$this->messages = [];
$this->sectionResolver = $sectionResolver;
$this->security = $security;
}

public function isOpenSale(SectionInterface $section)
{
$this->init();
public function isOpenSale(
SectionInterface $section = null,
UserInterface $user = null,
\DateTime $date = null
): bool {
// Initialisation
$this->messages = [];

if (is_null($section)) {
$section = $this->sectionResolver->getCurrent();
}

if (is_null($user)) {
$user = $this->security->getUser();
}

if (is_null($date)) {
$date = new \DateTime();
}

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

$now = new \DateTime();
if ($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_OPEN) {
$this->addMessage('Les commandes sont ouvertes (configuration de la section).');
return true;
}

// order state
$this->checkOrderState();
if(is_null($this->getIsOpenSale())) {
return $this->getIsOpenSale();
if ($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_CLOSED) {
$this->addMessage('Les commandes sont fermées (configuration de la section).');
return false;
}

// order maximum per cycle
$countOrderShopCycle = 0 ;
// Nombre maximum de commandes par cycle (voir configuration de section)
$countOrderShopCycle = 0;
$orderMaximumPerCycle = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_MAXIMUM_PER_CYCLE);
if($countOrderShopCycle >= $orderMaximumPerCycle) {
if ($orderMaximumPerCycle && $countOrderShopCycle >= $orderMaximumPerCycle) {
$this->addMessage('Le nombre maximum de commande a été atteint.');
return false;
}

// période de fermeture des commandes
// Période de fermeture des commandes issue de la configuration de la section (congés)
$orderClosedStart = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_START);
$orderClosedEnd = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_END);

if($orderClosedStart && $orderClosedEnd && $now >= $orderClosedStart && $now <= $orderClosedEnd) {
if ($orderClosedStart && $orderClosedEnd && $date >= $orderClosedStart && $date <= $orderClosedEnd) {
$this->addMessage(
'Les commandes sont fermées (période de fermeture des commandes dans la configuration de la section).'
);
return false;
}

// commandes ouvertes
// ..
// Période d'ouverture des commandes
$openings = $section->getOpenings();

// par défaut
if(is_null($this->getIsOpenSale())) {
$this->setIsOpenSale(true);
foreach ($openings as $opening) {
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;
}
}
}

return $this->getIsOpenSale();
$this->addMessage('Les commandes sont fermées (périodes d\'ouverture classique des commandes).');

return false;
}

public function checkOrderState(SectionInterface $section)
public function isDateMatchWithOpening(\DateTime $date, OpeningInterface $opening): bool
{
$orderState = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_STATE);
$day = $date->format('N');
$dayOpening = $opening->getDay();

if ($opening->getTimeStart()) {
$dateOpeningStart = clone $date;
$dateOpeningStart->setTime(
$opening->getTimeStart()->format('H'),
$opening->getTimeStart()->format('i')
);
}

if($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_OPEN) {
$this->setIsOpenSale(true);
$this->addMessage('Les commandes sont ouvertes.');
if ($opening->getTimeEnd()) {
$dateOpeningEnd = clone $date;
$dateOpeningEnd->setTime(
$opening->getTimeEnd()->format('H'),
$opening->getTimeEnd()->format('i')
);
}

if($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_CLOSED) {
$this->setIsOpenSale(false);
$this->addMessage('Les commandes sont fermées.');
if ($day == $dayOpening) {
// Commandes ouvertes toute la journée
if (!$opening->getTimeStart() && !$opening->getTimeEnd()) {
return true;
} // Commandes ouvertes à partir de timeStart
elseif ($opening->getTimeStart() && !$opening->getTimeEnd() && $date >= $dateOpeningStart) {
return true;
} // Commandes ouvertes jusqu'à timeEnd
elseif (!$opening->getTimeStart() && $opening->getTimeEnd() && $date < $dateOpeningEnd) {
return true;
} // Commandes ouvertes de timeStart à timeEnd
elseif ($opening->getTimeStart() && $opening->getTimeEnd()
&& $date >= $dateOpeningStart && $date < $dateOpeningEnd) {
return true;
}
}
}

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

public function setIsOpenSale(bool $isOpenSale)
public function getMessages(): array
{
$this->isOpenSale = $isOpenSale;
return $this->messages;
}

public function addMessage(string $message)
public function addMessage(string $message): void
{
$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;
}
*/
}

正在加载...
取消
保存