diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index 219f185..2431d92 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -103,6 +103,7 @@ if (!class_exists('WC_Retailcrm_Base')) { if (!$this->get_option('deactivate_update_order') || $this->get_option('deactivate_update_order') == static::NO ) { + add_action('woocommerce_new_order', array($this, 'create_order'), 11, 1); add_action('woocommerce_update_order', array($this, 'update_order'), 11, 1); } @@ -289,6 +290,19 @@ if (!class_exists('WC_Retailcrm_Base')) { $this->customers->updateCustomer($customer_id); } + /** + * Create order in retailCRM + * @param int $order_id + */ + public function create_order($order_id) + { + if (WC_Retailcrm_Plugin::history_running() === true) { + return; + } + + $this->orders->orderCreate($order_id); + } + /** * Edit order in retailCRM * @param int $order_id diff --git a/src/include/class-wc-retailcrm-orders.php b/src/include/class-wc-retailcrm-orders.php index b15fc4e..7e5f185 100644 --- a/src/include/class-wc-retailcrm-orders.php +++ b/src/include/class-wc-retailcrm-orders.php @@ -387,7 +387,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $this->order_payment->is_new = true; $order_data['payments'][] = $this->order_payment->build($order)->get_data(); } - + $this->order = apply_filters('retailcrm_process_order', WC_Retailcrm_Plugin::clearArray($order_data), $order); } diff --git a/src/include/order/class-wc-retailcrm-order-payment.php b/src/include/order/class-wc-retailcrm-order-payment.php index 6171154..5eb63de 100644 --- a/src/include/order/class-wc-retailcrm-order-payment.php +++ b/src/include/order/class-wc-retailcrm-order-payment.php @@ -51,6 +51,8 @@ class WC_Retailcrm_Order_Payment extends WC_Retailcrm_Abstracts_Data */ public function build($order, $externalId = false) { + $this->reset_data(); + $data = array( 'amount' => (double) $order->get_total() ); @@ -81,11 +83,27 @@ class WC_Retailcrm_Order_Payment extends WC_Retailcrm_Abstracts_Data } } - $this->set_data_fields(WC_Retailcrm_Plugin::clearArray($data)); + $this->set_data_fields($data); return $this; } + /** + * Returns false if payment doesn't have method + * + * @return array + */ + public function get_data() + { + $data = parent::get_data(); + + if (empty($data['type'])) { + return array(); + } + + return $data; + } + public function reset_data() { $this->data = array(