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

order_date not set to NULL when a serial number is set to 'available' status #384

Open
gmn42 opened this issue Sep 2, 2023 · 0 comments

Comments

@gmn42
Copy link
Contributor

gmn42 commented Sep 2, 2023

When a serial number is set to 'available' status (via the UI or through the Key class), the order_id is set to 0 and the order_date should be set to NULL (see Key.php line 518). However, this does not happen because wp_array_slice_assoc() is used during the save() method in the parent Model class, and this function cannot handle keys in the input array that are set to NULL (probably a WP bug, it uses isset() on the input array, which returns false if a key exists but is set to null).

This can be resolved with the following patch (I can't submit a PR because Model.php is not in this repo):

--- ../wc-serial-numbers/lib/Lib/Model.php	2023-08-31 23:59:24.424829309 -0700
+++ lib/Lib/Model.php	2023-09-02 12:48:06.633619770 -0700
@@ -467,7 +467,7 @@ abstract class Model {
 		 */
 		do_action( $this->get_hook_prefix() . '_pre_update', $this, $changes );
 
-		$data = wp_array_slice_assoc( $changes, $this->get_core_data_keys() );
+		$data = $this->array_slice_assoc( $changes, $this->get_core_data_keys() );
 
 		/**
 		 * Filters the data to be updated in the database.
@@ -503,6 +503,10 @@ abstract class Model {
 		return true;
 	}
 
+	function array_slice_assoc($array,$keys) {
+		return array_intersect_key($array,array_flip($keys));
+	}
+
 	/**
 	 * Deletes the object from database.
 	 *

See the Notes section at https://www.php.net/manual/en/function.array-slice.php for more info about this solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant