You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
4.7KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Resolver;
  3. use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
  4. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  5. class OpeningResolver
  6. {
  7. protected ?bool $isOpenSale = null;
  8. protected array $messages = [];
  9. public function init()
  10. {
  11. $this->isOpenSale = false;
  12. $this->messages = [];
  13. }
  14. public function isOpenSale(SectionInterface $section)
  15. {
  16. $this->init();
  17. $now = new \DateTime();
  18. // order state
  19. $this->checkOrderState();
  20. if(is_null($this->getIsOpenSale())) {
  21. return $this->getIsOpenSale();
  22. }
  23. // order maximum per cycle
  24. $countOrderShopCycle = 0 ;
  25. $orderMaximumPerCycle = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_MAXIMUM_PER_CYCLE);
  26. if($countOrderShopCycle >= $orderMaximumPerCycle) {
  27. return false;
  28. }
  29. // période de fermeture des commandes
  30. $orderClosedStart = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_START);
  31. $orderClosedEnd = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_END);
  32. if($orderClosedStart && $orderClosedEnd && $now >= $orderClosedStart && $now <= $orderClosedEnd) {
  33. return false;
  34. }
  35. // commandes ouvertes
  36. // ..
  37. // par défaut
  38. if(is_null($this->getIsOpenSale())) {
  39. $this->setIsOpenSale(true);
  40. }
  41. return $this->getIsOpenSale();
  42. }
  43. public function checkOrderState(SectionInterface $section)
  44. {
  45. $orderState = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_STATE);
  46. if($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_OPEN) {
  47. $this->setIsOpenSale(true);
  48. $this->addMessage('Les commandes sont ouvertes.');
  49. }
  50. if($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_CLOSED) {
  51. $this->setIsOpenSale(false);
  52. $this->addMessage('Les commandes sont fermées.');
  53. }
  54. }
  55. public function getIsOpenSale()
  56. {
  57. return $this->isOpenSale;
  58. }
  59. public function setIsOpenSale(bool $isOpenSale)
  60. {
  61. $this->isOpenSale = $isOpenSale;
  62. }
  63. public function addMessage(string $message)
  64. {
  65. $this->messages[] = $message;
  66. }
  67. /*
  68. public function isOpenSale($context = self::OPENSALE_CONTEXT_FRONTEND, $checkMaximumOrderWeek = true)
  69. {
  70. if($this->isOpenFullTime()) {
  71. return true ;
  72. }
  73. $merchantCurrent = $this->merchantUtils->getMerchantCurrent();
  74. $orderOpenDay = $merchantCurrent->getMerchantConfig('order-open-day');
  75. $orderOpenTime = new \DateTime($merchantCurrent->getMerchantConfig('order-open-time'));
  76. $orderOpenDayVip = $merchantCurrent->getMerchantConfig('order-open-day-vip');
  77. $orderOpenTimeVip = new \DateTime($merchantCurrent->getMerchantConfig('order-open-time-vip'));
  78. $orderCloseDay = $merchantCurrent->getMerchantConfig('order-close-day');
  79. $orderCloseTime = new \DateTime($merchantCurrent->getMerchantConfig('order-close-time'));
  80. if($orderOpenDayVip && $orderOpenTimeVip) {
  81. if($context == self::OPENSALE_CONTEXT_BACKEND
  82. || ($context == self::OPENSALE_CONTEXT_FRONTEND
  83. && $this->userUtils->isUserInGroupVip())) {
  84. if($orderOpenDayVip < $orderOpenDay) {
  85. $orderOpenDay = $orderOpenDayVip ;
  86. $orderOpenTime = $orderOpenTimeVip ;
  87. }
  88. elseif($orderOpenDayVip == $orderOpenDay) {
  89. if($orderOpenTimeVip < $orderOpenTime) {
  90. $orderOpenTime = $orderOpenTimeVip ;
  91. }
  92. }
  93. }
  94. }
  95. $dayToday = date('N');
  96. $now = new \DateTime();
  97. $openDays = $this->getOpenDays($orderOpenDay, $orderCloseDay);
  98. if( in_array($dayToday, $openDays)
  99. && !$this->isHolidays()
  100. && (!$checkMaximumOrderWeek || ($checkMaximumOrderWeek && !$this->isMaximumOrderWeekAchieved()))
  101. && in_array($dayToday, $openDays)
  102. && (($dayToday == $orderOpenDay && $dayToday == $orderCloseDay && $now >= $orderOpenTime && $now <= $orderCloseTime)
  103. || ($dayToday == $orderOpenDay && $dayToday != $orderCloseDay && $now >= $orderOpenTime)
  104. || ($dayToday == $orderCloseDay && $dayToday != $orderOpenDay && $now <= $orderCloseTime)
  105. || ($dayToday != $orderOpenDay && $dayToday != $orderCloseDay))
  106. ) {
  107. return true;
  108. }
  109. return false;
  110. }
  111. */
  112. }