merge fixes
This commit is contained in:
parent
0560967fdb
commit
35376c40fc
9 changed files with 18 additions and 311 deletions
|
@ -1,4 +1,3 @@
|
|||
<<<<<<< HEAD
|
||||
## 2020-06-18 4.0.0
|
||||
* Поддержка корпоративных клиентов
|
||||
* Поддержка изменения покупателя в заказе
|
||||
|
|
|
@ -558,45 +558,6 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
|
|||
}
|
||||
|
||||
/**
|
||||
<<<<<<< HEAD
|
||||
* Validate API version
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validate_api_version_field($key, $value)
|
||||
{
|
||||
$post = $this->get_post_data();
|
||||
|
||||
$versionMap = array(
|
||||
'v4' => '4.0',
|
||||
'v5' => '5.0'
|
||||
);
|
||||
|
||||
$api = new WC_Retailcrm_Proxy(
|
||||
$post[$this->plugin_id . $this->id . '_api_url'],
|
||||
$post[$this->plugin_id . $this->id . '_api_key'],
|
||||
null,
|
||||
$this->get_option('corporate_enabled', 'no') === 'yes'
|
||||
);
|
||||
|
||||
$response = $api->apiVersions();
|
||||
|
||||
if (!empty($response) && $response->isSuccessful()) {
|
||||
if (!in_array($versionMap[$value], $response['versions'])) {
|
||||
WC_Admin_Settings::add_error( esc_html__( 'The selected API version is unavailable', 'retailcrm' ) );
|
||||
$value = '';
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
=======
|
||||
>>>>>>> Dropped v4, fixes for several bugs, tests.
|
||||
* Validate API url
|
||||
*
|
||||
* @param string $key
|
||||
|
@ -646,7 +607,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
|
|||
$value = '';
|
||||
}
|
||||
|
||||
if (!$response->isSuccessful()) {
|
||||
if (empty($response) || !$response->isSuccessful()) {
|
||||
WC_Admin_Settings::add_error( esc_html__( 'Enter the correct API key', 'retailcrm' ) );
|
||||
$value = '';
|
||||
}
|
||||
|
|
|
@ -85,6 +85,11 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) :
|
|||
return $response;
|
||||
}
|
||||
|
||||
if (empty($response)) {
|
||||
WC_Retailcrm_Logger::add(sprintf("[%s] null (no response whatsoever)", $called));
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
// Don't print long lists in debug logs (errors while calling this will be easy to detect anyway)
|
||||
// Also don't call useless array_map at all while debug mode is off.
|
||||
|
|
|
@ -279,23 +279,6 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
|||
return;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
$client = $this->getApiClient();
|
||||
|
||||
if (empty($client)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$wcCustomer = new WC_Customer($customer_id);
|
||||
$response = $client->customersList(array('email' => $wcCustomer->get_billing_email()));
|
||||
|
||||
if ((!empty($response) && $response->isSuccessful()) && isset($response['customers']) && count($response['customers']) > 0) {
|
||||
return;
|
||||
}
|
||||
=======
|
||||
=======
|
||||
>>>>>>> restore correct merge state
|
||||
$client = $this->getApiClient();
|
||||
|
||||
if (empty($client)) {
|
||||
|
@ -303,9 +286,13 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
|||
}
|
||||
|
||||
$wcCustomer = new WC_Customer($customer_id);
|
||||
$resp = $client->customersList(array('email' => $wcCustomer->get_billing_email()));
|
||||
$response = $client->customersList(array('email' => $wcCustomer->get_billing_email()));
|
||||
|
||||
if ($resp && $resp->isSuccessful() && isset($resp['customers']) && count($resp['customers']) > 0) {
|
||||
if (!empty($response)
|
||||
&& $response->isSuccessful()
|
||||
&& isset($response['customers'])
|
||||
&& count($response['customers']) > 0
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -460,13 +460,9 @@ if (!class_exists('WC_Retailcrm_Customers')) :
|
|||
$search = $this->retailcrm->customersList(array('email' => $filter['email']));
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
if (!empty($search) && $search->isSuccessful()) {
|
||||
=======
|
||||
if (isset($search) && $search->isSuccessful()) {
|
||||
$customer = false;
|
||||
|
||||
>>>>>>> fix customer squashing
|
||||
if (isset($search['customers'])) {
|
||||
if (empty($search['customers'])) {
|
||||
return false;
|
||||
|
@ -527,7 +523,7 @@ if (!class_exists('WC_Retailcrm_Customers')) :
|
|||
{
|
||||
$search = $this->retailcrm->customersCorporateList($filter);
|
||||
|
||||
if (isset($search) && $search->isSuccessful()) {
|
||||
if (!empty($search) && $search->isSuccessful()) {
|
||||
if (isset($search['customersCorporate'])) {
|
||||
if (empty($search['customersCorporate'])) {
|
||||
return false;
|
||||
|
|
|
@ -108,33 +108,6 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
|||
*/
|
||||
protected function customersHistory($date, $sinceId)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
if ($since_id) {
|
||||
$response = $this->retailcrm->customersHistory(array('sinceId' => $since_id));
|
||||
} else {
|
||||
$response = $this->retailcrm->customersHistory(array('startDate' => $date));
|
||||
}
|
||||
|
||||
if (!empty($response) && $response->isSuccessful()) {
|
||||
if (empty($response['history'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$history = $response['history'];
|
||||
$end_change = end($history);
|
||||
$new_since_id = $end_change['id'];
|
||||
|
||||
$mapping = array(
|
||||
'first_name' => 'first_name',
|
||||
'last_name' => 'last_name',
|
||||
'email' => 'billing_email',
|
||||
'phones' => 'billing_phone',
|
||||
'address.region' => 'billing_state',
|
||||
'address.index' => 'billing_postcode',
|
||||
'address.country' => 'billing_country',
|
||||
'address.city' => 'billing_city'
|
||||
);
|
||||
=======
|
||||
$filter = array('startDate' => $date);
|
||||
|
||||
if ($sinceId) {
|
||||
|
@ -156,15 +129,7 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
|||
$lastChange = end($history);
|
||||
$customers = WC_Retailcrm_History_Assembler::assemblyCustomer($history);
|
||||
WC_Retailcrm_Plugin::$history_run = true;
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> WIP: Change client in the order (not ready at this point; also tests should fail)
|
||||
=======
|
||||
WC_Retailcrm_Logger::debug(__METHOD__, 'Assembled customers history:', $customers);
|
||||
>>>>>>> WIP: Logic for company replacement via component (which was surprisingly easy to implement)
|
||||
=======
|
||||
WC_Retailcrm_Logger::debug(__METHOD__, array('Assembled customers history:', $customers));
|
||||
>>>>>>> Compatibility fixes for php 5.3
|
||||
|
||||
foreach ($customers as $crmCustomer) {
|
||||
if (!isset($crmCustomer['externalId'])) {
|
||||
|
@ -228,12 +193,6 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
|||
$filter = array('sinceId' => $since_id);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
if (!empty($response) && $response->isSuccessful()) {
|
||||
if (empty($response['history'])) {
|
||||
return false;
|
||||
}
|
||||
=======
|
||||
$request = new WC_Retailcrm_Paginated_Request();
|
||||
$history = $request
|
||||
->setApi($this->retailcrm)
|
||||
|
@ -243,7 +202,6 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
|||
->setLimit(100)
|
||||
->execute()
|
||||
->getData();
|
||||
>>>>>>> WIP: Change client in the order (not ready at this point; also tests should fail)
|
||||
|
||||
if (!empty($history)) {
|
||||
$last_change = end($history);
|
||||
|
@ -367,10 +325,7 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
|||
* @param array $options
|
||||
*
|
||||
* @return bool
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
* @throws \Exception
|
||||
>>>>>>> fixes for possible crashes
|
||||
* @throws \WC_Data_Exception
|
||||
*/
|
||||
protected function orderUpdate($order, $options)
|
||||
|
@ -401,32 +356,6 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
|||
$wc_order->set_shipping_last_name($order['lastName']);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> sync phone via history
|
||||
if (isset($order['phone'])) {
|
||||
$wc_order->set_billing_phone($order['phone']);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
if (isset($order['email'])) {
|
||||
$wc_order->set_billing_email($order['email']);
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> fixes & more fields for sync
|
||||
=======
|
||||
|
||||
=======
|
||||
=======
|
||||
>>>>>>> sync phone via history
|
||||
$this->handleCustomerDataChange($wc_order, $order);
|
||||
>>>>>>> Fixes, customer change logic for legal entities & individual persons (contact person will be used in the second case)
|
||||
=======
|
||||
if (!$this->handleCustomerDataChange($wc_order, $order)) {
|
||||
if (isset($order['phone'])) {
|
||||
$wc_order->set_billing_phone($order['phone']);
|
||||
|
@ -436,9 +365,7 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
|||
$wc_order->set_billing_email($order['email']);
|
||||
}
|
||||
}
|
||||
>>>>>>> don't break customer change with sync
|
||||
|
||||
>>>>>>> WIP: Logic for company replacement via component (which was surprisingly easy to implement)
|
||||
if (array_key_exists('items', $order)) {
|
||||
foreach ($order['items'] as $key => $item) {
|
||||
if (!isset($item['offer'][$this->bind_field])) {
|
||||
|
@ -846,7 +773,7 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
|||
if (empty($crmOrder)) {
|
||||
$result = $this->retailcrm->ordersGet($order['id'], 'id');
|
||||
|
||||
if ($result->isSuccessful()) {
|
||||
if (!empty($result) && $result->isSuccessful()) {
|
||||
$crmOrder = $result['order'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,120 +130,6 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
|||
|
||||
$wcOrder = wc_get_order($order_id);
|
||||
$this->processOrder($wcOrder);
|
||||
<<<<<<< HEAD
|
||||
$wpUser = $wcOrder->get_user();
|
||||
|
||||
if ($wpUser instanceof WP_User) {
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
$wpUserId = (int)$wpUser->get('ID');
|
||||
$wooCustomer = new WC_Customer($wpUserId);
|
||||
|
||||
<<<<<<< HEAD
|
||||
if (empty($foundCustomer)) {
|
||||
$foundCustomer = $this->customers->searchCustomer(array(
|
||||
'email' => $wcOrder->get_billing_email()
|
||||
));
|
||||
}
|
||||
|
||||
if (empty($foundCustomer)) {
|
||||
$customerId = $this->customers->createCustomer($wpUserId);
|
||||
=======
|
||||
if ($isCorporateEnabled && WC_Retailcrm_Customers::customerPossiblyCorporate($wooCustomer)) {
|
||||
$foundRegularCustomer = $this->customers->searchCustomer(array(
|
||||
'externalId' => $wpUserId
|
||||
));
|
||||
>>>>>>> WIP: corporate customers support
|
||||
|
||||
// If regular customer was found - create order with it.
|
||||
if (!empty($foundRegularCustomer)) {
|
||||
return $this->orderCreate($order_id, true);
|
||||
}
|
||||
|
||||
$foundCustomer = $this->customers->searchCorporateCustomer(array(
|
||||
'externalId' => $wpUserId
|
||||
));
|
||||
|
||||
if (empty($foundCustomer)) {
|
||||
$customerData = $this->customers->createCorporateCustomer($wpUserId);
|
||||
|
||||
if ($customerData instanceof WC_Retailcrm_Customer_Corporate_Response) {
|
||||
if (!empty($customerData->getId())) {
|
||||
$this->order['customer']['id'] = $customerData->getId();
|
||||
}
|
||||
|
||||
if (!empty($customerData->getContactId())) {
|
||||
$this->order['contact']['id'] = $customerData->getContactId();
|
||||
}
|
||||
|
||||
if (!empty($customerData->getContactExternalId())) {
|
||||
$this->order['contact']['externalId'] = $customerData->getContactExternalId();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->order['customer']['externalId'] = $foundCustomer['externalId'];
|
||||
|
||||
if (isset($foundCustomer['mainCustomerContact']['customer']['id'])) {
|
||||
$this->order['contact']['id'] = $foundCustomer['mainCustomerContact']['customer']['id'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
<<<<<<< HEAD
|
||||
if (!empty($foundCustomer['externalId'])) {
|
||||
$this->order['customer']['externalId'] = $foundCustomer['externalId'];
|
||||
} else {
|
||||
$this->order['customer']['id'] = $foundCustomer['id'];
|
||||
}
|
||||
=======
|
||||
$foundCustomer = $this->customers->searchCustomer(array(
|
||||
'externalId' => $wpUserId
|
||||
));
|
||||
|
||||
if (empty($foundCustomer)) {
|
||||
$customerId = $this->customers->createRegularCustomer($wpUserId);
|
||||
|
||||
if (!empty($customerId)) {
|
||||
$this->order['customer']['id'] = $customerId;
|
||||
}
|
||||
} else {
|
||||
$this->order['customer']['externalId'] = $foundCustomer['externalId'];
|
||||
}
|
||||
>>>>>>> WIP: corporate customers support
|
||||
}
|
||||
=======
|
||||
=======
|
||||
=======
|
||||
>>>>>>> restore correct merge state
|
||||
if (!WC_Retailcrm_Customers::isCustomer($wpUser)) {
|
||||
return $wcOrder;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> corporate customers alternative logic
|
||||
>>>>>>> corporate customers alternative logic
|
||||
$wpUserId = (int) $wpUser->get('ID');
|
||||
<<<<<<< HEAD
|
||||
$this->fillOrderCreate($wpUserId, $wpUser->get('email'), $wcOrder);
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> WIP: different (better) logic for corporate clients, fix for possible problem with identifiers
|
||||
=======
|
||||
$this->fillOrderCreate($wpUserId, $wpUser->get('billing_email'), $wcOrder);
|
||||
>>>>>>> merge changes
|
||||
>>>>>>> merge changes
|
||||
=======
|
||||
$wpUserId = (int) $wpUser->get('ID');
|
||||
$this->fillOrderCreate($wpUserId, $wpUser->get('billing_email'), $wcOrder);
|
||||
>>>>>>> restore correct merge state
|
||||
} else {
|
||||
$wcCustomer = $this->customers->buildCustomerFromOrderData($wcOrder);
|
||||
$this->fillOrderCreate(0, $wcCustomer->get_billing_email(), $wcOrder);
|
||||
}
|
||||
=======
|
||||
>>>>>>> company fix for corporate clients implementation & pass client change from cms to retailCRM
|
||||
|
||||
try {
|
||||
$response = $this->retailcrm->ordersCreate($this->order);
|
||||
|
@ -359,52 +245,12 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
|||
);
|
||||
$this->order['customer']['id'] = $corporateId;
|
||||
} else {
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
if (!empty($foundCustomer['externalId'])) {
|
||||
$this->order['customer']['externalId'] = $foundCustomer['externalId'];
|
||||
} else {
|
||||
$this->order['customer']['id'] = $foundCustomer['id'];
|
||||
}
|
||||
=======
|
||||
>>>>>>> new address logic & fixes
|
||||
$foundCustomer = $this->customers->searchCustomer(array(
|
||||
'email' => $wcOrder->get_billing_email()
|
||||
));
|
||||
|
||||
if (empty($foundCustomer)) {
|
||||
$customerId = $this->customers->createRegularCustomer($wcCustomer);
|
||||
|
||||
if (!empty($customerId)) {
|
||||
$this->order['customer']['id'] = $customerId;
|
||||
}
|
||||
} else {
|
||||
$this->order['customer']['externalId'] = $foundCustomer['externalId'];
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> WIP: corporate customers support
|
||||
=======
|
||||
=======
|
||||
=======
|
||||
>>>>>>> restore correct merge state
|
||||
$this->customers->fillCorporateAddress(
|
||||
$crmCorporate['id'],
|
||||
new WC_Customer($wcCustomerId),
|
||||
$wcOrder
|
||||
);
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> new address logic & fixes
|
||||
>>>>>>> new address logic & fixes
|
||||
$this->order['customer']['id'] = $crmCorporate['id'];
|
||||
|
||||
=======
|
||||
$this->order['customer']['id'] = $crmCorporate['id'];
|
||||
>>>>>>> restore correct merge state
|
||||
}
|
||||
|
||||
$companiesResponse = $this->retailcrm->customersCorporateCompanies(
|
||||
|
@ -450,16 +296,8 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
|||
|
||||
$response = $this->retailcrm->ordersEdit($this->order);
|
||||
|
||||
<<<<<<< HEAD
|
||||
if ((!empty($response) && $response->isSuccessful()) && $this->retailcrm_settings['api_version'] == 'v5') {
|
||||
=======
|
||||
if ($response->isSuccessful()) {
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> Dropped v4, fixes for several bugs, tests.
|
||||
$this->payment = $this->orderUpdatePaymentType($order);
|
||||
=======
|
||||
if (!empty($response) && $response->isSuccessful()) {
|
||||
$this->payment = $this->orderUpdatePaymentType($wcOrder);
|
||||
>>>>>>> company fix for corporate clients implementation & pass client change from cms to retailCRM
|
||||
}
|
||||
|
||||
return $wcOrder;
|
||||
|
@ -478,14 +316,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
|||
return null;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
$response = $this->retailcrm->ordersGet($order->get_id());
|
||||
|
||||
if (!empty($response) && $response->isSuccessful()) {
|
||||
$retailcrmOrder = $response['order'];
|
||||
=======
|
||||
$retailcrmOrder = $this->getCrmOrder($order->get_id());
|
||||
>>>>>>> several fixes & environment variable which can be used to output logs to stdout in tests
|
||||
|
||||
if (!empty($retailcrmOrder)) {
|
||||
foreach ($retailcrmOrder['payments'] as $payment_data) {
|
||||
|
|
|
@ -184,4 +184,3 @@ class WC_Retailcrm_Plugin {
|
|||
return self::$history_run;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,13 +126,15 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper
|
|||
|
||||
/**
|
||||
* @param $retailcrm
|
||||
*
|
||||
* @dataProvider dataProviderApiClient
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function test_create_customer_empty_response($retailcrm)
|
||||
{
|
||||
$this->responseMock = null;
|
||||
$this->apiMock = null;
|
||||
|
||||
|
||||
$retailcrm_customer = $this->getRetailcrmCustomer($retailcrm);
|
||||
$id = $retailcrm_customer->createCustomer($this->customer->get_id());
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue