Closed mikkamp closed 1 month ago
@coreymckrill Thanks for the quick review. I went ahead and added that offset to the payment date as well.
Looking in the DB table for wc_order_stats
I can now see the last 10 orders have a random offset for the payment date:
Would you mind taking one more quick look that all is well?
@mikkamp looks good! Another thing just occurred to me, though. In some cases, adding up to 36 hours to the paid/completed date could end up making those dates be in the future. That doesn't seem great to me, but I could be convinced otherwise.
If we want to prevent that, we could potentially do something like this:
min( strtotime( $date ) + ( wp_rand( 0, 36 ) * HOUR_IN_SECONDS ), time() )
Another thing just occurred to me, though. In some cases, adding up to 36 hours to the paid/completed date could end up making those dates be in the future. That doesn't seem great to me, but I could be convinced otherwise.
That is true, but considering that we are also able to generate orders in the future, with something like:
wp wc generate orders 10 --date-start=2024-10-01 --date-end=2024-10-30
I didn't think it would be such a big deal to have payment dates in the future. If they would really want to prevent that then they could always specify an older date range to prevent it from getting anything in the future.
All Submissions:
Changes proposed in this Pull Request:
When we generate orders we are able to generate them over a range of dates. This works correctly when setting the order creation date. However other dates will default to the current date.
So if we generate a set of orders for the Analytics reports the
date_paid
will all be at the time of when the order was generated. Which isn't very useful for populating some test data for these reports.This PR changes that behaviour and allows setting both the paid date as well as the order completed date. This is set based on the chosen status of the order. Paid date is set for both processing and completed. Completed date is set for only completed orders. The date is set by adding a random amount of 0 to 36 hours to the creation date.
How to test the changes in this Pull Request:
wp wc generate orders 10 --date-start=2024-01-01 --date-end=2024-01-31
Other information:
Changelog entry
FOR PR REVIEWER ONLY: