diff --git a/retailcrm/include/class-wc-retailcrm-orders.php b/retailcrm/include/class-wc-retailcrm-orders.php index 16ec1cf..219b5d4 100644 --- a/retailcrm/include/class-wc-retailcrm-orders.php +++ b/retailcrm/include/class-wc-retailcrm-orders.php @@ -250,20 +250,20 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $order_data_arr = []; if (version_compare(get_option('woocommerce_db_version'), '3.0', '<' )) { - $order_data_arr['id'] = $order->id; - $order_data_arr['date'] = $order->order_date; - $order_data_arr['payment_method'] = $order->payment_method; - $order_data_arr['discount_total'] = $order->data['discount_total']; - $order_data_arr['discount_tax'] = $order->data['discount_tax']; - $order_data_arr['customer_comment'] = $order->data['customerComment']; + $order_data_arr['id'] = $order->id; + $order_data_arr['date'] = $order->order_date; + $order_data_arr['payment_method'] = $order->payment_method; + $order_data_arr['discount_total'] = $order->get_total_discount(); + $order_data_arr['discount_tax'] = $order->cart_discount_tax; + $order_data_arr['customer_comment'] = $order->customer_message; } else { $order_info = $order->get_data(); - $order_data_arr['id'] = $order_info['id']; - $order_data_arr['payment_method'] = $order->get_payment_method(); - $order_data_arr['date'] = $order_info['date_created']->date('Y-m-d H:i:s'); - $order_data_arr['discount_total'] = $order_info['discount_total']; - $order_data_arr['discount_tax'] = $order_info['discount_tax']; + $order_data_arr['id'] = $order_info['id']; + $order_data_arr['date'] = $order_info['date_created']->date('Y-m-d H:i:s'); + $order_data_arr['payment_method'] = $order->get_payment_method(); + $order_data_arr['discount_total'] = $order_info['discount_total']; + $order_data_arr['discount_tax'] = $order_info['discount_tax']; $order_data_arr['customer_comment'] = $order->get_customer_note(); } @@ -450,16 +450,23 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $this->retailcrm->ordersPaymentCreate($payment); } + /** + * update order + * + * @param int $order_id + * + * @return void + */ public function updateOrder($order_id) { - $order = $this->processOrder($order_id); - - $response = $this->retailcrm->ordersEdit($order); - $order = new WC_Order($order_id); + $order_data = $this->processOrder($order_id); + $order_data_info = $this->getOrderData($order_id); + + $response = $this->retailcrm->ordersEdit($order_data); if ($response->isSuccessful()) { - $this->orderUpdatePaymentType($order_id, $order->payment_method); + $this->orderUpdatePaymentType($order_id, $order_data_info['payment_method']); } } } diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index 2d17995..4250101 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -321,6 +321,13 @@ function ajax_upload() { updateOrder($order_id); } +/** + * create order (woocommerce 3.0) + * + * @param int $order_id + * + * @return void + */ + +function create_order($order_id) { + if ( get_post_type($order_id) == 'shop_order' && get_post_status( $order_id ) != 'auto-draft' ) { + if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) { + include_once( __DIR__ . check_custom_order() ); + } + + $order_class = new WC_Retailcrm_Orders(); + $order_class->orderCreate($order_id); + } +} + register_activation_hook( __FILE__, 'retailcrm_install' ); register_deactivation_hook( __FILE__, 'retailcrm_deactivation' ); if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option( 'active_plugins')))) { load_plugin_textdomain('wc_retailcrm', false, dirname(plugin_basename( __FILE__ )) . '/'); add_filter('cron_schedules', 'filter_cron_schedules', 10, 1); - add_action('woocommerce_checkout_order_processed', 'retailcrm_process_order', 10, 1); add_action('retailcrm_history', 'retailcrm_history_get'); add_action('retailcrm_icml', 'generate_icml'); add_action('retailcrm_inventories', 'load_stocks'); @@ -349,11 +374,13 @@ if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_ add_action( 'woocommerce_checkout_update_user_meta', 10, 2 ); if (version_compare(get_option('woocommerce_db_version'), '3.0', '<' )) { + add_action('woocommerce_checkout_order_processed', 'retailcrm_process_order', 10, 1); add_action('woocommerce_order_status_changed', 'retailcrm_update_order_status', 11, 1); add_action('woocommerce_saved_order_items', 'retailcrm_update_order_items', 10, 2); add_action('update_post_meta', 'retailcrm_update_order', 11, 4); add_action('woocommerce_payment_complete', 'retailcrm_update_order_payment', 11, 1); } else { add_action('woocommerce_update_order', 'update_order', 11, 1); + add_action('wp_insert_post', 'create_order' ); } }