1
0
Fork 0
mirror of synced 2025-04-11 05:00:54 +00:00

Compare commits

..

4 commits

Author SHA1 Message Date
ellynoize
4363cccc40
Bump version of module (#361)
Co-authored-by: ellynoize <a.kolesnikov@retailcrm.ru>
2025-02-19 13:09:06 +03:00
ellynoize
3610cec728
Add returned types for methods offsetExists, offsetSet, offsetUnset in WC_Retailcrm_Response (#360) 2025-02-19 12:31:06 +03:00
Kocmonavtik
bce545979c
Optimization of order unloading (#359) 2025-02-06 10:14:39 +03:00
Kocmonavtik
cd57de01e6
Added additional parameters to GET requests (#358) 2025-02-04 11:28:44 +03:00
11 changed files with 110 additions and 28 deletions

View file

@ -1,3 +1,15 @@
## 2025-02-19 4.8.21
* Fix version of module
## 2025-02-18 4.8.20
* Add returned types for methods offsetExists, offsetSet, offsetUnset in WC_Retailcrm_Response
## 2025-02-04 4.8.19
* Optimization of order unloading
## 2025-02-03 4.8.18
* Added additional parameters to GET requests
## 2025-01-21 4.8.17 ## 2025-01-21 4.8.17
* Fix deploy * Fix deploy

View file

@ -1 +1 @@
4.8.17 4.8.21

View file

@ -77,9 +77,10 @@ class WC_Retailcrm_Request
'cms_version' => function_exists('get_bloginfo') ? get_bloginfo('version') : '', 'cms_version' => function_exists('get_bloginfo') ? get_bloginfo('version') : '',
'woo_version' => WC()->version ?? '', 'woo_version' => WC()->version ?? '',
'php_version' => function_exists('phpversion') ? phpversion() : '', 'php_version' => function_exists('phpversion') ? phpversion() : '',
'module_version' => WC_Integration_Retailcrm::MODULE_VERSION, 'module_version' => WC_Integration_Retailcrm::MODULE_VERSION,
'ga_option_is_active' => getOptionByCode('ua') === WC_Retailcrm_Abstracts_Settings::YES,
]) ])
: $parameters = array_merge($this->defaultParameters, $parameters); : array_merge($this->defaultParameters, $parameters);
$url = $this->url . $path; $url = $this->url . $path;

View file

@ -120,9 +120,8 @@ class WC_Retailcrm_Response implements \ArrayAccess
* @param mixed $value value * @param mixed $value value
* *
* @throws \BadMethodCallException * @throws \BadMethodCallException
* @return void
*/ */
public function offsetSet($offset, $value) public function offsetSet($offset, $value): void
{ {
throw new \BadMethodCallException('This activity not allowed'); throw new \BadMethodCallException('This activity not allowed');
} }
@ -133,9 +132,8 @@ class WC_Retailcrm_Response implements \ArrayAccess
* @param mixed $offset offset * @param mixed $offset offset
* *
* @throws \BadMethodCallException * @throws \BadMethodCallException
* @return void
*/ */
public function offsetUnset($offset) public function offsetUnset($offset): void
{ {
throw new \BadMethodCallException('This call not allowed'); throw new \BadMethodCallException('This call not allowed');
} }
@ -145,9 +143,8 @@ class WC_Retailcrm_Response implements \ArrayAccess
* *
* @param mixed $offset offset * @param mixed $offset offset
* *
* @return bool
*/ */
public function offsetExists($offset) public function offsetExists($offset): bool
{ {
return isset($this->response[$offset]); return isset($this->response[$offset]);
} }
@ -156,10 +153,10 @@ class WC_Retailcrm_Response implements \ArrayAccess
* Get offset * Get offset
* *
* @param mixed $offset offset * @param mixed $offset offset
* * @return mixed
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* *
* @return mixed * TODO PHP < 8.0 не поддерживает тип mixed. Оператор | для перечисления типов также не поддерживается.
*/ */
public function offsetGet($offset) public function offsetGet($offset)
{ {

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 * Send payment in CRM
* *

View file

@ -83,14 +83,11 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
*/ */
public function uploadArchiveOrders(?int $page, array $ids = []) public function uploadArchiveOrders(?int $page, array $ids = [])
{ {
WC_Retailcrm_Logger::info(__METHOD__, 'Archive order IDs: ' . implode(', ', $ids));
if (!$this->retailcrm instanceof WC_Retailcrm_Proxy) { if (!$this->retailcrm instanceof WC_Retailcrm_Proxy) {
return null; return null;
} }
$orderIds = []; $orderIds = [];
$uploadErrors = [];
if (null !== $page) { if (null !== $page) {
$orderIds = $this->getCmsOrders($page); $orderIds = $this->getCmsOrders($page);
@ -98,14 +95,40 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
$orderIds = $ids; $orderIds = $ids;
} }
if ($orderIds !== []) { if ($orderIds === []) {
foreach ($orderIds as $orderId) { return null;
$errorMessage = $this->orders->orderCreate($orderId); }
if (is_string($errorMessage)) { WC_Retailcrm_Logger::info(__METHOD__, 'Archive order IDs: ' . implode(', ', $ids));
$uploadErrors[$orderId] = $errorMessage;
} [$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); $this->logOrdersUploadErrors($uploadErrors);
@ -225,7 +248,7 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
*/ */
private function logOrdersUploadErrors($errors) private function logOrdersUploadErrors($errors)
{ {
if (empty($errors) === true) { if ($errors === []) {
return; return;
} }

View file

@ -207,3 +207,8 @@ function isCorporateOrder($wcCustomer, $wcOrder)
{ {
return !empty($wcCustomer->get_billing_company()) || !empty($wcOrder->get_billing_company()); return !empty($wcCustomer->get_billing_company()) || !empty($wcOrder->get_billing_company());
} }
function getOptionByCode($optionName)
{
return get_option(WC_Retailcrm_Base::$option_key)[$optionName] ?? null;
}

View file

@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla
Requires PHP: 7.1 Requires PHP: 7.1
Requires at least: 5.3 Requires at least: 5.3
Tested up to: 6.5 Tested up to: 6.5
Stable tag: 4.8.17 Stable tag: 4.8.21
License: GPLv1 or later License: GPLv1 or later
License URI: http://www.gnu.org/licenses/gpl-1.0.html License URI: http://www.gnu.org/licenses/gpl-1.0.html
@ -82,6 +82,18 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i
== Changelog == == Changelog ==
= 4.8.21 =
* Fix version of module
= 4.8.20 =
* Add returned types for methods offsetExists, offsetSet, offsetUnset in WC_Retailcrm_Response
= 4.8.19 =
* Optimization of order unloading
= 4.8.18 =
* Added additional parameters to GET requests
= 4.8.17 = = 4.8.17 =
* Fix deploy * Fix deploy

View file

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

View file

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

View file

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