-
-
Notifications
You must be signed in to change notification settings - Fork 446
Fix CatalogRule start date insert logic #1007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I think the code is correct. I made a test: // Original code.
$fromTime = (int) strtotime('2020-01-01');
$toTime = (int) strtotime('2020-01-02');
$toTime = $toTime ? ($toTime + 86400 - 1) : 0;
$result = [date('r', $fromTime), date('r', $toTime)]; The result is
Now with your code: // Changed code.
$fromTime = (int) strtotime('2020-01-01');
$fromTime = $fromTime ? ($fromTime - 86400 + 1) : 0;
$toTime = (int) strtotime('2020-01-02');
$toTime = $toTime ? ($toTime + 86400 - 1) : 0;
$result = [date('r', $fromTime), date('r', $toTime)]; The result is wrong:
|
When we faced this issue it was a timezone issue. I remember that the day before the Black Friday we set a rule to star on the next day. We are in the Europe/Rome timezone but we have an Australian store view with Sidney timezone, so we expected to see the rule already applied in the AU store view because it was already the Black Friday day there. I remember we debugged locally and the problem was that the rule wasn’t added at the moment we created it but it should because of the Sidney timezone. So we fixed with this change. |
Could it be that the Australian store timezone was not configured correctly in the backend? |
No it was configured correctly. |
There have been some changes on this in the past also ... same problem ... I remember it was fixed (Amsterdam timezone) .... it has to do with time of running, core time of the (unix) server and the timezone. |
We should move forward this PR. @kiatng - what is your opinion? |
I coulnd't really understand why this solutions fixes the problem but I think we should never use +-86400 seconds since it doesn't work the day of the daylight saving +-1 hour change. |
I think we need to replicate the issue first. |
ok since nobody knows what this is about and how to replicate, I'm closing it. |
I would leave it open. I will make time to replicate the issue. If it confirms I will go further to implement the PR and check what is happening. |
@addison74 I would close this, @kiatng tested the coded and seemed not work #1007 (comment) (that result is wrong for sure) but using SECONDS_IN_DAY is also not a super good practise since it doesn't work the day of daylightsaving change. |
maybe it could be converted to an issue but we need a full reproducible case |
Hi guys, I'll try to provide a way to reproduce the issue in the next days. |
Hi guys, the bug still exist. At least on version 19.4.21 of OpenMage.
If the current time is 3 PM of the 2023-01-16 in Europe/Rome, it means that in the Australia/Sydney timezone the current time is 2 AM (or 1 AM depending on the daylight saving time) of the 2023-01-17. This means that on the "Australian" store view the promotion should be already applied and we should see the discounted price of 236 for the "AVIATOR SUNGLASSES"; but what happens is that we still see the full price of 295. If you apply the patch provided in this PR and you save and apply the catalog price rule again you'll get the discounted price. |
Note changing magento-lts/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php Lines 233 to 238 in 7c16d61
[edit] To add the rule ahead of time, change line 209 magento-lts/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php Lines 208 to 213 in 7c16d61
to if ($fromTime > $timestamp + self::SECONDS_IN_DAY @mmenozzi Can you test line 209 without changing |
Also seen this .... the topic is slowly growing a beard ... |
I tested the test case with and without the PR, and this is not working, like @kiatng says the rule is applied to early. By applying rules and reindexing at Friday, 20 January 2023 14:13:08 Europe/Paris or Saturday, 21 January 2023 12:12:21 am Australia/Sydney, this does not change anything (with the PR - without the PR price are not discounted). |
Line 209: if ($fromTime > $timestamp
|| ($toTime && $toTime < $timestamp)
) { The Instead, we can change it to if ($fromTime > $timestamp + self::SECONDS_IN_DAY
|| ($toTime && $toTime < $timestamp)
) { Note that the comparison for @luigifab Can you test if this works. |
With @kiatng suggestion, discount is not applied too early, BUT to display the discount, I had to "Save and apply" my rule at 26/01/23 13:08:49 utc / Friday, 27 January 2023 12:08:49 am Australia/Sydney. Before applying the rule, I forgot to add the product to the cart to check the price. I will try again. |
51b2e94
to
3037ae0
Compare
so sorry guys, I've rebased the PR and it screwed everything... I've rebuilt it (adding my strtotime() suggestions), do you think it misses something? |
Not sure about changes between the version of the PR I tested and now. |
The 86400 second cannot be used, it does not work 2 days a year, that i am more than sure |
This issue reminds me of another one that I discussed in another forum https://magento.stackexchange.com/questions/133405/issue-when-specialpricefromdate-is-equal-with-specialpricetodate/ What happens when price_from is perfectly equal to price_to? For example both having the value 2023-07-16 00:00. Naturally it should run for a day. |
Is it possible to deploy the PR on demo.openmage.org to test it again? |
@kiatng is the original PR still available? |
For the same reason the rule is inserted until 24 hours after the rule end date, we should also start inserting it 24 hours before the start date. Am I wrong?