Remember downloadable files (#44008)

* The previously uploaded file should re-appear when the product changes from downloadable to not and then back again

* Add changelog file

* Fix php linter error
This commit is contained in:
Maikel Perez 2024-01-23 14:53:22 -03:00 committed by GitHub
parent 2acbb3d3fb
commit 9f3c7885a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: tweak
The previously uploaded file should re-appear when the product changes from downloadable to not and then back again

View File

@ -1561,6 +1561,31 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
return $params;
}
/**
* Get the downloads for a product.
*
* @param WC_Product $product Product instance.
*
* @return array
*/
protected function get_downloads( $product ) {
$downloads = array();
$context = isset( $this->request ) && isset( $this->request['context'] ) ? $this->request['context'] : 'view';
if ( $product->is_downloadable() || 'edit' === $context ) {
foreach ( $product->get_downloads() as $file_id => $file ) {
$downloads[] = array(
'id' => $file_id, // MD5 hash.
'name' => $file['name'],
'file' => $file['file'],
);
}
}
return $downloads;
}
/**
* Get product data.
*