Merged in feature/MAW-855-import-code-into-aws (pull request #2)

code import from pantheon

* code import from pantheon
This commit is contained in:
Tony Volpe
2023-12-04 23:08:14 +00:00
parent 8c9b1312bc
commit 8f4b5efda6
4766 changed files with 185592 additions and 239967 deletions

View File

@@ -590,6 +590,35 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
return null;
}
/**
* Parse dates from a CSV.
* Dates can be Unix timestamps or in any format supported by strtotime().
*
* @param string $value Field value.
*
* @return string|null
*/
public function parse_datetime_field( $value ) {
try {
// If value is a Unix timestamp, convert it to a datetime string.
if ( is_numeric( $value ) ) {
$datetime = new DateTime( "@{$value}" );
// Return datetime string in ISO8601 format (eg. 2018-01-01T00:00:00Z) to preserve UTC timezone since Unix timestamps are always UTC.
return $datetime->format( 'Y-m-d\TH:i:s\Z' );
}
// Check whether the value is a valid date string.
if ( false !== strtotime( $value ) ) {
// If the value is a valid date string, return as is.
return $value;
}
} catch ( Exception $e ) {
// DateTime constructor throws an exception if the value is not a valid Unix timestamp.
return null;
}
// If value is not valid Unix timestamp or date string, return null.
return null;
}
/**
* Parse backorders from a CSV.
*
@@ -725,8 +754,8 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
'type' => array( $this, 'parse_comma_field' ),
'published' => array( $this, 'parse_published_field' ),
'featured' => array( $this, 'parse_bool_field' ),
'date_on_sale_from' => array( $this, 'parse_date_field' ),
'date_on_sale_to' => array( $this, 'parse_date_field' ),
'date_on_sale_from' => array( $this, 'parse_datetime_field' ),
'date_on_sale_to' => array( $this, 'parse_datetime_field' ),
'name' => array( $this, 'parse_skip_field' ),
'short_description' => array( $this, 'parse_description_field' ),
'description' => array( $this, 'parse_description_field' ),