fix error with client duplication
This commit is contained in:
parent
45bbd5dd81
commit
1481edae95
@ -1,3 +1,6 @@
|
||||
## 2020-04-13 3.6.2
|
||||
* Исправлена ошибка, которая приводила к дублированию некоторых клиентов
|
||||
|
||||
## 2019-03-31 3.6.1
|
||||
* Исправлена ошибка генерации каталога товаров
|
||||
|
||||
|
@ -228,16 +228,33 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
update_option(static::$option_key, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create customer in retailCRM
|
||||
* @param int $customer_id
|
||||
*/
|
||||
/**
|
||||
* Create customer in retailCRM
|
||||
*
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function create_customer($customer_id)
|
||||
{
|
||||
if (WC_Retailcrm_Plugin::history_running() === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
$client = $this->getApiClient();
|
||||
|
||||
if (empty($client)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$wcCustomer = new WC_Customer($customer_id);
|
||||
$resp = $client->customersList(array('email' => $wcCustomer->get_billing_email()));
|
||||
|
||||
if ($resp && $resp->isSuccessful() && isset($resp['customers']) && count($resp['customers']) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->customers->createCustomer($customer_id);
|
||||
}
|
||||
|
||||
@ -321,7 +338,7 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
/**
|
||||
* Get retailcrm api client
|
||||
*
|
||||
* @return bool|WC_Retailcrm_Proxy
|
||||
* @return bool|WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V4|\WC_Retailcrm_Client_V5
|
||||
*/
|
||||
public function getApiClient()
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ if (!class_exists('WC_Retailcrm_Customers')) :
|
||||
|
||||
const CUSTOMER_ROLE = 'customer';
|
||||
|
||||
/** @var bool | WC_Retailcrm_Proxy */
|
||||
/** @var bool | WC_Retailcrm_Proxy | \WC_Retailcrm_Client_V5 */
|
||||
protected $retailcrm;
|
||||
|
||||
/** @var array */
|
||||
@ -148,7 +148,7 @@ if (!class_exists('WC_Retailcrm_Customers')) :
|
||||
'createdAt' => $createdAt->date('Y-m-d H:i:s'),
|
||||
'firstName' => $firstName ? $firstName : $customer->get_username(),
|
||||
'lastName' => $customer->get_last_name(),
|
||||
'email' => $customer->get_email(),
|
||||
'email' => $customer->get_billing_email(),
|
||||
'address' => $this->customer_address->build($customer)->get_data()
|
||||
);
|
||||
|
||||
|
@ -135,6 +135,12 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
'externalId' => $wpUserId
|
||||
));
|
||||
|
||||
if (empty($foundCustomer)) {
|
||||
$foundCustomer = $this->customers->searchCustomer(array(
|
||||
'email' => $wcOrder->get_billing_email()
|
||||
));
|
||||
}
|
||||
|
||||
if (empty($foundCustomer)) {
|
||||
$customerId = $this->customers->createCustomer($wpUserId);
|
||||
|
||||
@ -142,7 +148,11 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
$this->order['customer']['id'] = $customerId;
|
||||
}
|
||||
} else {
|
||||
$this->order['customer']['externalId'] = $foundCustomer['externalId'];
|
||||
if (!empty($foundCustomer['externalId'])) {
|
||||
$this->order['customer']['externalId'] = $foundCustomer['externalId'];
|
||||
} else {
|
||||
$this->order['customer']['id'] = $foundCustomer['id'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$foundCustomer = $this->customers->searchCustomer(array(
|
||||
@ -157,7 +167,11 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
$this->order['customer']['id'] = $customerId;
|
||||
}
|
||||
} else {
|
||||
$this->order['customer']['externalId'] = $foundCustomer['externalId'];
|
||||
if (!empty($foundCustomer['externalId'])) {
|
||||
$this->order['customer']['externalId'] = $foundCustomer['externalId'];
|
||||
} else {
|
||||
$this->order['customer']['id'] = $foundCustomer['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,9 @@ API-ключ должен быть для отдельного магазина
|
||||
2. В появившихся списках справочников настройте соответствие способов доставки и оплаты, а так же статусов заказов. Отметьте галочку "Выгружать остатки", если хотите выгружать остатки из Retailcrm в магазин (подробнее смотрите в описании).
|
||||
|
||||
== Changelog ==
|
||||
= 3.6.2 =
|
||||
* Исправлена ошибка, которая приводила к дублированию некоторых клиентов
|
||||
|
||||
= 3.6.1 =
|
||||
* Исправлена ошибка генерации каталога товаров
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Version: 3.6.1
|
||||
* Version: 3.6.2
|
||||
* WC requires at least: 3.0
|
||||
* WC tested up to: 3.9.3
|
||||
* Plugin Name: WooCommerce retailCRM
|
||||
|
@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* @link https://wordpress.org/plugins/woo-retailcrm/
|
||||
* @version 3.6.1
|
||||
* @version 3.6.2
|
||||
*
|
||||
* @package RetailCRM
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user