|
10 | 10 | use PrestaShop\PrestaShop\Core\Domain\Discount\ValueObject\DiscountType; |
11 | 11 | use PrestaShop\PrestaShop\Core\FeatureFlag\FeatureFlagSettings; |
12 | 12 | use PrestaShop\PrestaShop\Core\FeatureFlag\FeatureFlagStateCheckerInterface; |
| 13 | +use PrestaShop\PrestaShop\Core\Util\DateTime\DateTime as DateTimeUtil; |
13 | 14 |
|
14 | 15 | /** |
15 | 16 | * Class CartRuleCore. |
@@ -46,7 +47,7 @@ class CartRuleCore extends ObjectModel |
46 | 47 | /** |
47 | 48 | * @var string|null |
48 | 49 | */ |
49 | | - public $date_to; |
| 50 | + public $date_to = null; |
50 | 51 | public $description; |
51 | 52 | public $quantity = 1; |
52 | 53 | public ?int $total_quantity = null; |
@@ -111,7 +112,7 @@ class CartRuleCore extends ObjectModel |
111 | 112 | 'fields' => [ |
112 | 113 | 'id_customer' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId'], |
113 | 114 | 'date_from' => ['type' => self::TYPE_DATE, 'validate' => 'isDate', 'required' => true], |
114 | | - 'date_to' => ['type' => self::TYPE_DATE, 'validate' => 'isDate', 'required' => true], |
| 115 | + 'date_to' => ['type' => self::TYPE_DATE, 'validate' => 'isDateOrNull', 'required' => false, 'allow_null' => true], |
115 | 116 | 'description' => ['type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => DiscountSettings::MAX_DESCRIPTION_LENGTH], |
116 | 117 | 'quantity' => ['type' => self::TYPE_INT, 'allow_null' => true, 'validate' => 'isUnsignedInt'], |
117 | 118 | 'total_quantity' => ['type' => self::TYPE_INT, 'allow_null' => true, 'validate' => 'isUnsignedInt'], |
@@ -377,8 +378,9 @@ public static function haveCartRuleToday($idCustomer) |
377 | 378 | '") OR (date_from >= "' . $start_date . |
378 | 379 | '" AND date_from <= "' . $end_date . |
379 | 380 | '") OR (date_from < "' . $start_date . |
380 | | - '" AND date_to > "' . $end_date . |
381 | | - '")) AND `id_customer` IN (0,' . (int) $idCustomer . ')'; |
| 381 | + '" AND (date_to > "' . $end_date . |
| 382 | + '" OR date_to IS NULL)' . |
| 383 | + ')) AND `id_customer` IN (0,' . (int) $idCustomer . ')'; |
382 | 384 |
|
383 | 385 | $haveCartRuleToday[$idCustomer] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); |
384 | 386 | } |
@@ -432,7 +434,7 @@ public static function getCustomerCartRules( |
432 | 434 | $sql .= ')'; |
433 | 435 |
|
434 | 436 | // Then, conditions for date, voucher active property and total amount of vouchers in stock |
435 | | - $sql .= ' AND NOW() BETWEEN cr.date_from AND cr.date_to |
| 437 | + $sql .= ' AND ((cr.date_from <= NOW() AND cr.date_to IS NULL) OR (NOW() BETWEEN cr.date_from AND cr.date_to)) |
436 | 438 | ' . ($active ? 'AND cr.`active` = 1' : '') . ' |
437 | 439 | ' . ($inStock ? 'AND (cr.`quantity` > 0 OR cr.`quantity` is null)' : ''); |
438 | 440 |
|
@@ -789,7 +791,7 @@ public function checkValidity(Context $context, $alreadyInCart = false, $display |
789 | 791 | if (strtotime($this->date_from) > time()) { |
790 | 792 | return (!$display_error) ? false : $this->trans('This voucher is not valid yet', [], 'Shop.Notifications.Error'); |
791 | 793 | } |
792 | | - if (strtotime($this->date_to) < time()) { |
| 794 | + if (!DateTimeUtil::isNull($this->date_to ?? null) && strtotime($this->date_to) < time()) { |
793 | 795 | return (!$display_error) ? false : $this->trans('This voucher has expired', [], 'Shop.Notifications.Error'); |
794 | 796 | } |
795 | 797 |
|
@@ -1995,7 +1997,7 @@ public static function autoAddToCart(?Context $context = null, bool $useOrderPri |
1995 | 1997 | WHERE cr.active = 1 |
1996 | 1998 | AND cr.code = "" |
1997 | 1999 | AND (cr.quantity > 0 OR cr.quantity is null) |
1998 | | - AND NOW() BETWEEN cr.date_from AND cr.date_to |
| 2000 | + AND ((cr.date_from <= NOW() AND cr.date_to IS NULL) OR (NOW() BETWEEN cr.date_from AND cr.date_to)) |
1999 | 2001 | AND ( |
2000 | 2002 | cr.id_customer = 0 |
2001 | 2003 | ' . (Validate::isLoadedObject($context->customer) ? 'OR cr.id_customer = ' . (int) $context->cart->id_customer : '') . ' |
|
0 commit comments