1
0
mirror of synced 2025-01-18 17:01:41 +03:00

ref #89481 The 'page' parameter has been removed from the history API methods (#302)

This commit is contained in:
Uryvskiy Dima 2023-04-25 11:59:57 +03:00 committed by GitHub
parent d3f298645d
commit 9a533b97dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 86 deletions

View File

@ -1,3 +1,6 @@
## 2022-04-25 4.6.1
* The algorithm for getting the history of orders and customers has been optimized
## 2022-03-17 4.6.0
* Added functionality of abandoned carts

View File

@ -1 +1 @@
4.6.0
4.6.1

View File

@ -245,23 +245,16 @@ class WC_Retailcrm_Client_V5
* Get corporate customers history
*
* @param array $filter
* @param int $page
* @param int $limit
*
* @return WC_Retailcrm_Response
*/
public function customersCorporateHistory(array $filter = [], int $page = 1, int $limit = 100)
public function customersCorporateHistory(array $filter = [], int $limit = 100)
{
$parameters = [
'page' => $page,
'limit' => $limit,
'filter' => $filter,
];
return $this->client->makeRequest(
'/customers-corporate/history',
WC_Retailcrm_Request::METHOD_GET,
$parameters
['limit' => $limit, 'filter' => $filter]
);
}
@ -1306,23 +1299,16 @@ class WC_Retailcrm_Client_V5
* Get orders history
*
* @param array $filter
* @param int $page
* @param int $limit
*
* @return WC_Retailcrm_Response
*/
public function ordersHistory(array $filter = [], int $page = 1, int $limit = 100)
public function ordersHistory(array $filter = [], int $limit = 100)
{
$parameters = [
'page' => $page,
'limit' => $limit,
'filter' => $filter,
];
return $this->client->makeRequest(
'/orders/history',
WC_Retailcrm_Request::METHOD_GET,
$parameters
['limit' => $limit, 'filter' => $filter]
);
}
@ -1625,23 +1611,16 @@ class WC_Retailcrm_Client_V5
* Get customers history
*
* @param array $filter
* @param int $page
* @param int $limit
*
* @return WC_Retailcrm_Response
*/
public function customersHistory(array $filter = [], int $page = 1, int $limit = 100)
public function customersHistory(array $filter = [], int $limit = 100)
{
$parameters = [
'page' => $page,
'limit' => $limit,
'filter' => $filter,
];
return $this->client->makeRequest(
'/customers/history',
WC_Retailcrm_Request::METHOD_GET,
$parameters
['limit' => $limit, 'filter' => $filter]
);
}
@ -1819,7 +1798,6 @@ class WC_Retailcrm_Client_V5
* Get orders assembly history
*
* @param array $filter (default: array())
* @param int $page (default: int)
* @param int $limit (default: null)
*
* @return WC_Retailcrm_Response
@ -1828,18 +1806,12 @@ class WC_Retailcrm_Client_V5
*
* @throws InvalidArgumentException
*/
public function ordersPacksHistory(array $filter = [], int $page = 1, int $limit = 100)
public function ordersPacksHistory(array $filter = [], int $limit = 100)
{
$parameters = [
'page' => $page,
'limit' => $limit,
'filter' => $filter,
];
return $this->client->makeRequest(
'/orders/packs/history',
WC_Retailcrm_Request::METHOD_GET,
$parameters
['limit' => $limit, 'filter' => $filter]
);
}

View File

