Fix: variations exported as draft were imported as draft (#36933)

* Fix: variations exported as draft were imported as draft

* Add changelog file

* Fix "ArrayUtil::get_value_or_default" for existing keys with null values

Now ArrayUtil::get_value_or_default($array, $key, $default) will return
null, instead of $default, when $array[$key] exists and is null.

* Undo the change to ArrayUtil (will get its own PR)
This commit is contained in:
Néstor Soriano 2023-03-07 17:57:17 +01:00 committed by GitHub
parent 81fdbe3125
commit 8786c19b74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix variations exported as draft being imported as draft (and thus remaining invisible)

View File

@ -843,15 +843,20 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
// Status is mapped from a special published field.
if ( isset( $data['published'] ) ) {
$published = $data['published'];
if ( is_float( $published ) ) {
$published = (int) $published;
}
$statuses = array(
-1 => 'draft',
0 => 'private',
1 => 'publish',
);
$data['status'] = isset( $statuses[ $data['published'] ] ) ? $statuses[ $data['published'] ] : 'draft';
$data['status'] = $statuses[ $published ] ?? 'draft';
// Fix draft status of variations.
if ( isset( $data['type'] ) && 'variation' === $data['type'] && -1 === $data['published'] ) {
if ( 'variation' === ( $data['type'] ?? null ) && -1 === $published ) {
$data['status'] = 'publish';
}