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

fix error with client duplication

This commit is contained in:
Pavel 2020-04-13 15:58:56 +03:00
parent 45bbd5dd81
commit 1481edae95
8 changed files with 49 additions and 12 deletions

View File

@ -1,3 +1,6 @@
## 2020-04-13 3.6.2
* Исправлена ошибка, которая приводила к дублированию некоторых клиентов
## 2019-03-31 3.6.1
* Исправлена ошибка генерации каталога товаров

View File

@ -1 +1 @@
3.6.1
3.6.2

View File

@ -230,7 +230,11 @@ if (!class_exists('WC_Retailcrm_Base')) {
/**
* Create customer in retailCRM
*
* @param int $customer_id
*
* @return void
* @throws \Exception
*/
public function create_customer($customer_id)
{
@ -238,6 +242,19 @@ if (!class_exists('WC_Retailcrm_Base')) {
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()
{

View File

@ -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()
);

View File

@ -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 {
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 {
if (!empty($foundCustomer['externalId'])) {
$this->order['customer']['externalId'] = $foundCustomer['externalId'];
} else {
$this->order['customer']['id'] = $foundCustomer['id'];
}
}
}

View File

@ -45,6 +45,9 @@ API-ключ должен быть для отдельного магазина
2. В появившихся списках справочников настройте соответствие способов доставки и оплаты, а так же статусов заказов. Отметьте галочку "Выгружать остатки", если хотите выгружать остатки из Retailcrm в магазин (подробнее смотрите в описании).
== Changelog ==
= 3.6.2 =
* Исправлена ошибка, которая приводила к дублированию некоторых клиентов
= 3.6.1 =
* Исправлена ошибка генерации каталога товаров

View File

@ -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

View File

@ -15,7 +15,7 @@
*
*
* @link https://wordpress.org/plugins/woo-retailcrm/
* @version 3.6.1
* @version 3.6.2
*
* @package RetailCRM
*/