Delete deprecated API V4. Refactoring API V5 and history getting method
This commit is contained in:
parent
9113a89cd2
commit
4a68135e33
@ -1,3 +1,10 @@
|
||||
## 2022-02-24 4.4.2
|
||||
* Delete deprecated API V4. Refactoring API V5 and history getting method
|
||||
* Fix bug with use xmlId
|
||||
* Add order number transfer CMS -> CRM by history
|
||||
* Add documentation for registering client functionality
|
||||
* Delete legacy code for update customer name and surname
|
||||
|
||||
## 2022-01-17 4.4.1
|
||||
* Added functionality to skip some orders statuses
|
||||
* Improved the create/update method when registering customers
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -18,7 +18,7 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
|
||||
class WC_Retailcrm_Base extends WC_Retailcrm_Abstracts_Settings
|
||||
{
|
||||
/** @var \WC_Retailcrm_Proxy|WC_Retailcrm_Client_V4|WC_Retailcrm_Client_V5|bool */
|
||||
/** @var WC_Retailcrm_Proxy|WC_Retailcrm_Client_V5|bool */
|
||||
protected $apiClient;
|
||||
|
||||
/** @var \WC_Retailcrm_Customers */
|
||||
@ -33,7 +33,7 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
/**
|
||||
* Init and hook in the integration.
|
||||
*
|
||||
* @param \WC_Retailcrm_Proxy|WC_Retailcrm_Client_V4|WC_Retailcrm_Client_V5|bool $retailcrm (default = false)
|
||||
* @param WC_Retailcrm_Proxy|WC_Retailcrm_Client_V5|bool $retailcrm (default = false)
|
||||
*/
|
||||
public function __construct($retailcrm = false)
|
||||
{
|
||||
@ -631,7 +631,7 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
/**
|
||||
* Get retailcrm api client
|
||||
*
|
||||
* @return bool|WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V4|\WC_Retailcrm_Client_V5
|
||||
* @return bool|WC_Retailcrm_Proxy
|
||||
*/
|
||||
public function getApiClient()
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ if (!class_exists('WC_Retailcrm_History')) :
|
||||
/** @var array|mixed|void */
|
||||
protected $retailcrmSettings;
|
||||
|
||||
/** @var bool|\WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V4|\WC_Retailcrm_Client_V5 */
|
||||
/** @var bool|WC_Retailcrm_Proxy|WC_Retailcrm_Client_V5 */
|
||||
protected $retailcrm;
|
||||
|
||||
/** @var array|mixed */
|
||||
@ -35,7 +35,7 @@ if (!class_exists('WC_Retailcrm_History')) :
|
||||
/**
|
||||
* WC_Retailcrm_History constructor.
|
||||
*
|
||||
* @param \WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V4|\WC_Retailcrm_Client_V5|bool $retailcrm (default = false)
|
||||
* @param WC_Retailcrm_Proxy|WC_Retailcrm_Client_V5|bool $retailcrm (default = false)
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
@ -92,7 +92,6 @@ if (!class_exists('WC_Retailcrm_History')) :
|
||||
protected function customersHistory()
|
||||
{
|
||||
$sinceId = get_option('retailcrm_customers_history_since_id');
|
||||
$request = new WC_Retailcrm_Paginated_Request();
|
||||
$pagination = 1;
|
||||
|
||||
$filter = !empty($sinceId)
|
||||
@ -100,13 +99,9 @@ if (!class_exists('WC_Retailcrm_History')) :
|
||||
: ['startDate' => $this->startDate->format('Y-m-d H:i:s')];
|
||||
|
||||
do {
|
||||
$history = $request
|
||||
->reset()
|
||||
->setApi($this->retailcrm)
|
||||
->setMethod('customersHistory')
|
||||
->setParams([$filter])
|
||||
->execute()
|
||||
->getData();
|
||||
$historyResponse = $this->retailcrm->customersHistory($filter);
|
||||
|
||||
$history = $this->getHistoryData($historyResponse);
|
||||
|
||||
if (!empty($history)) {
|
||||
$builder = new WC_Retailcrm_WC_Customer_Builder();
|
||||
@ -195,7 +190,6 @@ if (!class_exists('WC_Retailcrm_History')) :
|
||||
{
|
||||
$options = array_flip(array_filter($this->retailcrmSettings));
|
||||
$sinceId = get_option('retailcrm_orders_history_since_id');
|
||||
$request = new WC_Retailcrm_Paginated_Request();
|
||||
$pagination = 1;
|
||||
|
||||
$filter = !empty($sinceId)
|
||||
@ -203,13 +197,9 @@ if (!class_exists('WC_Retailcrm_History')) :
|
||||
: ['startDate' => $this->startDate->format('Y-m-d H:i:s')];
|
||||
|
||||
do {
|
||||
$history = $request
|
||||
->reset()
|
||||
->setApi($this->retailcrm)
|
||||
->setMethod('ordersHistory')
|
||||
->setParams([$filter])
|
||||
->execute()
|
||||
->getData();
|
||||
$historyResponse = $this->retailcrm->OrdersHistory($filter);
|
||||
|
||||
$history = $this->getHistoryData($historyResponse);
|
||||
|
||||
if (!empty($history)) {
|
||||
$lastChange = end($history);
|
||||
@ -1295,6 +1285,25 @@ if (!class_exists('WC_Retailcrm_History')) :
|
||||
|
||||
return isset($arr[$key]) ? $arr[$key] : $def;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get history data.
|
||||
*
|
||||
* @param $historyResponse
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getHistoryData($historyResponse)
|
||||
{
|
||||
if (!$historyResponse->isSuccessful() || empty($historyResponse['history'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
time_nanosleep(0, 300000000);
|
||||
|
||||
return $historyResponse['history'];
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
@ -14,7 +14,7 @@
|
||||
if (!class_exists('WC_Retailcrm_Orders')) :
|
||||
class WC_Retailcrm_Orders
|
||||
{
|
||||
/** @var bool|WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V5|\WC_Retailcrm_Client_V4 */
|
||||
/** @var bool|WC_Retailcrm_Proxy|WC_Retailcrm_Client_V5 */
|
||||
protected $retailcrm;
|
||||
|
||||
/** @var array */
|
||||
|
@ -115,15 +115,14 @@ class WC_Retailcrm_Plugin
|
||||
/**
|
||||
* Edit configuration in CRM
|
||||
*
|
||||
* @param WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V4|\WC_Retailcrm_Client_V5 $api_client
|
||||
* @param WC_Retailcrm_Proxy|WC_Retailcrm_Client_V5 $api_client
|
||||
* @param string $client_id
|
||||
* @param bool $active
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function integration_module($api_client, $client_id, $active = true)
|
||||
{
|
||||
|
||||
if (!$api_client instanceof WC_Retailcrm_Proxy) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1,121 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP version 5.6
|
||||
*
|
||||
* Class WC_Retailcrm_Paginated_Request - It will merge request with pagination data into one big monstrous array.
|
||||
* Use with caution, it can cause problems with very large data sets (due to memory exhaustion, obviously).
|
||||
*
|
||||
* @category Integration
|
||||
* @author RetailCRM <integration@retailcrm.ru>
|
||||
* @license http://retailcrm.ru Proprietary
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://help.retailcrm.ru
|
||||
*/
|
||||
class WC_Retailcrm_Paginated_Request
|
||||
{
|
||||
/**
|
||||
* @var \WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V5
|
||||
*/
|
||||
private $api;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $method;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $params;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* Sets retailCRM api client to request
|
||||
*
|
||||
* @param \WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V5 $api
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setApi($api)
|
||||
{
|
||||
$this->api = $api;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets API client method to request
|
||||
*
|
||||
* @param string $method
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets method params for API client.
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setParams($params)
|
||||
{
|
||||
$this->params = $params;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes request
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$response = call_user_func_array(
|
||||
[$this->api, $this->method],
|
||||
$this->params
|
||||
);
|
||||
|
||||
if ($response->isSuccessful() && !empty($response['history'])) {
|
||||
$this->data = array_merge($this->data, $response['history']);
|
||||
}
|
||||
|
||||
time_nanosleep(0, 300000000);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset paginated request
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
$this->data = [];
|
||||
$this->method = '';
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -4,8 +4,8 @@ Donate link: https://www.simla.com
|
||||
Tags: Интеграция, Simla.com, simla
|
||||
Requires PHP: 5.6
|
||||
Requires at least: 5.3
|
||||
Tested up to: 5.8
|
||||
Stable tag: 4.4.1
|
||||
Tested up to: 5.9
|
||||
Stable tag: 4.4.2
|
||||
License: GPLv1 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-1.0.html
|
||||
|
||||
@ -82,6 +82,13 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i
|
||||
|
||||
|
||||
== Changelog ==
|
||||
= 4.4.2 =
|
||||
* Delete deprecated API V4. Refactoring API V5 and history getting method
|
||||
* Fix bug with use xmlId
|
||||
* Add order number transfer CMS -> CRM by history
|
||||
* Add documentation for registering client functionality
|
||||
* Delete legacy code for update customer name and surname
|
||||
|
||||
= 4.4.1 =
|
||||
* Added functionality to skip some orders statuses
|
||||
* Improved the create/update method when registering customers
|
||||
|
@ -5,10 +5,10 @@
|
||||
* Description: Integration plugin for WooCommerce & Simla.com
|
||||
* Author: RetailDriver LLC
|
||||
* Author URI: http://retailcrm.pro/
|
||||
* Version: 4.4.1
|
||||
* Tested up to: 5.8
|
||||
* Version: 4.4.2
|
||||
* Tested up to: 5.9
|
||||
* WC requires at least: 5.4
|
||||
* WC tested up to: 5.8
|
||||
* WC tested up to: 6.2
|
||||
* Text Domain: retailcrm
|
||||
*/
|
||||
|
||||
@ -104,7 +104,6 @@ if (!class_exists( 'WC_Integration_Retailcrm')) :
|
||||
require_once(self::checkCustomFile('include/models/class-wc-retailcrm-customer-switcher-result.php'));
|
||||
require_once(self::checkCustomFile('include/components/class-wc-retailcrm-logger.php'));
|
||||
require_once(self::checkCustomFile('include/components/class-wc-retailcrm-history-assembler.php'));
|
||||
require_once(self::checkCustomFile('include/components/class-wc-retailcrm-paginated-request.php'));
|
||||
require_once(self::checkCustomFile('include/components/class-wc-retailcrm-customer-switcher.php'));
|
||||
require_once(self::checkCustomFile('include/abstracts/class-wc-retailcrm-abstract-builder.php'));
|
||||
require_once(self::checkCustomFile('include/abstracts/class-wc-retailcrm-abstracts-settings.php'));
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @link https://wordpress.org/plugins/woo-retailcrm/
|
||||
*
|
||||
* @version 4.4.1
|
||||
* @version 4.4.2
|
||||
*
|
||||
* @package RetailCRM
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user