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

Added functionality to skip some orders statuses

This commit is contained in:
Dima Uryvskiy 2022-01-20 17:26:24 +03:00 committed by GitHub
parent 6cbb10e0ec
commit f8ac961520
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 896 additions and 797 deletions

View File

@ -1,3 +1,9 @@
## 2022-01-17 4.4.1
* Added functionality to skip some orders statuses
* Improved the create/update method when registering customers
* Add mapping metadata fields in settings
* Improvement of the user interface, plugin operation, fix bugs
## 2021-12-15 4.4.0
* Migrating to PHP 5.6. We tested the module, improved performance, security and test coverage.
* Add validate countryIso. Fix bug with duplicate customer address

View File

@ -1 +1 @@
4.4.0
4.4.1

View File

@ -2,12 +2,10 @@
В данной опции необходимо настроить соответствие между статусами WooCommerce и CRM.
Слева располагаются статусы WooCommerce, справа CRM. В выпадающем списке справа нужно выбрать статус в CRM, который будет соответствовать статусу в WooCommerce. Данное сопоставление требуется выбрать **для всех статусов**. Если ни одно из предложенных значений **не подходит**, то необходимо **создать в CRM новый статус**, либо пропустить сопоставление.
Слева располагаются статусы WooCommerce, справа CRM. В выпадающем списке справа нужно выбрать статус в CRM, который будет соответствовать статусу в WooCommerce. Данное сопоставление требуется выбрать **для всех статусов**. Если ни одно из предложенных значений **не подходит**, с версии 4.4.1 вы можете выбрать "Не отправлять в CRM", либо **создать в CRM новый статус**
После создания нового статуса на стороне CRM, в WooCommerce необходимо обновить страницу настроек *(перед этим не забудьте сохранить указанные ранее настройки)*, чтобы в предложенных значениях появился новый созданный статус.
Если сопоставление пропустить и не выбрать ни одного значения, в этом случае, **обновления** по заказу с данным статусом в WooCommerce, **не будут передаваться в CRM**.
Также в списке значений для сопоставления выводятся только **Активные в CRM статусы**.
Обратите внимание, что **значения не должны повторяться**, т.е. для двух статусов WooCommerce, не может быть выбран один и тот же статус в CRM. Необходимо выбирать 1 к 1.

View File

@ -0,0 +1,10 @@
## Статусы заказов
Обратная синхронизация (CRM --> WC):
* Если в CRM создают заказ со статусом для которого не выбран маппинг, модуль по умолчанию поставит "pending" для этого заказа в WC.
* Если в CRM изменении заказ со статусом для которого не выбран маппинг, статус заказа в WC изменен не будет.
Прямая синхронизация (WC --> CRM):
* Если в WC создают/изменяют заказ со статусом для которого в настройках маппинга статусов выбрано "Не отправлять в CRM", при создании заказа, в массиве данных заказа поля "status" не будет, CRM поставит статус по умолчанию, при изменении статус заказа в CRM изменен не будет.

View File

@ -0,0 +1,4 @@
## Платежи
1. Модуль при обратной синхронизации устанавливает только метод оплаты, но никак не реагирует на статус оплат в WooCommerce.

View File

@ -307,3 +307,7 @@ msgstr "Sincronización del historial"
msgid "Syncing inventories"
msgstr "Sincronización de inventario"
msgid "Don't send to CRM"
msgstr "No enviar al CRM"

View File

@ -316,5 +316,9 @@ msgstr "Синхронизация истории"
msgid "Syncing inventories"
msgstr "Синхронизация запасов"
msgid "Don't send to CRM"
msgstr "Не отправлять в CRM"

View File

@ -251,7 +251,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
/**
* Statuses options
*/
$statuses_option_list = array();
$statuses_option_list = ['not-upload' => __("Don't send to CRM", 'retailcrm')];
$retailcrm_statuses_list = $this->apiClient->statusesList();
if (!empty($retailcrm_statuses_list) && $retailcrm_statuses_list->isSuccessful()) {
@ -265,23 +265,23 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
$wc_statuses = wc_get_order_statuses();
$this->form_fields[] = array(
$this->form_fields[] = [
'title' => __('Statuses', 'retailcrm'),
'type' => 'heading',
'description' => '',
'id' => 'statuses_options'
);
];
foreach ($wc_statuses as $idx => $name) {
$uid = str_replace('wc-', '', $idx);
$this->form_fields[$uid] = array(
$this->form_fields[$uid] = [
'title' => __($name, 'woocommerce'),
'css' => 'min-width:350px;',
'class' => 'select',
'type' => 'select',
'options' => $statuses_option_list,
'desc_tip' => true,
);
];
}
}

View File

@ -618,15 +618,9 @@ if (!class_exists('WC_Retailcrm_History')) :
$customerId = isset($order['contact']['externalId']) ? $order['contact']['externalId'] : null;
}
$args = array(
'status' => isset($options[$order['status']])
? $options[$order['status']]
: 'processing',
'customer_id' => $customerId
);
$orderStatus = isset($options[$order['status']]) ? $options[$order['status']] : 'pending';
/** @var WC_Order|WP_Error wcOrder */
$wcOrder = wc_create_order($args);
$wcOrder = wc_create_order(['status' => $orderStatus, 'customer_id' => $customerId]);
$wcOrder->set_date_created($order['createdAt']);
$customer = $order['customer'];
$contactOrCustomer = array();

