Closed (fixed)
Project:
Commerce Core
Version:
8.x-2.x-dev
Component:
Promotions
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
27 May 2017 at 02:35 UTC
Updated:
29 Sep 2017 at 16:17 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mglamanFailing test
Comment #3
mglamanPR with fix: https://github.com/drupalcommerce/commerce/pull/741
That meant to me 2017-02-15. And when I change that locally it passes.
I'm really confused. Because when we run #2792653: Checkout coupon pane implementation there's this bug.
Comment #4
mglamanOkay, now this fails and makes the issue clear. The promotion which has a start date manually set works fine. However, when a start date is not specified it seems to fail.
Comment #5
mglamanSo confused.
gmdate, running kernel test where promotion uses generated date time.
changed to just date
So I think the problem is in core?
Comment #6
mglamanSo confused. I added the following debugging in the entity class for Promotion.
The result:
So, for some reason once the time is passed to TypedData/Field API it jumps. I've had a nearly constant different of almost 8 hours. And actually, at looking at changes, it decreases over time.
Comment #7
mglamanmore, better testing.
Improved debugging when getting default value
This gets us the following output in test:
Somewhere core screws our date. The only core test coverage for this TypedData plugin is `\Drupal\KernelTests\Core\TypedData\TypedDataTest::testGetAndSet` and barely is testing.
Comment #8
mglamanThe issue is the
\Drupal\datetime\DateTimeComputedclass.with adjustment
I get this output
When the value is via DateTimeComputed the timed difference is way off.
Comment #9
mglamanIt seems the problem is #2632040: [PP-1] Add ability to select a timezone for datetime field.
It defaults timezone to UTC. Working on a fix.
Comment #10
agoradesign commentedYou surely know these moments, when you struggle with a problem such as you're doing now and already are quite confused and your nerves are frazzled, when suddenly someone comes being nitpicky about some minor important details that don't contribute nothing to solve the real problem? Well, here it is such one :DD
I believe that both the end date comparison as well as the proposed change to the start date comparison are wrong. Instead of ">=" and "<=" you should use ">" and "<". I know, this is only a matter of one second each and theefore relevant for edge cases that probably won't ever happen, and if, no one could prove that it was wrong or right, but we always aim for the correct results ;)
I've just done a pen & paper test. For easier imagining I haven't written down full timestamps, but rather stick to minute granularity in visualization, assuming that every entry is exactly happening at 0 seconds to given hour and minute.
When you have a discount valid from 12:00 to 14:00, then I'd expect that immediately starting from 12:00:00 and not 12:00:01 the promotion is available, as well as 14:00:00 is still valid. The attached pic shows that you should leave the equals sign in both comparisons.
This example leads me to a very interesting question regarding promotions in Commerce 2.x: is it possible to define start and end time granularity on a hour base? I do have an use case: a few weeks ago a customer (running on a different e-commerce platform), was participating on a campaign, which allowed a high discount only during 00:00 and 03:00 in Saturday night. Lacking the possibility to define the promotion end time during the day, they set the alarm clock to manually disable it during the night on a weekend :D
Comment #11
mglamanRE: #10. True, we assume midnight.
The test failed last night: https://travis-ci.org/drupalcommerce/commerce/jobs/236614056. Just passed locally. So it's all about the hours.
Based on the linked core issue, I do think we should at least consider the following changes
Because the calculated date time does not take into consideration the timezone. Or we should change it. Or not.
Either way, we've had plenty of people having invalid coupons due to start times. Functional tests pass versus kernel tests with our logic.
Comment #12
mglamanI found #2632040: [PP-1] Add ability to select a timezone for datetime field. Our errors were using the computed
datefield value and not the raw timestamp and generating our own date time object. This bug only realized itself around evening time.The PR here has tests and now tests this bug specifically, and has the fix: https://github.com/drupalcommerce/commerce/pull/741
Comment #13
mglamanPatch for those who need it
Comment #15
bojanz commentedFixing this became a real late night adventure because a test fix showed that DrupalDateTime::createFromFormat() actually defaults the time to the current time, instead of 00:00:00. Fixed by not using it.
Comment #16
bojanz commentedAlso, note that there's another problem here: because the date field stores no timezone, the promotion start/end dates are always specific to the customer's timezone. If you specified June 1st - June 10th assuming the EST timezone, and I'm in the GMT timezone, then the promotion will start earlier for me than for someone who's in EST. We could solve this by having a $store->timezone that's used for these things.
Should be possible to do a hook_entity_base_fields_alter() and change the datetime_type for the fields from date to datetime. The widgets respect that. A more interesting question is whether hours should be allowed by default. That's something that we can change at any time, since the field schema doesn't depend on it.
Comment #18
mengi commentedWould be great to have a timezone for the store and be able to control the time for promotions to start/end. I think this should be the default with midnight entered.