@ -94,31 +94,22 @@ if (!class_exists('WC_Retailcrm_History')) :
*/
protected function customersHistory()
{
$sinceId = get_option('retailcrm_customers_history_since_id');
$pagination = 1;
$page = 1;
$sinceId = get_option('retailcrm_customers_history_since_id');
$filter = !empty($sinceId)
? ['sinceId' => $sinceId]
: ['startDate' => $this->startDate->format('Y-m-d H:i:s')];
do {
$historyResponse = $this->retailcrm->customersHistory($filter);
$isLastPage = $this->checkTotalPage($pagination, $historyResponse);
if ($isLastPage) {
break;
}
$history = $this->getHistoryData($historyResponse);
if (!empty($history)) {
$lastChange = end($history);
$filter['sinceId'] = $lastChange['id'];
update_option('retailcrm_customers_history_since_id', $lastChange['id']);
$filter['sinceId'] = $lastChange['id'];
WC_Retailcrm_Logger::debug(__METHOD__, [
'Processing customers history, ID:',
$filter['sinceId']
@ -197,8 +188,13 @@ if (!class_exists('WC_Retailcrm_History')) :
break;
}
$pagination++;
} while ($pagination !== self::PAGE_LIMIT);
$page++;
if ($page > self::PAGE_LIMIT) {
break;
}
} while ($historyResponse['pagination']['currentPage'] < $historyResponse['pagination']['totalPageCount']);
}
/**
@ -208,31 +204,23 @@ if (!class_exists('WC_Retailcrm_History')) :
*/
protected function ordersHistory()
{
$options = array_flip(array_filter($this->retailcrmSettings));
$sinceId = get_option('retailcrm_orders_history_since_id');
$pagination = 1;
$page = 1;
$options = array_flip(array_filter($this->retailcrmSettings));
$sinceId = get_option('retailcrm_orders_history_since_id');
$filter = !empty($sinceId)
? ['sinceId' => $sinceId]
: ['startDate' => $this->startDate->format('Y-m-d H:i:s')];
do {
$historyResponse = $this->retailcrm->OrdersHistory($filter);
$isLastPage = $this->checkTotalPage($pagination, $historyResponse);
if ($isLastPage) {
break;
}
$history = $this->getHistoryData($historyResponse);
if (!empty($history)) {
$lastChange = end($history);
$filter['sinceId'] = $lastChange['id'];
update_option('retailcrm_orders_history_since_id', $lastChange['id']);
$filter['sinceId'] = $lastChange['id'];
WC_Retailcrm_Logger::debug(__METHOD__, [
'Processing orders history, ID:',
$filter['sinceId']
@ -307,8 +295,11 @@ if (!class_exists('WC_Retailcrm_History')) :
break;
}
$pagination++;
} while ($pagination !== self::PAGE_LIMIT);
if ($page > self::PAGE_LIMIT) {
break;
}
} while ($historyResponse['pagination']['currentPage'] < $historyResponse['pagination']['totalPageCount']);
WC_Retailcrm_Plugin::$history_run = false;
@ -1449,7 +1440,12 @@ if (!class_exists('WC_Retailcrm_History')) :
*/
private function getHistoryData($historyResponse)
{
if (!$historyResponse->isSuccessful() || empty($historyResponse['history'])) {
if (
!$historyResponse instanceof WC_Retailcrm_Response
|| !$historyResponse->isSuccessful()
|| empty($historyResponse['history'])
|| empty($historyResponse['pagination'])
) {
return [];
}
@ -1457,23 +1453,6 @@ if (!class_exists('WC_Retailcrm_History')) :
return $historyResponse['history'];
}
/**
* @param int $currentPage
* @param WC_Retailcrm_Response $historyResponse Responce from CRM
*
* @return bool
*/
private function checkTotalPage($currentPage, $historyResponse): bool
{
$totalPageCount = $historyResponse['pagination']['totalPageCount'] ?? null;
if (empty($totalPageCount)) {
return true;
}
return $currentPage > $totalPageCount;
}
}
endif;

View File

@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla
Requires PHP: 7.0
Requires at least: 5.3
Tested up to: 6.0
Stable tag: 4.6.0
Stable tag: 4.6.1
License: GPLv1 or later
License URI: http://www.gnu.org/licenses/gpl-1.0.html
@ -82,6 +82,9 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i
== Changelog ==
= 4.6.1 =
* The algorithm for getting the history of orders and customers has been optimized
= 4.6.0 =
* Added functionality of abandoned carts

View File

@ -5,7 +5,7 @@
* Description: Integration plugin for WooCommerce & Simla.com
* Author: RetailDriver LLC
* Author URI: http://retailcrm.pro/
* Version: 4.6.0
* Version: 4.6.1
* Tested up to: 6.0
* WC requires at least: 5.4
* WC tested up to: 6.9

View File

@ -16,7 +16,7 @@
*
* @link https://wordpress.org/plugins/woo-retailcrm/
*
* @version 4.6.0
* @version 4.6.1
*
* @package RetailCRM
*/