|
- <?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;
- }
- */
- }
|