1
0
mirror of synced 2025-01-19 01:11:42 +03:00

Deleted space in the date, discount for order items (#43)

This commit is contained in:
Akolzin Dmitry 2018-01-10 14:26:05 +03:00 committed by Alex Lushpai
parent 2aed9a81eb
commit f7c2c71d93
4 changed files with 47 additions and 29 deletions

View File

@ -29,6 +29,11 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) :
); );
} }
/**
* Upload customers to CRM
*
* @return void
*/
public function customersUpload() public function customersUpload()
{ {
$users = get_users(); $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) public function createCustomer($customer_id)
{ {
$customer = new WC_Customer($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) public function updateCustomer($customer_id)
{ {
$customer = new WC_Customer($customer_id); $customer = new WC_Customer($customer_id);
@ -93,6 +112,13 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) :
} }
} }
/**
* Process customer
*
* @param object $customer
*
* @return array $data_customer
*/
protected function processCustomer($customer) protected function processCustomer($customer)
{ {
$createdAt = $customer->get_date_created(); $createdAt = $customer->get_date_created();

View File

@ -14,6 +14,9 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
*/ */
class WC_Retailcrm_Orders class WC_Retailcrm_Orders
{ {
protected $retailcrm_settings;
protected $retailcrm;
public function __construct() public function __construct()
{ {
$this->retailcrm_settings = get_option( 'woocommerce_integration-retailcrm_settings' ); $this->retailcrm_settings = get_option( 'woocommerce_integration-retailcrm_settings' );
@ -275,7 +278,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
* *
* @param int $order_id * @param int $order_id
* *
* @return arr * @return array $order_data
*/ */
public function processOrder($order_id) 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['createdAt'] = trim($order_data_info['date']);
$order_data['customerComment'] = $order_data_info['customer_comment']; $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') { 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']]; $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) { foreach ($order->get_items() as $item) {
$uid = ($item['variation_id'] > 0) ? $item['variation_id'] : $item['product_id'] ; $uid = ($item['variation_id'] > 0) ? $item['variation_id'] : $item['product_id'] ;
$_product = wc_get_product($uid); $_product = wc_get_product($uid);
$price = wc_get_price_including_tax($_product);
if ($_product) { if ($_product) {
$product_price = $item->get_total() ? $item->get_total() / $item->get_quantity() : 0; $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; $product_tax = $item->get_total_tax() ? $item->get_total_tax() / $item->get_quantity() : 0;
$price_item = $product_price + $product_tax; $price_item = $product_price + $product_tax;
$discount_price = $price - $price_item;
if ($this->retailcrm_settings['api_version'] != 'v3') {
$order_item = array( $order_item = array(
'offer' => array('externalId' => $uid), 'offer' => array('externalId' => $uid),
'productName' => $item['name'], 'productName' => $item['name'],
'initialPrice' => (float)$price_item, 'initialPrice' => (float)$price,
'quantity' => $item['qty'],
);
} else {
$order_item = array(
'productId' => $uid,
'productName' => $item['name'],
'initialPrice' => (float)$price_item,
'quantity' => $item['qty'], '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;
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Version: 2.0.1 * Version: 2.0.2
* Plugin Name: WooCommerce RetailCRM * Plugin Name: WooCommerce RetailCRM
* Plugin URI: https://wordpress.org/plugins/woo-retailcrm/ * Plugin URI: https://wordpress.org/plugins/woo-retailcrm/
* Description: Integration plugin for WooCommerce & RetailCRM * Description: Integration plugin for WooCommerce & RetailCRM

View File

@ -15,7 +15,7 @@
* *
* *
* @link https://wordpress.org/plugins/woo-retailcrm/ * @link https://wordpress.org/plugins/woo-retailcrm/
* @since 2.0.1 * @since 2.0.2
* *
* @package RetailCRM * @package RetailCRM
*/ */