Fix: SQL queries using NOW() rely on MySQL timezone instead of shop timezone#41596
Closed
mattgoud wants to merge 1 commit into
Closed
Fix: SQL queries using NOW() rely on MySQL timezone instead of shop timezone#41596mattgoud wants to merge 1 commit into
mattgoud wants to merge 1 commit into
Conversation
359a7a3 to
14b0a04
Compare
This was referenced Jun 2, 2026
14b0a04 to
118da1c
Compare
Replace all occurrences of NOW() in raw SQL queries with PHP's date('Y-m-d H:i:s')
so that the shop's configured timezone (PHP) is always used instead of the MySQL
server's timezone (UTC by default).
Fixes PrestaShop#30828
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
118da1c to
fbb2b6a
Compare
Contributor
Author
|
Closed. Alternative solution proposed by the PR #41628 (nb: targets the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NOW()to compare or store the current date, which relies on the MySQL server timezone (UTC by default). This caused issues when the shop's configured timezone differs from the MySQL server's timezone — for example, a cart rule valid from a given hour would not appear to customers until MySQL's UTC clock reached that hour.This PR replaces all core occurrences of
NOW()in raw SQL queries with PHP'sdate('Y-m-d H:i:s'), which always uses the shop's configured timezone (set viadate_default_timezone_set). The affected files areCartRule.php(2 occurrences — the primary bug),ProductSale.php(3 occurrences),Connection.php(1 occurrence) andProduct.php(1 occurrence).Europe/Paris(or any timezone different from UTC).2. Ensure your MySQL server runs in UTC (default).
3. Create a cart rule for a specific customer with a
date_fromset to the current time.4. Log in on the FO with that customer and go to My account > My vouchers.
5. The cart rule should appear immediately (before the fix it would only appear 1–2 hours later depending on DST).
9.1.x(merges up intodevelop). The broader connection-level approach fordevelop/9.2 — which aligns the MySQL session time zone with the shop time zone on every connection and covers allNOW()at once — is #41628. The two do not conflict (idempotent, no file overlap); see #41628 for the full comparison. Native module PRs from the same effort: PrestaShop/ps_googleanalytics#177, PrestaShop/blockwishlist#451, PrestaShop/ps_emailsubscription#127, PrestaShop/ps_facetedsearch#1234, PrestaShop/pagesnotfound#42, PrestaShop/statssearch#30, PrestaShop/statsbestproducts#28