API should generate or set file ID when setting downloads. Closes #18330
This commit is contained in:
parent
3459f83a9d
commit
effbf87e22
|
@ -1177,7 +1177,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
if ( is_a( $download, 'WC_Product_Download' ) ) {
|
||||
$download_object = $download;
|
||||
} else {
|
||||
$download_object = new WC_Product_Download();
|
||||
$download_object = new WC_Product_Download();
|
||||
|
||||
// If we don't have a previous hash, generate UUID for download.
|
||||
if ( empty( $download['download_id'] ) ) {
|
||||
|
|
|
@ -1172,10 +1172,10 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
}
|
||||
|
||||
$download = new WC_Product_Download();
|
||||
$download->set_id( $key );
|
||||
$download->set_id( $file['id'] ? $file['id'] : wp_generate_uuid4() );
|
||||
$download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) );
|
||||
$download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) );
|
||||
$files[] = $download;
|
||||
$files[] = $download;
|
||||
}
|
||||
$product->set_downloads( $files );
|
||||
|
||||
|
|
|
@ -1527,7 +1527,7 @@ class WC_API_Products extends WC_API_Resource {
|
|||
}
|
||||
|
||||
$download = new WC_Product_Download();
|
||||
$download->set_id( $key );
|
||||
$download->set_id( $file['id'] ? $file['id'] : wp_generate_uuid4() );
|
||||
$download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) );
|
||||
$download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) );
|
||||
$files[] = $download;
|
||||
|
|
|
@ -2031,7 +2031,7 @@ class WC_API_Products extends WC_API_Resource {
|
|||
}
|
||||
|
||||
$download = new WC_Product_Download();
|
||||
$download->set_id( $key );
|
||||
$download->set_id( $file['id'] ? $file['id'] : wp_generate_uuid4() );
|
||||
$download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) );
|
||||
$download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) );
|
||||
$files[] = $download;
|
||||
|
|
|
@ -960,7 +960,7 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
|
|||
}
|
||||
|
||||
$download = new WC_Product_Download();
|
||||
$download->set_id( $key );
|
||||
$download->set_id( $file['id'] ? $file['id'] : wp_generate_uuid4() );
|
||||
$download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) );
|
||||
$download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) );
|
||||
$files[] = $download;
|
||||
|
|
Loading…
Reference in New Issue