Parcourir la source

add handling after payment, fix statuses

Dalibor Votruba il y a 1 an
Parent
commit
8b6d8ebd57

+ 7 - 5
studiou-wc-ord-print-statuses/includes/class-bulk-actions-manager.php

@@ -35,13 +35,15 @@ class Bulk_Actions_Manager {
         global $wpdb;
         $orders_data = $wpdb->get_results("SELECT * FROM `vsu_orders_car_prod_qty_img` WHERE order_no IN (" . implode(',', array_map('intval', $post_ids)) . ")");
 
+
+        $this->set_status_to_prepare_to_printing($post_ids, $redirect_to);
+        UtilsLog::log('Order statuses set to "to-print" after export.');
+
         if (!empty($orders_data)) {
             $csv_data = $this->generate_csv($orders_data);
+            UtilsLog::log('file prepare_to_printing_export.csv exported');
             $this->output_csv($csv_data, 'prepare_to_printing_export.csv');
         }
-
-        $this->set_status_to_prepare_to_printing($post_ids, $redirect_to);
-        UtilsLog::log('file exported');
         return $redirect_to;
     }
 
@@ -51,7 +53,7 @@ class Bulk_Actions_Manager {
             UtilsLog::log('Setting status Order #' . $post_id . ' to "to-print"');
             $order = wc_get_order($post_id);
             if ($order) {
-                $order->update_status('wc-to-print');
+                $order->update_status('to-print');
                 update_post_meta($post_id, 'to-print-date', current_time('mysql'));
                 UtilsLog::log('Order #' . $post_id . ' marked as "to-print"');
             }
@@ -67,7 +69,7 @@ class Bulk_Actions_Manager {
         foreach ($post_ids as $post_id) {
             $order = wc_get_order($post_id);
             if ($order) {
-                $order->update_status('wc-in-print');
+                $order->update_status('in-print');
                 update_post_meta($post_id, 'in-print-date', current_time('mysql'));
             }
         }

+ 4 - 4
studiou-wc-ord-print-statuses/includes/class-import-manager.php

@@ -76,7 +76,7 @@ class Import_Manager {
                 $errors[] = sprintf(__('Order %s not found.', 'studiou-wc-ord-print-statuses'), $row['order_no']);
                 continue;
             }
-            $order->update_status('wc-in-print');
+            $order->update_status('in-print');
             $order->update_meta_data('in_print_date', current_time('mysql'));
             $order->update_meta_data('external_ref_ord_no', $row['ExternalOrder']);
             $order->update_meta_data('external_ref_ord_date', $row['ExternalOrderDate']);
@@ -91,7 +91,7 @@ class Import_Manager {
         }
 
         wp_redirect(add_query_arg('message', urlencode($message), admin_url('admin.php?page=studiou-import-protocols')));
-        exit;
+        //exit;
     }
 
     public function handle_import_delivered_protocol() {
@@ -127,7 +127,7 @@ class Import_Manager {
                 continue;
             }
 
-            $order->update_status('wc-completed');
+            $order->update_status('completed');
             $order->update_meta_data('external_ref_ord_delivered', current_time('mysql'));
             $order->save();
 
@@ -140,7 +140,7 @@ class Import_Manager {
         }
 
         wp_redirect(add_query_arg('message', urlencode($message), admin_url('admin.php?page=studiou-import-protocols')));
-        exit;
+        //exit;
     }
 
     private function parse_csv($file_path) {

+ 16 - 2
studiou-wc-ord-print-statuses/includes/class-order-status-manager.php

@@ -18,6 +18,8 @@ class Order_Status_Manager {
         add_action('init', array($this, 'register_custom_order_statuses'));
         add_filter('wc_order_statuses', array($this, 'add_custom_order_statuses_to_list'));
         add_action('woocommerce_order_status_changed', array($this, 'handle_status_transitions'), 10, 3);
+        add_action('woocommerce_payment_complete', array($this, 'set_order_processing_status'));
+
     }
 
     public function register_custom_order_statuses() {
@@ -53,13 +55,25 @@ class Order_Status_Manager {
     public function handle_status_transitions($order_id, $old_status, $new_status) {
         // Handle status transitions here
         // For example:
-        if ($new_status === 'wc-to-print') {
+        UtilsLog::log('Order #' . $order_id . ' status change ' . $old_status . ' -> ' . $new_status);
+        if ($new_status === 'to-print') {
             update_post_meta($order_id, 'to-print-date', current_time('mysql'));
-        } elseif ($new_status === 'wc-in-print') {
+        } elseif ($new_status === 'in-print') {
             update_post_meta($order_id, 'in-print-date', current_time('mysql'));
         }
     }
 
+    public function set_order_processing_status($order_id) {
+        UtilsLog::log('Order #' . $order_id . ' payment complete');
+        $order = wc_get_order($order_id);
+        if ($order && !$order->has_status('completed')) {
+            UtilsLog::log('Order #' . $order_id . ' will be move to processing');
+            $order->update_status('processing', __('Payment received, order is now processing.', 'studiou-wc-ord-print-statuses'));
+            // Add a note to the order
+            $order->add_order_note(__('Order automatically set to processing by Studiou WC Order Print Statuses plugin.', 'studiou-wc-ord-print-statuses'));
+            
+        }
+    }
     public function get_custom_statuses() {
         return $this->custom_statuses;
     }