1
0
mirror of synced 2025-02-07 02:29:23 +03:00

Optimization of order unloading (#359)

This commit is contained in:
Kocmonavtik 2025-02-06 10:14:39 +03:00 committed by GitHub
parent cd57de01e6
commit bce545979c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 79 additions and 18 deletions

View File

@ -1,3 +1,6 @@
## 2025-02-04 4.8.19
* Optimization of order unloading
## 2025-02-03 4.8.18
* Added additional parameters to GET requests

View File

@ -1 +1 @@
4.8.18
4.8.19

View File

@ -602,6 +602,32 @@ if (!class_exists('WC_Retailcrm_Orders')) :
);
}
public function processOrderForUpload($orderIds)
{
$ordersForUpload = [];
$errorOrders = [];
foreach ($orderIds as $orderId) {
try {
$this->order = [];
$this->processOrder(wc_get_order($orderId));
if ($this->order === []) {
throw new \RuntimeException(sprintf('Order %s is not uploaded', $orderId));
}
$ordersForUpload[] = $this->order;
} catch (Throwable $exception) {
$errorOrders[$orderId] = sprintf(
'Exception for Order [%s]: %s. Trace: %s',
$orderId, $exception->getMessage(), $exception->getTraceAsString()
);
}
}
return [$ordersForUpload, $errorOrders];
}
/**
* Send payment in CRM
*

View File

@ -83,14 +83,11 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
*/
public function uploadArchiveOrders(?int $page, array $ids = [])
{
WC_Retailcrm_Logger::info(__METHOD__, 'Archive order IDs: ' . implode(', ', $ids));
if (!$this->retailcrm instanceof WC_Retailcrm_Proxy) {
return null;
}
$orderIds = [];
$uploadErrors = [];
if (null !== $page) {
$orderIds = $this->getCmsOrders($page);
@ -98,14 +95,40 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
$orderIds = $ids;
}
if ($orderIds !== []) {
foreach ($orderIds as $orderId) {
$errorMessage = $this->orders->orderCreate($orderId);
if ($orderIds === []) {
return null;
}
if (is_string($errorMessage)) {
$uploadErrors[$orderId] = $errorMessage;
}
WC_Retailcrm_Logger::info(__METHOD__, 'Archive order IDs: ' . implode(', ', $ids));
[$ordersForUpload, $uploadErrors] = $this->orders->processOrderForUpload($orderIds);
try {
$response = $this->retailcrm->ordersUpload($ordersForUpload);
if (!$response->isSuccessful()) {
throw new RuntimeException(
sprintf(
'Failure to upload orders: %s. Status code: %s',
$response->getErrorString(),
$response->getStatusCode()
)
);
}
} catch (Exception $exception) {
WC_Retailcrm_Logger::error(
__METHOD__,
sprintf("Error while uploading orders: %s", $exception->getMessage())
);
return null;
}
/** WP version >= 6 */
if (function_exists('wp_cache_flush_runtime')) {
wp_cache_flush_runtime();
} else {
wp_cache_flush();
}
$this->logOrdersUploadErrors($uploadErrors);
@ -225,7 +248,7 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
*/
private function logOrdersUploadErrors($errors)
{
if (empty($errors) === true) {
if ($errors === []) {
return;
}

View File

@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla
Requires PHP: 7.1
Requires at least: 5.3
Tested up to: 6.5
Stable tag: 4.8.18
Stable tag: 4.8.19
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.8.19 =
* Optimization of order unloading
= 4.8.18 =
* Added additional parameters to GET requests

View File

@ -5,7 +5,7 @@
* Description: Integration plugin for WooCommerce & Simla.com
* Author: RetailDriver LLC
* Author URI: http://retailcrm.pro/
* Version: 4.8.18
* Version: 4.8.19
* Tested up to: 6.5
* Requires Plugins: woocommerce
* WC requires at least: 5.4
@ -27,7 +27,7 @@ if (!class_exists( 'WC_Integration_Retailcrm')) :
class WC_Integration_Retailcrm {
const WOOCOMMERCE_SLUG = 'woocommerce';
const WOOCOMMERCE_PLUGIN_PATH = 'woocommerce/woocommerce.php';
const MODULE_VERSION = '4.8.18';
const MODULE_VERSION = '4.8.19';
private static $instance;

View File

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

View File

@ -36,7 +36,8 @@ class WC_Retailcrm_Uploader_Test extends WC_Retailcrm_Test_Case_Helper
'getCountOrders',
'customersGet',
'customersList',
'ordersCreate'
'ordersCreate',
'ordersUpload',
))
->getMock();
@ -96,10 +97,10 @@ class WC_Retailcrm_Uploader_Test extends WC_Retailcrm_Test_Case_Helper
* @param $retailcrm
* @dataProvider dataProviderApiClient
*/
public function test_upload_selected_orders()
public function test_upload_selected_orders($retailcrm)
{
$_GET['order_ids_retailcrm'] = '123, 345, 456';
$retailcrm_uploader = $this->getRetailcrmUploader($this->apiMock);
$retailcrm_uploader = $this->getRetailcrmUploader($retailcrm);
$uploadSelectedOrders = $retailcrm_uploader->uploadSelectedOrders();
$this->assertEquals(null, $uploadSelectedOrders);
@ -123,6 +124,11 @@ class WC_Retailcrm_Uploader_Test extends WC_Retailcrm_Test_Case_Helper
public function dataProviderApiClient()
{
$this->setUp();
$this->apiMock
->expects($this->any())
->method('ordersUpload')
->willReturn(new WC_Retailcrm_Response(200, ''))
;
return array(
array(