From c92087fc33d3842fb3d80d85a31aef4aa779baef Mon Sep 17 00:00:00 2001 From: OlfatProgressus Date: Mon, 11 Nov 2024 16:19:36 +0200 Subject: [PATCH 1/3] not to remove the merged file path from the saved data --- src/Order/Base.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Order/Base.php b/src/Order/Base.php index 7e167f95..c65123e6 100644 --- a/src/Order/Base.php +++ b/src/Order/Base.php @@ -537,14 +537,7 @@ function ( $barc ) { $barcodes ); - $saved_data['labels'] = array_map( - function ( $label ) { - unset( $label['merged_files'] ); - - return $label; - }, - $labels - ); + $saved_data['labels'] = $labels; if ( $this->settings->is_auto_complete_order_enabled() ) { // Updating the order status to completed. @@ -711,7 +704,8 @@ public function put_label_content( $response, $order, $parent_barcode, $parent_l $label_extension = ! empty( $label_contents['OutputType'] ) ? sanitize_title( $label_contents['OutputType'] ) : 'pdf'; $barcode = $response[ $type ][ $shipment_idx ][ $content_type['barcode_key'] ]; $barcode = is_array( $barcode ) ? array_shift( $barcode ) : $barcode; - $filename = Utils::generate_label_name( $order->get_id(), $label_type, $barcode, 'A6', $label_extension ); + $label_format = $this->settings->get_label_format(); + $filename = Utils::generate_label_name( $order->get_id(), $label_type, $barcode, $label_format, $label_extension ); $filepath = trailingslashit( POSTNL_UPLOADS_DIR ) . $filename; if ( wp_mkdir_p( POSTNL_UPLOADS_DIR ) && ! file_exists( $filepath ) ) { From 64b2717bc12af91c030138a112541dd2c09020bd Mon Sep 17 00:00:00 2001 From: OlfatProgressus Date: Thu, 21 Nov 2024 12:00:36 +0200 Subject: [PATCH 2/3] Fix file not found error by remove delete_label_files function --- src/Order/Base.php | 29 ++++++----------------------- src/Order/Bulk.php | 4 ---- src/Order/Single.php | 2 -- 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/src/Order/Base.php b/src/Order/Base.php index c65123e6..eb6693bb 100644 --- a/src/Order/Base.php +++ b/src/Order/Base.php @@ -1271,6 +1271,12 @@ public function delete_label( $saved_data ) { return false; } + if( isset( $saved_data['labels']['label']['merged_files'] ) ){ + foreach ( $saved_data['labels']['label']['merged_files'] as $label_path ) { + unlink( $label_path ); + } + } + return unlink( $saved_data['labels']['label']['filepath'] ); } @@ -1413,29 +1419,6 @@ protected function get_tracking_link( $order_id ) { return sprintf( '%2$s', esc_url( $tracking_url ), $saved_data['labels']['label']['barcode'] ); } - /** - * Delete label files from label info. - * - * @param Array $labels List of label info. - */ - public function delete_label_files( $labels ) { - if ( empty( $labels ) ) { - return; - } - - foreach ( $labels as $label_type => $label_info ) { - if ( empty( $label_info['merged_files'] ) || empty( $label_info['filepath'] ) ) { - continue; - } - - foreach ( $label_info['merged_files'] as $path ) { - if ( file_exists( $path ) && $path !== $label_info['filepath'] ) { - unlink( $path ); - } - } - } - } - /** * Check if the order have the label data. * diff --git a/src/Order/Bulk.php b/src/Order/Bulk.php index b2c17076..3d82efd9 100644 --- a/src/Order/Bulk.php +++ b/src/Order/Bulk.php @@ -229,10 +229,6 @@ public function merge_bulk_labels( $gen_labels ) { $merged_info = $this->merge_labels( $label_paths, $filename, $start_position ); - foreach ( $gen_labels as $labels ) { - $this->delete_label_files( $labels ); - } - if ( file_exists( $merged_info ['filepath'] ) ) { // We're saving the bulk file path temporarily and access it later during the download process. // This information expires in 3 minutes (180 seconds), just enough for the user to see the diff --git a/src/Order/Single.php b/src/Order/Single.php index ea91188f..12669ef1 100644 --- a/src/Order/Single.php +++ b/src/Order/Single.php @@ -460,8 +460,6 @@ public function save_meta_box_ajax() { $labels = $result['labels']; $tracking_note = $this->get_tracking_note( $order_id ); - $this->delete_label_files( $labels ); - if ( ! empty( $tracking_note ) ) { $return_data = array_merge( $result['saved_data'], From fc8b293c88933e6ccf80a3e22c2e9b728a40db61 Mon Sep 17 00:00:00 2001 From: OlfatProgressus <161600042+OlfatProgressus@users.noreply.github.com> Date: Fri, 29 Nov 2024 14:13:36 +0200 Subject: [PATCH 3/3] Update src/Order/Base.php Co-authored-by: Abdalsalaam Halawa --- src/Order/Base.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Order/Base.php b/src/Order/Base.php index eb6693bb..d51c39eb 100644 --- a/src/Order/Base.php +++ b/src/Order/Base.php @@ -1271,8 +1271,8 @@ public function delete_label( $saved_data ) { return false; } - if( isset( $saved_data['labels']['label']['merged_files'] ) ){ - foreach ( $saved_data['labels']['label']['merged_files'] as $label_path ) { + if ( isset( $saved_data['labels']['label']['merged_files'] ) ) { + foreach ( $saved_data['labels']['label']['merged_files'] as $label_path ) { unlink( $label_path ); } }