View File

@ -81,7 +81,7 @@ class WC_Retailcrm_Order extends WC_Retailcrm_Abstracts_Data
$this->set_data_fields($data);
$this->set_number($order);
if (isset($this->settings[$order->get_status()])) {
if (isset($this->settings[$order->get_status()]) && 'not-upload' !== $this->settings[$order->get_status()]) {
$this->set_data_field('status', $this->settings[$order->get_status()]);
}

Binary file not shown.

Binary file not shown.

View File

@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla
Requires PHP: 5.6
Requires at least: 5.3
Tested up to: 5.8
Stable tag: 4.4.0
Stable tag: 4.4.1
License: GPLv1 or later
License URI: http://www.gnu.org/licenses/gpl-1.0.html
@ -82,6 +82,12 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i
== Changelog ==
= 4.4.1 =
* Added functionality to skip some orders statuses
* Improved the create/update method when registering customers
* Add mapping metadata fields in settings
* Improvement of the user interface, plugin operation, fix bugs
= 4.4.0 =
* Migrating to PHP 5.6. We tested the module, improved performance, security and test coverage.
* Add validate countryIso. Fix bug with duplicate customer address

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@ class WC_Retailcrm_Test_Case_Helper extends WC_Unit_Test_Case
*/
protected function setOptions()
{
$options = array(
$options = [
'api_url' => 'https://example.retailcrm.ru',
'api_key' => 'test_key',
'corporate_enabled' => 'yes',
@ -26,7 +26,7 @@ class WC_Retailcrm_Test_Case_Helper extends WC_Unit_Test_Case
'p_pending' => 'no',
'p_private' => 'no',
'p_publish' => 'no',
'order_methods' => array(0 => 'phone'),
'order_methods' => [ 0 => 'phone' ],
'flat_rate_shipping' => 'delivery',
'free_shipping' => 'delivery2',
'local_pickup' => 'delivery3',
@ -39,9 +39,9 @@ class WC_Retailcrm_Test_Case_Helper extends WC_Unit_Test_Case
'processing' => 'status2',
'on-hold' => 'status3',
'completed' => 'status4',
'cancelled' => 'status5',
'refunded' => 'status6',
'failed' => 'status7',
'refunded' => 'status5',
'failed' => 'status6',
'cancelled' => 'not-upload',
'sync' => 'yes',
'ua' => 'yes',
'ua_code' => 'UA-XXXXXXX-XX',
@ -59,7 +59,7 @@ class WC_Retailcrm_Test_Case_Helper extends WC_Unit_Test_Case
'update_number' => 'yes',
'debug_mode' => 'yes',
'debug-info' => ''
);
];
update_option(WC_Retailcrm_Base::$option_key, $options);
@ -76,30 +76,27 @@ class WC_Retailcrm_Test_Case_Helper extends WC_Unit_Test_Case
} else {
global $wpdb;
foreach ( array(
foreach ([
$wpdb->posts,
$wpdb->postmeta,
$wpdb->comments,
$wpdb->commentmeta,
$wpdb->term_relationships,
$wpdb->termmeta,
) as $table ) {
] as $table ) {
//phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DELETE FROM {$table}" );
}
foreach ( array(
$wpdb->terms,
$wpdb->term_taxonomy,
) as $table ) {
foreach ([$wpdb->terms, $wpdb->term_taxonomy] as $table) {
//phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DELETE FROM {$table} WHERE term_id != 1" );
$wpdb->query("DELETE FROM {$table} WHERE term_id != 1");
}
$wpdb->query( "UPDATE {$wpdb->term_taxonomy} SET count = 0" );
$wpdb->query("UPDATE {$wpdb->term_taxonomy} SET count = 0");
$wpdb->query( "DELETE FROM {$wpdb->users} WHERE ID != 1" );
$wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE user_id != 1" );
$wpdb->query("DELETE FROM {$wpdb->users} WHERE ID != 1");
$wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE user_id != 1");
}
}

View File

@ -40,26 +40,26 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
$retailcrm_history = new WC_Retailcrm_History($this->apiMock);
$retailcrm_history->getHistory();
$orders = wc_get_orders(array('numberposts' => -1));
$order_added = end($orders);
$orders = wc_get_orders(array('numberposts' => -1));
$wcOrder = end($orders);
if (!$order_added) {
if (!$wcOrder) {
$this->fail('$order_added is null - no orders were added after receiving history');
}
$order_added_items = $order_added->get_items();
$order_added_items = $wcOrder->get_items();
$order_added_item = reset($order_added_items);
$shipping_address = $order_added->get_address('shipping');
$billing_address = $order_added->get_address('billing');
$shipping_address = $wcOrder->get_address('shipping');
$billing_address = $wcOrder->get_address('billing');
$options = get_option(\WC_Retailcrm_Base::$option_key);
$this->assertEquals('status1', $options[$order_added->get_status()]);
$this->assertEquals('status1', $options[$wcOrder->get_status()]);
if (is_object($order_added_item)) {
$this->assertEquals($product->get_id(), $order_added_item->get_product()->get_id());
}
$this->assertNotEmpty($order_added->get_date_created());
$this->assertNotEmpty($wcOrder->get_date_created());
$this->assertEquals("2018-01-01 00:00:00", $order['history'][0]['createdAt']);
$this->assertNotEmpty($shipping_address['first_name']);
$this->assertNotEmpty($shipping_address['last_name']);
@ -83,11 +83,29 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertNotEmpty($billing_address['country']);
$this->assertNotEmpty($billing_address['state']);
if ($order_added->get_payment_method()) {
$this->assertEquals('payment4', $options[$order_added->get_payment_method()]);
if ($wcOrder->get_payment_method()) {
$this->assertEquals('payment4', $options[$wcOrder->get_payment_method()]);
}
}
public function test_history_order_create_statuses()
{
$product = WC_Helper_Product::create_simple_product();
$order = DataHistoryRetailCrm::get_history_data_new_order($product->get_id());
$this->mockHistory(true, DataHistoryRetailCrm::empty_history(), $order);
$retailcrm_history = new WC_Retailcrm_History($this->apiMock);
$retailcrm_history->getHistory();
$orders = wc_get_orders(array( 'numberposts' => - 1 ));
$wcOrder = end($orders);
$options = get_option(\WC_Retailcrm_Base::$option_key);
$this->assertEquals('status1', $options[$wcOrder->get_status()]);
}
public function test_history_order_create_deleted_items()
{
$product = WC_Helper_Product::create_simple_product();
@ -166,13 +184,13 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
$retailcrm_history = new \WC_Retailcrm_History($this->apiMock);
$retailcrm_history->getHistory();
$order_updated = wc_get_order($order->get_id());
$order_updated_items = $order_updated->get_items();
$order_updated_item = end($order_updated_items);
$wcOrder = wc_get_order($order->get_id());
$wcOrderItems = $wcOrder->get_items();
$wcOrderItem = end($wcOrderItems);
$this->assertEquals(2, count($order_updated_items));
$this->assertEquals(2, $order_updated_item->get_quantity());
$this->assertEquals($product->get_id(), $order_updated_item->get_product()->get_id());
$this->assertEquals(2, count($wcOrderItems));
$this->assertEquals(2, $wcOrderItem->get_quantity());
$this->assertEquals($product->get_id(), $wcOrderItem->get_product()->get_id());
}
public function test_history_order_update()

View File

@ -48,7 +48,9 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
/**
* @param $retailcrm
*
* @dataProvider dataProviderRetailcrm
* @throws Exception
*/
public function test_order_create($retailcrm)
{
@ -57,12 +59,12 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$responseMockCustomers = $this->createResponseMock();
$responseMockCustomers->setResponse(
array(
[
'success' => true,
'customers' => array(
array('externalId' => 1)
)
)
'customers' => [
['externalId' => 1]
]
]
);
$this->setMockResponse($retailcrm, 'ordersCreate', $responseMock);
@ -191,7 +193,8 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
/**
* @param $isSuccessful
* @param $retailcrm
*
* @throws Exception
* @dataProvider dataProviderUpdateOrder
*/
public function test_update_order($isSuccessful, $retailcrm)
@ -264,6 +267,59 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
}
}
/**
* @param $isSuccessful
* @param $retailcrm
*
* @throws Exception
* @dataProvider dataProviderUpdateOrder
*/
public function test_update_order_statuses($isSuccessful, $retailcrm)
{
$this->createTestOrder();
if ($retailcrm) {
$responseMock = $this->createResponseMock();
$this->setMockResponse($responseMock, 'isSuccessful', $isSuccessful);
$this->setMockResponse($retailcrm, 'ordersEdit', $responseMock);
$this->setMockResponse($retailcrm, 'ordersPaymentDelete', $responseMock);
$response = $this->getResponseData($this->order->get_id());
$responseMock->setResponse($response);
$this->setMockResponse($retailcrm, 'ordersGet', $responseMock);
}
//Check change status to not-uploaded in CRM
$this->order->set_status('cancelled');
$this->order->save();
$retailcrmOrders = $this->getRetailcrmOrders($retailcrm);
$order = $retailcrmOrders->updateOrder($this->order->get_id());
$orderData = $retailcrmOrders->getOrder();
if ($retailcrm) {
$this->assertInstanceOf('WC_Order', $order);
$this->assertInternalType('array', $orderData);
$this->assertArrayNotHasKey('status', $orderData);
//Check change status to uploaded in CRM
$this->order->set_status('completed');
$this->order->save();
$order = $retailcrmOrders->updateOrder($this->order->get_id());
$orderData = $retailcrmOrders->getOrder();
$this->assertInstanceOf('WC_Order', $order);
$this->assertInternalType('array', $orderData);
$this->assertArrayHasKey('status', $orderData);
$this->assertEquals('status4', $orderData['status']);
} else {
$this->assertEquals(null, $order);
}
}
public function test_is_corporate_order()
{
$this->createTestOrder();