From f7c2c71d934de7badc17abaa74d7638e6acc6921 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Wed, 10 Jan 2018 14:26:05 +0300 Subject: [PATCH] Deleted space in the date, discount for order items (#43) --- .../include/class-wc-retailcrm-customers.php | 30 ++++++++++++- .../include/class-wc-retailcrm-orders.php | 42 ++++++++----------- woo-retailcrm/retailcrm.php | 2 +- woo-retailcrm/uninstall.php | 2 +- 4 files changed, 47 insertions(+), 29 deletions(-) diff --git a/woo-retailcrm/include/class-wc-retailcrm-customers.php b/woo-retailcrm/include/class-wc-retailcrm-customers.php index fbd689e..bbbb508 100644 --- a/woo-retailcrm/include/class-wc-retailcrm-customers.php +++ b/woo-retailcrm/include/class-wc-retailcrm-customers.php @@ -28,7 +28,12 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) : $this->retailcrm_settings['api_version'] ); } - + + /** + * Upload customers to CRM + * + * @return void + */ public function customersUpload() { $users = get_users(); @@ -69,6 +74,13 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) : } } + /** + * Create customer in CRM + * + * @param int $customer_id + * + * @return void + */ public function createCustomer($customer_id) { $customer = new WC_Customer($customer_id); @@ -81,6 +93,13 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) : } } + /** + * Edit customer in CRM + * + * @param int $customer_id + * + * @return void + */ public function updateCustomer($customer_id) { $customer = new WC_Customer($customer_id); @@ -93,12 +112,19 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) : } } + /** + * Process customer + * + * @param object $customer + * + * @return array $data_customer + */ protected function processCustomer($customer) { $createdAt = $customer->get_date_created(); $firstName = $customer->get_first_name(); $data_customer = array( - 'createdAt' => $createdAt->date('Y-m-d H:i:s '), + 'createdAt' => $createdAt->date('Y-m-d H:i:s'), 'externalId' => $customer_id, 'firstName' => $firstName ? $firstName : $customer->get_username(), 'lastName' => $customer->get_last_name(), diff --git a/woo-retailcrm/include/class-wc-retailcrm-orders.php b/woo-retailcrm/include/class-wc-retailcrm-orders.php index a5b2347..acf272a 100644 --- a/woo-retailcrm/include/class-wc-retailcrm-orders.php +++ b/woo-retailcrm/include/class-wc-retailcrm-orders.php @@ -14,6 +14,9 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : */ class WC_Retailcrm_Orders { + protected $retailcrm_settings; + protected $retailcrm; + public function __construct() { $this->retailcrm_settings = get_option( 'woocommerce_integration-retailcrm_settings' ); @@ -275,7 +278,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : * * @param int $order_id * - * @return arr + * @return array $order_data */ public function processOrder($order_id) { @@ -292,16 +295,6 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $order_data['createdAt'] = trim($order_data_info['date']); $order_data['customerComment'] = $order_data_info['customer_comment']; - if ( $order_data_info['discount_total'] ) { - $discount = $order_data_info['discount_total'] + $order_data_info['discount_tax']; - - if ($this->retailcrm_settings['api_version'] == 'v5') { - if ($discount > 0) $order_data['discountManualAmount'] = $discount; - } else { - if ($discount > 0) $order_data['discount'] = $discount; - } - } - if ( !empty( $order_data_info['payment_method'] ) && !empty($this->retailcrm_settings[$order_data_info['payment_method']]) && $this->retailcrm_settings['api_version'] != 'v5') { $order_data['paymentType'] = $this->retailcrm_settings[$order_data_info['payment_method']]; } @@ -376,26 +369,25 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : foreach ($order->get_items() as $item) { $uid = ($item['variation_id'] > 0) ? $item['variation_id'] : $item['product_id'] ; $_product = wc_get_product($uid); + $price = wc_get_price_including_tax($_product); if ($_product) { $product_price = $item->get_total() ? $item->get_total() / $item->get_quantity() : 0; $product_tax = $item->get_total_tax() ? $item->get_total_tax() / $item->get_quantity() : 0; $price_item = $product_price + $product_tax; + $discount_price = $price - $price_item; - if ($this->retailcrm_settings['api_version'] != 'v3') { - $order_item = array( - 'offer' => array('externalId' => $uid), - 'productName' => $item['name'], - 'initialPrice' => (float)$price_item, - 'quantity' => $item['qty'], - ); - } else { - $order_item = array( - 'productId' => $uid, - 'productName' => $item['name'], - 'initialPrice' => (float)$price_item, - 'quantity' => $item['qty'], - ); + $order_item = array( + 'offer' => array('externalId' => $uid), + 'productName' => $item['name'], + 'initialPrice' => (float)$price, + 'quantity' => $item['qty'], + ); + + if ($this->retailcrm_settings['api_version'] == 'v5') { + $order_item['discountManualAmount'] = $discount_price; + } elseif ($this->retailcrm_settings['api_version'] == 'v4') { + $order_item['discount'] = $discount_price; } } diff --git a/woo-retailcrm/retailcrm.php b/woo-retailcrm/retailcrm.php index 4ea6269..add5549 100644 --- a/woo-retailcrm/retailcrm.php +++ b/woo-retailcrm/retailcrm.php @@ -1,6 +1,6 @@