1
0
mirror of synced 2025-02-06 18:19:24 +03:00

fixed customer transmission

This commit is contained in:
Дмитрий 2019-08-27 15:14:34 +03:00
parent db56c05725
commit 1b2f0d053a
2 changed files with 30 additions and 23 deletions

View File

@ -172,8 +172,8 @@ if (!class_exists('WC_Retailcrm_Customers')) :
*/ */
public function searchCustomer($filter) public function searchCustomer($filter)
{ {
if (isset($filter['id'])) { if (isset($filter['externalId'])) {
$search = $this->retailcrm->customersGet($filter['id']); $search = $this->retailcrm->customersGet($filter['externalId']);
} elseif (isset($filter['email'])) { } elseif (isset($filter['email'])) {
$search = $this->retailcrm->customersList(array('email' => $filter['email'])); $search = $this->retailcrm->customersList(array('email' => $filter['email']));
} }

View File

@ -125,38 +125,45 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
return null; return null;
} }
$order = wc_get_order($order_id); $wcOrder = wc_get_order($order_id);
$this->processOrder($order); $this->processOrder($wcOrder);
$customer = $order->get_user(); $wpUser = $wcOrder->get_user();
if ($customer != false) { if ($wpUser instanceof WP_User) {
$search = $this->customers->searchCustomer(array('id' => $customer->get('ID'))); $wpUserId = (int)$wpUser->get('ID');
$foundCustomer = $this->customers->searchCustomer(array(
'externalId' => $wpUserId
));
if (!$search) { if (empty($foundCustomer)) {
$this->customers->createCustomer($customer); $customerId = $this->customers->createCustomer($wpUserId);
} else {
$this->order['customer']['externalId'] = $search['externalId'];
}
} else {
$search = $this->customers->searchCustomer(array('email' => $order->get_billing_email()));
if (!$search) { if (!empty($customerId)) {
$new_customer = $this->customers->buildCustomerFromOrderData($order); $this->order['customer']['id'] = $customerId;
$id = $this->customers->createCustomer($new_customer);
if ($id !== null) {
$this->order['customer']['id'] = $id;
} }
} else { } else {
$this->order['customer']['externalId'] = $search['externalId']; $this->order['customer']['externalId'] = $foundCustomer['externalId'];
} }
} else {
$foundCustomer = $this->customers->searchCustomer(array(
'email' => $wcOrder->get_billing_email()
));
unset($new_customer); if (empty($foundCustomer)) {
$wcCustomer = $this->customers->buildCustomerFromOrderData($wcOrder);
$customerId = $this->customers->createCustomer($wcCustomer);
if (!empty($customerId)) {
$this->order['customer']['id'] = $customerId;
}
} else {
$this->order['customer']['externalId'] = $foundCustomer['externalId'];
}
} }
$this->retailcrm->ordersCreate($this->order); $this->retailcrm->ordersCreate($this->order);
return $order; return $wcOrder;
} }
/** /**