Skip to content
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

Fixes #38757 - pass time values on CSV importer #39372

Conversation

AndrewJDawes
Copy link
Contributor

@AndrewJDawes AndrewJDawes commented Jul 23, 2023

Validate datestrings and convert Unix timestamps to datestrings with UTC timezone specified.

Submission Review Guidelines:

Changes proposed in this Pull Request:

Add time support to date on sale from and date on sale to to product CSV import.

Closes #38757 .

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Run
# wp shell
wp> strtotime('now');
=> int(1690313746)
wp> strtotime('+12 hours');
=> int(1690358071)
  1. Create a product import CSV file
SKU,Name,"Date sale price starts","Date sale price ends"
"pr-39372-1","pr 39372 1","2023-08-01 09:00","2023-08-02 21:00"
"pr-39372-2","pr 39372 2","2023-08-01T09:00","2023-08-01T21:00"
"pr-39372-3","pr 39372 3","2023/08/01 09:00","2023/08/01 21:00"
"pr-39372-4","pr 39372 4","FIRST_TIMESTAMP","SECOND_TIMESTAMP"
  1. Import this product CSV in trunk
  2. Using the imported product IDs, repeat the same 3 lines for each in wp shell
$product = wc_get_product( PRODUCTID );
$product->get_date_on_sale_from();
$product->get_date_on_sale_to();

5- Product should be on sale as follows

  • 1 - 2023-08-01 00:00 to 2023-08-02 00:00
  • 2 - 2023-08-01 00:00 to 2023-08-01 00:00
  • 3 - not on sale
  • 4 - not on sale

6- Switch to this branch
7- Re-import the CSV with the modify existing checked
8- Repeat step 4. Product should be on sale as follows

  • 1 - 2023-08-01 09:00 to 2023-08-02 21:00
  • 2 - 2023-08-01 09:00 to 2023-08-01 21:00
  • 3 - 2023-08-01 09:00 to 2023-08-01 21:00
  • 4 - on sale for 12 hours starting when you ran the first strtotime() above
  1. Optionally, test any of the standard formats

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message Allow passing time values on product CSV importer.

Comment

Validate datestrings and convert Unix timestamps to datestrings with UTC timezone specified.
@github-actions github-actions bot added plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution labels Jul 23, 2023
@woocommercebot woocommercebot requested review from a team and rrennick and removed request for a team July 23, 2023 01:09
@github-actions
Copy link
Contributor

Hi ,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@rrennick
Copy link
Contributor

@AndrewJDawes Thanks again. When we ask contributors to make changes to a PR, we are not asking for a new PR. We would like to see the changes made to the PR being reviewed. Having the discussion of change all located on the same PR is useful to us when the change is X years old and we need to refresh on why the change was made.

Secondly, people test every PR that makes functional changes so we need testing instructions on those PRs. In this case, we'll need to ensure the a wider range of date formats work in multiple regional settings so I'll research that a bit and add the testing instructions.

Copy link
Contributor

@rrennick rrennick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndrewJDawes Thanks for the help. This looks and tested great. I'll need to add a changelog then let it re-run through CI once the one suggestion is addressed before approving.

// If the value is a valid date string, return as is.
return $value;
}
// If value is not valid Unix timestamp or date string, return null.
Copy link
Contributor

@rrennick rrennick Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this return to after the try/catch block so the funtcion always falls back to explicitly returning a null?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also one code sniff issue that needs to be addressed.

@AndrewJDawes
Copy link
Contributor Author

Thanks for explaining this to me, @rrennick !

Appreciate your help on this - this has helped me learn a good deal about how to contribute.

I implemented your feedback on this same PR.

Would you please let me know if there is anything else I should do before this can be merged?

Copy link
Contributor

@rrennick rrennick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please let me know if there is anything else I should do before this can be merged?

This looks great @AndrewJDawes . Thanks for the help.

@rrennick rrennick added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Jul 31, 2023
@nigeljamesstevenson nigeljamesstevenson added needs: internal testing Indicates if the PR requires further testing conducted by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Jul 31, 2023
@nigeljamesstevenson nigeljamesstevenson merged commit 132aba1 into woocommerce:trunk Jul 31, 2023
25 of 26 checks passed
@github-actions github-actions bot added this to the 8.1.0 milestone Jul 31, 2023
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Jul 31, 2023
@nigeljamesstevenson nigeljamesstevenson removed the needs: analysis Indicates if the PR requires a PR testing scrub session. label Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: internal testing Indicates if the PR requires further testing conducted by Solaris plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Product not put on Sale after importing data thru CSV
3 participants