diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a3f1d6..eadbc49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/VERSION b/VERSION index 64b5ae3..4f3470c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.4.0 \ No newline at end of file +4.4.1 \ No newline at end of file diff --git a/doc/1.Setup/Order statuses.md b/doc/1.Setup/Order statuses.md index a2eec70..9c51dfa 100644 --- a/doc/1.Setup/Order statuses.md +++ b/doc/1.Setup/Order statuses.md @@ -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. diff --git a/doc/2. Workflow/Order statuses.md b/doc/2. Workflow/Order statuses.md new file mode 100644 index 0000000..719035a --- /dev/null +++ b/doc/2. Workflow/Order statuses.md @@ -0,0 +1,10 @@ +## Статусы заказов + +Обратная синхронизация (CRM --> WC): +* Если в CRM создают заказ со статусом для которого не выбран маппинг, модуль по умолчанию поставит "pending" для этого заказа в WC. +* Если в CRM изменении заказ со статусом для которого не выбран маппинг, статус заказа в WC изменен не будет. + +Прямая синхронизация (WC --> CRM): +* Если в WC создают/изменяют заказ со статусом для которого в настройках маппинга статусов выбрано "Не отправлять в CRM", при создании заказа, в массиве данных заказа поля "status" не будет, CRM поставит статус по умолчанию, при изменении статус заказа в CRM изменен не будет. + + diff --git a/doc/4. Known issues/Issues.md b/doc/4. Known issues/Issues.md new file mode 100644 index 0000000..6ba9cb3 --- /dev/null +++ b/doc/4. Known issues/Issues.md @@ -0,0 +1,4 @@ +## Платежи + +1. Модуль при обратной синхронизации устанавливает только метод оплаты, но никак не реагирует на статус оплат в WooCommerce. + diff --git a/resources/pot/retailcrm-es_ES.pot b/resources/pot/retailcrm-es_ES.pot index 79328cd..e75c247 100644 --- a/resources/pot/retailcrm-es_ES.pot +++ b/resources/pot/retailcrm-es_ES.pot @@ -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" + + diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot index 99e428e..72ddc7b 100644 --- a/resources/pot/retailcrm-ru_RU.pot +++ b/resources/pot/retailcrm-ru_RU.pot @@ -316,5 +316,9 @@ msgstr "Синхронизация истории" msgid "Syncing inventories" msgstr "Синхронизация запасов" +msgid "Don't send to CRM" +msgstr "Не отправлять в CRM" + + diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php index 84449e9..e9b97ff 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php @@ -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, - ); + ]; } } diff --git a/src/include/class-wc-retailcrm-history.php b/src/include/class-wc-retailcrm-history.php index 50a0d03..0199911 100644 --- a/src/include/class-wc-retailcrm-history.php +++ b/src/include/class-wc-retailcrm-history.php @@ -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(); diff --git a/src/include/order/class-wc-retailcrm-order.php b/src/include/order/class-wc-retailcrm-order.php index c601fdb..a18b3ca 100644 --- a/src/include/order/class-wc-retailcrm-order.php +++ b/src/include/order/class-wc-retailcrm-order.php @@ -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()]); } diff --git a/src/languages/retailcrm-es_ES.mo b/src/languages/retailcrm-es_ES.mo index 5d48b5f..54ed902 100644 Binary files a/src/languages/retailcrm-es_ES.mo and b/src/languages/retailcrm-es_ES.mo differ diff --git a/src/languages/retailcrm-ru_RU.mo b/src/languages/retailcrm-ru_RU.mo index 5abae5c..34b6ffa 100644 Binary files a/src/languages/retailcrm-ru_RU.mo and b/src/languages/retailcrm-ru_RU.mo differ diff --git a/src/readme.txt b/src/readme.txt index 3591402..1b40f73 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -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 diff --git a/src/retailcrm.php b/src/retailcrm.php index 5e31abb..0dbd5ec 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -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 diff --git a/src/uninstall.php b/src/uninstall.php index 74ab04c..27587f6 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -16,7 +16,7 @@ * * @link https://wordpress.org/plugins/woo-retailcrm/ * - * @version 4.4.0 + * @version 4.4.1 * * @package RetailCRM */ diff --git a/tests/datasets/data-history-retailcrm.php b/tests/datasets/data-history-retailcrm.php index 6b7c1fd..0977ab1 100644 --- a/tests/datasets/data-history-retailcrm.php +++ b/tests/datasets/data-history-retailcrm.php @@ -17,33 +17,33 @@ class DataHistoryRetailCrm { public static function empty_history() { - return array( + return [ 'success' => true, - 'history' => array(), - 'pagination' => array( + 'history' => [], + 'pagination' => [ 'limit' => 100, 'totalCount' => 0, 'currentPage' => 1, 'totalPageCount' => 0 - ) - ); + ] + ]; } public static function get_history_data_new_customer() { - return array( + return [ 'success' => true, - 'history' => array( - array ( + 'history' => [ + [ 'id' => 18009, 'createdAt' => '2021-12-03 13:22:45', 'created' => true, 'source' => 'user', - 'user' => array('id' => 11), + 'user' => [ 'id' => 11 ], 'field' => 'id', 'oldValue' => null, 'newValue' => 3758, - 'customer' => array ( + 'customer' => [ 'type' => 'customer', 'id' => 3758, 'isContact' => false, @@ -55,54 +55,54 @@ class DataHistoryRetailCrm 'totalSumm' => 0, 'averageSumm' => 0, 'ordersCount' => 0, - 'customFields' => array(), + 'customFields' => [], 'personalDiscount' => 0, 'cumulativeDiscount' => 0, - 'address' => array ( + 'address' => [ 'id' => 3503, 'index' => 123456, 'countryIso' => 'ES', 'region' => 'Region', 'city' => 'City', 'text' => 'street Test 777', - ), - 'segments' => array(), + ], + 'segments' => [], 'firstName' => 'Test_Name', 'lastName' => 'Test', 'email' => 'mail_test@mail.es', - 'phones' => array('0' => array('number' => '+79184563200')), + 'phones' => [ '0' => [ 'number' => '+79184563200' ] ], 'birthday' => '2021-10-01' - ) - ) - ), - 'pagination' => array( + ] + ] + ], + 'pagination' => [ 'limit' => 100, 'totalCount' => 1, 'currentPage' => 1, 'totalPageCount' => 1 - ) - ); + ] + ]; } public static function get_history_data_new_order($product_create_id) { - return array( + return [ 'success' => true, - 'history' => array( - array( + 'history' => [ + [ 'id' => 1, 'createdAt' => '2018-01-01 00:00:00', 'created' => true, 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 1 - ), + ], 'field' => 'status', 'oldValue' => null, - 'newValue' => array( + 'newValue' => [ 'code' => 'status1' - ), - 'order' => array( + ], + 'order' => [ 'slug' => 1, 'id' => 1, 'number' => '1C', @@ -121,36 +121,36 @@ class DataHistoryRetailCrm 'phone' => '80000000000', 'call' => false, 'expired' => false, - 'customer' => array( + 'customer' => [ 'type' => 'customer', - 'segments' => array(), + 'segments' => [], 'id' => 1, 'firstName' => 'Test', 'lastName' => 'Test', 'email' => 'email@test.ru', - 'phones' => array( - array( + 'phones' => [ + [ 'number' => '111111111111111' - ), - array( + ], + [ 'number' => '+7111111111' - ) - ), - 'address' => array( + ] + ], + 'address' => [ 'index' => '111111', 'countryIso' => 'RU', 'region' => 'Test region', 'city' => 'Test', 'text' => 'Test text address' - ), + ], 'createdAt' => '2018-01-01 00:00:00', 'managerId' => 1, 'vip' => false, 'bad' => false, 'site' => 'test-com', - 'contragent' => array( + 'contragent' => [ 'contragentType' => 'individual' - ), + ], 'personalDiscount' => 0, 'cumulativeDiscount' => 0, 'marginSumm' => 58654, @@ -158,98 +158,98 @@ class DataHistoryRetailCrm 'averageSumm' => 15387.25, 'ordersCount' => 4, 'costSumm' => 101, - 'customFields' => array( + 'customFields' => [ 'custom' => 'test' - ) - ), - 'contragent' => array(), - 'delivery' => array( + ] + ], + 'contragent' => [], + 'delivery' => [ 'cost' => 0, 'netCost' => 0, - 'address' => array( + 'address' => [ 'index' => '111111', 'countryIso' => 'RU', 'region' => 'Test region', 'city' => 'Test', 'text' => 'Test text address' - ) - ), + ] + ], 'site' => 'test-com', - 'status' => 'status1', - 'items' => array( - array( + 'status' => 'status4', + 'items' => [ + [ 'id' => 160, 'initialPrice' => 100, 'discountTotal' => 5, 'createdAt' => '2018-01-01 00:00:00', 'quantity' => 1, 'status' => 'new', - 'externalIds' => array( - array( + 'externalIds' => [ + [ 'code' => 'woocomerce', 'value' => '160_' . $product_create_id - ) - ), + ] + ], 'initialPrice' => 15, 'discountTotal' => 1, - 'offer' => array( + 'offer' => [ 'id' => 1, 'externalId' => $product_create_id, 'xmlId' => '1', 'name' => 'Test name', 'vatRate' => 'none' - ), - 'properties' => array(), + ], + 'properties' => [], 'purchasePrice' => 50 - ) - ), + ] + ], 'paymentType' => 'payment4', - 'payments' => array( - array( + 'payments' => [ + [ 'id' => 1, 'type' => 'payment4', 'amount' => 100, - ) - ), + ] + ], 'fromApi' => false, 'length' => 0, 'width' => 0, 'height' => 0, 'shipmentStore' => 'main', 'shipped' => false, - 'customFields' => array(), + 'customFields' => [], 'uploadedToExternalStoreSystem' => false - ) - ) - ), - 'pagination' => array( + ] + ] + ], + 'pagination' => [ 'limit' => 100, 'totalCount' => 1, 'currentPage' => 1, 'totalPageCount' => 1 - ) - ); + ] + ]; } public static function get_history_data_new_order_deleted_items($product_create_id, $product_delete_id) { - return array( + return [ 'success' => true, - 'history' => array( - array( + 'history' => [ + [ 'id' => 1, 'createdAt' => '2018-01-01 00:00:00', 'created' => true, 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 1 - ), + ], 'field' => 'status', 'oldValue' => null, - 'newValue' => array( + 'newValue' => [ 'code' => 'status1' - ), - 'order' => array( + ], + 'order' => [ 'slug' => 3, 'id' => 3, 'number' => '3C', @@ -268,36 +268,36 @@ class DataHistoryRetailCrm 'phone' => '80000000000', 'call' => false, 'expired' => false, - 'customer' => array( + 'customer' => [ 'type' => 'customer', - 'segments' => array(), + 'segments' => [], 'id' => 1, 'firstName' => 'Test', 'lastName' => 'Test', 'email' => 'email@test.ru', - 'phones' => array( - array( + 'phones' => [ + [ 'number' => '111111111111111' - ), - array( + ], + [ 'number' => '+7111111111' - ) - ), - 'address' => array( + ] + ], + 'address' => [ 'index' => '111111', 'countryIso' => 'RU', 'region' => 'Test region', 'city' => 'Test', 'text' => 'Test text address' - ), + ], 'createdAt' => '2018-01-01 00:00:00', 'managerId' => 1, 'vip' => false, 'bad' => false, 'site' => 'test-com', - 'contragent' => array( + 'contragent' => [ 'contragentType' => 'individual' - ), + ], 'personalDiscount' => 0, 'cumulativeDiscount' => 0, 'marginSumm' => 58654, @@ -305,267 +305,267 @@ class DataHistoryRetailCrm 'averageSumm' => 15387.25, 'ordersCount' => 4, 'costSumm' => 101, - 'customFields' => array( + 'customFields' => [ 'custom' => 'test' - ) - ), - 'contragent' => array(), - 'delivery' => array( + ] + ], + 'contragent' => [], + 'delivery' => [ 'cost' => 0, 'netCost' => 0, - 'address' => array( + 'address' => [ 'index' => '111111', 'countryIso' => 'RU', 'region' => 'Test region', 'city' => 'Test', 'text' => 'Test text address' - ) - ), + ] + ], 'site' => 'test-com', 'status' => 'status1', - 'items' => array( - array( + 'items' => [ + [ 'id' => 160, 'initialPrice' => 15, 'discountTotal' => 1, 'createdAt' => '2018-01-01 00:00:00', 'quantity' => 1, 'status' => 'new', - 'externalIds' => array( - array( + 'externalIds' => [ + [ 'code' => 'woocomerce', 'value' => '160_' . $product_create_id - ) - ), - 'offer' => array( + ] + ], + 'offer' => [ 'id' => 1, 'externalId' => $product_create_id, 'xmlId' => '1', 'name' => 'Test name', 'vatRate' => 'none' - ), - 'properties' => array(), + ], + 'properties' => [], 'purchasePrice' => 10 - ), - array( + ], + [ 'id' => 161, 'initialPrice' => 100, 'discountTotal' => 5, 'createdAt' => '2018-01-01 00:00:00', 'quantity' => 1, 'status' => 'new', - 'externalIds' => array( - array( + 'externalIds' => [ + [ 'code' => 'woocomerce', 'value' => '161_' . $product_delete_id - ) - ), - 'offer' => array( + ] + ], + 'offer' => [ 'id' => 2, 'externalId' => $product_delete_id, 'xmlId' => '2', 'name' => 'Test name 2', 'vatRate' => 'none' - ), - 'properties' => array(), + ], + 'properties' => [], 'purchasePrice' => 50 - ) - ), + ] + ], 'paymentType' => 'payment4', - 'payments' => array( - array( + 'payments' => [ + [ 'id' => 1, 'type' => 'payment4', 'amount' => 100, - ) - ), + ] + ], 'fromApi' => false, 'length' => 0, 'width' => 0, 'height' => 0, 'shipmentStore' => 'main', 'shipped' => false, - 'customFields' => array(), + 'customFields' => [], 'uploadedToExternalStoreSystem' => false - ) - ), - array( + ] + ], + [ 'id' => 2, 'createdAt' => '2018-01-01 00:01:00', 'source' => 'api', 'field' => 'order_product', - 'oldValue' => array( + 'oldValue' => [ 'id' => 161, - 'offer' => array( + 'offer' => [ 'id' => 2, 'externalId' => $product_delete_id - ) - ), + ] + ], 'newValue' => null, - 'order' => array( + 'order' => [ 'id' => 3, 'site' => 'test-com', 'status' => 'status1' - ), - 'item' => array( + ], + 'item' => [ 'id' => 161, 'initialPrice' => 100, 'discountTotal' => 5, 'createdAt' => '2018-01-01 00:00:00', 'quantity' => 1, 'status' => 'new', - 'externalIds' => array( - array( + 'externalIds' => [ + [ 'code' => 'woocomerce', 'value' => '161_' . $product_delete_id - ) - ), - 'offer' => array( + ] + ], + 'offer' => [ 'id' => 2, 'externalId' => $product_delete_id, 'xmlId' => '2', 'name' => 'Test name 2', 'vatRate' => 'none' - ), - 'properties' => array(), + ], + 'properties' => [], 'purchasePrice' => 50 - ) - ) - ), - 'pagination' => array( + ] + ] + ], + 'pagination' => [ 'limit' => 100, 'totalCount' => 2, 'currentPage' => 1, 'totalPageCount' => 1 - ) - ); + ] + ]; } public static function get_history_data_product_add($product_add_id, $order_id) { - return array( + return [ 'success' => true, - 'history' => array( - array( + 'history' => [ + [ 'id' => 2, 'createdAt' => '2018-01-01 00:00:01', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 1 - ), + ], 'field' => 'order_product', 'oldValue' => null, - 'newValue' => array( + 'newValue' => [ 'id' => 2, - 'offer' => array( + 'offer' => [ 'id' => 2, 'externalId' => $product_add_id, 'xmlId' => 'xmlId' - ) - ), - 'order' => array( + ] + ], + 'order' => [ 'id' => 2, 'externalId' => $order_id, 'site' => 'test-com', 'status' => 'status1' - ), - 'item' => array( + ], + 'item' => [ 'id' => 2, 'initialPrice' => 999, 'createdAt' => '2018-01-01 00:02:00', 'quantity' => 2, 'status' => 'status1', - 'externalIds' => array( - array( + 'externalIds' => [ + [ 'code' => 'woocomerce', 'value' => '160_' . $product_add_id - ) - ), - 'offer' => array( + ] + ], + 'offer' => [ 'id' => 2, 'externalId' => $product_add_id, 'xmlId' => 'xmlId', 'name' => 'Test name 2' - ), - 'properties' => array(), + ], + 'properties' => [], 'purchasePrice' => 500 - ) - ) - ), - 'pagination' => array( + ] + ] + ], + 'pagination' => [ 'limit' => 100, 'totalCount' => 1, 'currentPage' => 1, 'totalPageCount' => 1 - ) - ); + ] + ]; } public static function get_history_data_update($order_id) { - $history = array( + $history = [ 'success' => true, - 'history' => array( - array( + 'history' => [ + [ 'id' => 3, 'createdAt' => '2018-01-01 00:03:00', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 1 - ), + ], 'field' => 'status', - 'oldValue' => array( + 'oldValue' => [ 'code' => 'new' - ), - 'newValue' => array( + ], + 'newValue' => [ 'code' => 'status4' - ), - 'order' => array( + ], + 'order' => [ 'id' => 2, 'externalId' => $order_id, 'managerId' => 6, 'site' => 'test-com', 'status' => 'status4' - ) - ), - array( + ] + ], + [ 'id' => 4, 'createdAt' => '2018-01-01 00:03:00', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 1 - ), + ], 'field' => 'managerComment', - 'oldValue' => array( + 'oldValue' => [ 'code' => '' - ), - 'newValue' => array( + ], + 'newValue' => [ 'code' => 'managerComment' - ), - 'order' => array( + ], + 'order' => [ 'id' => 2, 'externalId' => $order_id, 'managerId' => 6, 'site' => 'test-com', 'status' => 'status4', 'managerComment' => 'managerComment' - ) - ), - array( + ] + ], + [ 'id' => 5, 'createdAt' => '2018-01-01 00:03:00', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 1 - ), + ], 'field' => 'customerComment', - 'oldValue' => array( + 'oldValue' => [ 'code' => '' - ), - 'newValue' => array( + ], + 'newValue' => [ 'code' => 'customerComment' - ), - 'order' => array( + ], + 'order' => [ 'id' => 2, 'externalId' => $order_id, 'managerId' => 6, @@ -573,23 +573,23 @@ class DataHistoryRetailCrm 'status' => 'status4', 'managerComment' => 'managerComment', 'customerComment' => 'customerComment' - ) - ), - array( + ] + ], + [ 'id' => 6, 'createdAt' => '2018-01-01 00:03:00', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 1 - ), + ], 'field' => 'phone', - 'oldValue' => array( + 'oldValue' => [ 'code' => '' - ), - 'newValue' => array( + ], + 'newValue' => [ 'code' => '12345678' - ), - 'order' => array( + ], + 'order' => [ 'id' => 2, 'externalId' => $order_id, 'managerId' => 6, @@ -598,23 +598,23 @@ class DataHistoryRetailCrm 'managerComment' => 'managerComment', 'customerComment' => 'customerComment', 'phone' => '12345678' - ) - ), - array( + ] + ], + [ 'id' => 7, 'createdAt' => '2018-01-01 00:03:00', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 1 - ), + ], 'field' => 'email', - 'oldValue' => array( + 'oldValue' => [ 'code' => '' - ), - 'newValue' => array( + ], + 'newValue' => [ 'code' => 'tester001@example.com' - ), - 'order' => array( + ], + 'order' => [ 'id' => 2, 'externalId' => $order_id, 'managerId' => 6, @@ -624,16 +624,16 @@ class DataHistoryRetailCrm 'customerComment' => 'customerComment', 'phone' => '12345678', 'email' => 'tester001@example.com' - ) - ) - ), - 'pagination' => array( + ] + ] + ], + 'pagination' => [ 'limit' => 100, 'totalCount' => 1, 'currentPage' => 1, 'totalPageCount' => 1 - ) - ); + ] + ]; $payment_v5 = array( 'id' => 4, @@ -668,18 +668,19 @@ class DataHistoryRetailCrm public static function get_history_order_for_client_replace($productId) { - return array( + return [ 'success' => true, 'generatedAt' => '2020-06-04 15:05:39', - 'history' => array(array( + 'history' => [ + [ 'id' => 25011, 'createdAt' => '2020-06-04 15:05:10', 'created' => true, 'source' => 'user', 'field' => 'status', 'oldValue' => null, - 'newValue' => array ('code' => 'new'), - 'order' => array ( + 'newValue' => [ 'code' => 'new' ], + 'order' => [ 'slug' => 5868, 'id' => 5868, 'number' => '5868C', @@ -700,7 +701,7 @@ class DataHistoryRetailCrm 'call' => false, 'expired' => false, 'managerId' => 27, - 'customer' => array( + 'customer' => [ 'type' => 'customer', 'id' => 4228, 'externalId' => '2', @@ -710,30 +711,30 @@ class DataHistoryRetailCrm 'vip' => false, 'bad' => false, 'site' => 'bitrix-test', - 'contragent' => array( + 'contragent' => [ 'contragentType' => 'individual', - ), - 'tags' => array(), + ], + 'tags' => [], 'marginSumm' => 9412, 'totalSumm' => 9412, 'averageSumm' => 9412, 'ordersCount' => 1, 'costSumm' => 0, - 'customFields' => array(), + 'customFields' => [], 'personalDiscount' => 0, 'cumulativeDiscount' => 0, - 'address' => array( + 'address' => [ 'id' => 3132, 'text' => 'ул. Пушкина дом Колотушкина', - ), - 'segments' => array(), + ], + 'segments' => [], 'firstName' => 'tester001', 'lastName' => 'tester001', 'email' => 'tester001@example.com', 'emailMarketingUnsubscribedAt' => '2020-06-01 15:34:23', - 'phones' => array(array('number' => '2354708915097')) - ), - 'contact' => array( + 'phones' => [ [ 'number' => '2354708915097' ] ] + ], + 'contact' => [ 'type' => 'customer', 'id' => 4228, 'externalId' => '2', @@ -743,1054 +744,1055 @@ class DataHistoryRetailCrm 'vip' => false, 'bad' => false, 'site' => 'bitrix-test', - 'contragent' => array( + 'contragent' => [ 'contragentType' => 'individual', - ), - 'tags' => array(), + ], + 'tags' => [], 'marginSumm' => 9412, 'totalSumm' => 9412, 'averageSumm' => 9412, 'ordersCount' => 1, 'costSumm' => 0, - 'customFields' => array(), + 'customFields' => [], 'personalDiscount' => 0, 'cumulativeDiscount' => 0, - 'address' => array( + 'address' => [ 'id' => 3132, 'text' => 'ул. Пушкина дом Колотушкина', - ), - 'segments' => array(), + ], + 'segments' => [], 'firstName' => 'tester001', 'lastName' => 'tester001', 'email' => 'tester001@example.com', 'emailMarketingUnsubscribedAt' => '2020-06-01 15:34:23', - 'phones' => array(array('number' => '2354708915097')) - ), - 'contragent' => array( + 'phones' => [ [ 'number' => '2354708915097' ] ] + ], + 'contragent' => [ 'contragentType' => 'individual', - ), - 'delivery' => array( + ], + 'delivery' => [ 'cost' => 0, 'netCost' => 0, - 'address' => array( + 'address' => [ 'id' => 5864, 'countryIso' => 'RU', 'text' => 'ул. Пушкина дом Колотушкина', - ), - ), + ], + ], 'site' => 'woocommerce', 'status' => 'new', - 'items' => array( - array( + 'items' => [ + [ 'id' => 160, 'initialPrice' => 100, 'discountTotal' => 5, 'createdAt' => '2018-01-01 00:00:00', 'quantity' => 1, 'status' => 'new', - 'externalIds' => array( - array( + 'externalIds' => [ + [ 'code' => 'woocomerce', 'value' => '160_' . $productId - ) - ), + ] + ], 'initialPrice' => 15, 'discountTotal' => 1, - 'offer' => array( + 'offer' => [ 'id' => 1, 'externalId' => $productId, 'xmlId' => '1', 'name' => 'Test name', 'vatRate' => 'none' - ), - 'properties' => array(), + ], + 'properties' => [], 'purchasePrice' => 50 - ) - ), + ] + ], 'fromApi' => false, 'length' => 0, 'width' => 0, 'height' => 0, 'shipmentStore' => 'main', 'shipped' => false, - 'customFields' => array() - ) - )), - 'pagination' => array( + 'customFields' => [] + ] + ] + ], + 'pagination' => [ 'limit' => 100, 'totalCount' => 1, 'currentPage' => 1, 'totalPageCount' => 1, - ) - ); + ] + ]; } public static function get_history_change_to_another_individual($orderExternalId) { - return array( + return [ 'success' => true, 'generatedAt' => '2020-06-05 12:29:14', - 'history' => array( - array( + 'history' => [ + [ 'id' => 25398, 'createdAt' => '2020-06-05 12:29:08', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'contact', - 'oldValue' => array( + 'oldValue' => [ 'id' => 4228, 'externalId' => '2', 'site' => 'bitrix-test', - ), - 'newValue' => array( + ], + 'newValue' => [ 'id' => 4231, 'site' => 'bitrix-test', - ), - 'order' => array( + ], + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25399, 'createdAt' => '2020-06-05 12:29:08', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'customer', - 'oldValue' => array( + 'oldValue' => [ 'id' => 4228, 'externalId' => '2', 'site' => 'bitrix-test', - ), - 'newValue' => array( + ], + 'newValue' => [ 'id' => 4231, 'site' => 'bitrix-test', - ), - 'order' => array( + ], + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25400, 'createdAt' => '2020-06-05 12:29:08', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'email', 'oldValue' => 'tester001@example.com', 'newValue' => 'ewtrhibehb126879@example.com', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25401, 'createdAt' => '2020-06-05 12:29:08', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'first_name', 'oldValue' => 'tester001', 'newValue' => 'tester002', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25402, 'createdAt' => '2020-06-05 12:29:08', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'last_name', 'oldValue' => 'tester001', 'newValue' => 'tester002', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25403, 'createdAt' => '2020-06-05 12:29:08', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'patronymic', 'oldValue' => null, 'newValue' => 'tester002', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25404, 'createdAt' => '2020-06-05 12:29:08', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'phone', 'oldValue' => '2354708915097', 'newValue' => '34687453268933', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - ), - 'pagination' => array( + ], + ], + ], + 'pagination' => [ 'limit' => 100, 'totalCount' => 7, 'currentPage' => 1, 'totalPageCount' => 1, - ), - ); + ], + ]; } public static function get_history_change_to_corporate($orderExternalId) { - return array( + return [ 'success' => true, 'generatedAt' => '2020-06-05 15:24:19', - 'history' => array( - array( + 'history' => [ + [ 'id' => 25744, 'createdAt' => '2020-06-05 15:24:12', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'delivery_address.city', 'oldValue' => 'с. Верхненазаровское', 'newValue' => 'Валдгейм', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25745, 'createdAt' => '2020-06-05 15:24:12', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'delivery_address.index', 'oldValue' => '34000', 'newValue' => '344091', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25746, 'createdAt' => '2020-06-05 15:24:12', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'delivery_address.region', 'oldValue' => 'Адыгея Республика', 'newValue' => 'Еврейская Автономная область', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25747, 'createdAt' => '2020-06-05 15:24:12', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'contragent.contragent_type', 'oldValue' => 'individual', 'newValue' => 'legal-entity', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25748, 'createdAt' => '2020-06-05 15:24:12', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'contragent.legal_address', 'oldValue' => null, 'newValue' => '344090 * Москва упцупуцйпуц йцавафыафыафыафы', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25749, 'createdAt' => '2020-06-05 15:24:12', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'company', 'oldValue' => null, - 'newValue' => array( + 'newValue' => [ 'id' => 591, 'name' => 'Компания1', - ), - 'order' => array( + ], + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25750, 'createdAt' => '2020-06-05 15:24:12', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'contact', - 'oldValue' => array( + 'oldValue' => [ 'id' => 4231, 'site' => 'bitrix-test', - ), - 'newValue' => array( + ], + 'newValue' => [ 'id' => 4219, 'externalId' => '4', 'site' => 'woocommerce', - ), - 'order' => array( + ], + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25751, 'createdAt' => '2020-06-05 15:24:12', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'customer', - 'oldValue' => array( + 'oldValue' => [ 'id' => 4231, 'site' => 'bitrix-test', - ), - 'newValue' => array( + ], + 'newValue' => [ 'id' => 4220, 'site' => 'woocommerce', - ), - 'order' => array( + ], + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25752, 'createdAt' => '2020-06-05 15:24:12', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'email', 'oldValue' => 'ewtrhibehb126879@example.com', 'newValue' => 'psycho913@example.com', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25753, 'createdAt' => '2020-06-05 15:24:12', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'first_name', 'oldValue' => 'tester002', 'newValue' => 'psycho913', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25754, 'createdAt' => '2020-06-05 15:24:12', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'last_name', 'oldValue' => 'tester002', 'newValue' => 'psycho913', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25755, 'createdAt' => '2020-06-05 15:24:12', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'patronymic', 'oldValue' => 'tester002', 'newValue' => null, - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25756, 'createdAt' => '2020-06-05 15:24:12', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'phone', 'oldValue' => '34687453268933', 'newValue' => '9135487458709', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - ), - 'pagination' => array( + ], + ], + ], + 'pagination' => [ 'limit' => 100, 'totalCount' => 13, 'currentPage' => 1, 'totalPageCount' => 1, - ), - ); + ], + ]; } public static function get_history_change_to_another_corporate($orderExternalId) { - return array( + return [ 'success' => true, 'generatedAt' => '2020-06-05 16:37:53', - 'history' => array( - array( + 'history' => [ + [ 'id' => 25979, 'createdAt' => '2020-06-05 16:37:46', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'contragent.legal_address', 'oldValue' => '344090 * Москва упцупуцйпуц йцавафыафыафыафы', 'newValue' => null, - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25980, 'createdAt' => '2020-06-05 16:37:46', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'company', - 'oldValue' => array( + 'oldValue' => [ 'id' => 591, 'name' => 'Компания1', - ), - 'newValue' => array( + ], + 'newValue' => [ 'id' => 621, 'name' => 'TestCompany3428769', - ), - 'order' => array( + ], + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25981, 'createdAt' => '2020-06-05 16:37:46', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'contact', - 'oldValue' => array( + 'oldValue' => [ 'id' => 4219, 'externalId' => '4', 'site' => 'woocommerce', - ), - 'newValue' => array( + ], + 'newValue' => [ 'id' => 4304, 'site' => 'woocommerce', - ), - 'order' => array( + ], + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25982, 'createdAt' => '2020-06-05 16:37:46', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'customer', - 'oldValue' => array( + 'oldValue' => [ 'id' => 4220, 'site' => 'woocommerce', - ), - 'newValue' => array( + ], + 'newValue' => [ 'id' => 4303, 'site' => 'woocommerce', - ), - 'order' => array( + ], + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25983, 'createdAt' => '2020-06-05 16:37:46', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'email', 'oldValue' => 'psycho913@example.com', 'newValue' => 'tester4867@example.com', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25984, 'createdAt' => '2020-06-05 16:37:46', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'first_name', 'oldValue' => 'psycho913', 'newValue' => 'Tester4867', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25985, 'createdAt' => '2020-06-05 16:37:46', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'last_name', 'oldValue' => 'psycho913', 'newValue' => 'Tester4867', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25986, 'createdAt' => '2020-06-05 16:37:46', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'patronymic', 'oldValue' => null, 'newValue' => 'Tester4867', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25987, 'createdAt' => '2020-06-05 16:37:46', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'phone', 'oldValue' => '9135487458709', 'newValue' => null, - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - ), - 'pagination' => array( + ], + ], + ], + 'pagination' => [ 'limit' => 100, 'totalCount' => 9, 'currentPage' => 1, 'totalPageCount' => 1, - ), - ); + ], + ]; } public static function get_history_change_only_company($orderExternalId) { - return array( + return [ 'success' => true, 'generatedAt' => '2020-06-05 17:13:23', - 'history' => array( - array( + 'history' => [ + [ 'id' => 25988, 'createdAt' => '2020-06-05 17:13:17', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'company', - 'oldValue' => array( + 'oldValue' => [ 'id' => 621, 'name' => 'TestCompany3428769', - ), - 'newValue' => array( + ], + 'newValue' => [ 'id' => 622, 'name' => 'TestCompany017089465', - ), - 'order' => array( + ], + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - ), - 'pagination' => array( + ], + ], + ], + 'pagination' => [ 'limit' => 100, 'totalCount' => 1, 'currentPage' => 1, 'totalPageCount' => 1, - ), - ); + ], + ]; } public static function get_history_change_only_contact($orderExternalId) { - return array( + return [ 'success' => true, 'generatedAt' => '2020-06-05 17:36:28', - 'history' => array( - array( + 'history' => [ + [ 'id' => 25989, 'createdAt' => '2020-06-05 17:36:20', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'contact', - 'oldValue' => array( + 'oldValue' => [ 'id' => 4304, 'site' => 'woocommerce', - ), - 'newValue' => array( + ], + 'newValue' => [ 'id' => 4305, 'site' => 'woocommerce', - ), - 'order' => array( + ], + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25990, 'createdAt' => '2020-06-05 17:36:20', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'email', 'oldValue' => 'tester4867@example.com', 'newValue' => 'tester2890@example.com', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25991, 'createdAt' => '2020-06-05 17:36:20', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'first_name', 'oldValue' => 'Tester4867', 'newValue' => 'Tester2890', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25992, 'createdAt' => '2020-06-05 17:36:20', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'last_name', 'oldValue' => 'Tester4867', 'newValue' => 'Tester2890', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25993, 'createdAt' => '2020-06-05 17:36:20', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'patronymic', 'oldValue' => 'Tester4867', 'newValue' => 'Tester2890', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25994, 'createdAt' => '2020-06-05 17:36:20', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'phone', 'oldValue' => null, 'newValue' => '32418790888', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - ), - 'pagination' => array( + ], + ], + ], + 'pagination' => [ 'limit' => 100, 'totalCount' => 6, 'currentPage' => 1, 'totalPageCount' => 1, - ), - ); + ], + ]; } public static function get_history_change_from_corporate_to_individual($orderExternalId) { - return array( + return [ 'success' => true, 'generatedAt' => '2020-06-05 17:47:05', - 'history' => array( - array( + 'history' => [ + [ 'id' => 25995, 'createdAt' => '2020-06-05 17:46:58', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'contragent.contragent_type', 'oldValue' => 'legal-entity', 'newValue' => 'individual', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25996, 'createdAt' => '2020-06-05 17:46:58', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'contact', - 'oldValue' => array( + 'oldValue' => [ 'id' => 4305, 'site' => 'woocommerce', - ), - 'newValue' => array( + ], + 'newValue' => [ 'id' => 4228, 'externalId' => '2', 'site' => 'bitrix-test', - ), - 'order' => array( + ], + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25997, 'createdAt' => '2020-06-05 17:46:58', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'customer', - 'oldValue' => array( + 'oldValue' => [ 'id' => 4303, 'site' => 'woocommerce', - ), - 'newValue' => array( + ], + 'newValue' => [ 'id' => 4228, 'externalId' => '2', 'site' => 'bitrix-test', - ), - 'order' => array( + ], + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25998, 'createdAt' => '2020-06-05 17:46:58', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'email', 'oldValue' => 'tester2890@example.com', 'newValue' => 'tester001@example.com', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 25999, 'createdAt' => '2020-06-05 17:46:58', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'first_name', 'oldValue' => 'Tester2890', 'newValue' => 'tester001', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 26000, 'createdAt' => '2020-06-05 17:46:58', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'last_name', 'oldValue' => 'Tester2890', 'newValue' => 'tester001', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 26001, 'createdAt' => '2020-06-05 17:46:58', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'patronymic', 'oldValue' => 'Tester2890', 'newValue' => null, - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - array( + ], + ], + [ 'id' => 26002, 'createdAt' => '2020-06-05 17:46:58', 'source' => 'user', - 'user' => array( + 'user' => [ 'id' => 27, - ), + ], 'field' => 'phone', 'oldValue' => '32418790888', 'newValue' => '2354708915097', - 'order' => array( + 'order' => [ 'id' => 5868, 'externalId' => $orderExternalId, 'managerId' => 27, 'site' => 'woocommerce', 'status' => 'new', - ), - ), - ), - 'pagination' => array( + ], + ], + ], + 'pagination' => [ 'limit' => 100, 'totalCount' => 8, 'currentPage' => 1, 'totalPageCount' => 1, - ), - ); + ], + ]; } public static function get_initial_regular_customer() { - return array( + return [ 'type' => 'customer', 'id' => 4228, 'externalId' => '2', @@ -1800,35 +1802,35 @@ class DataHistoryRetailCrm 'vip' => false, 'bad' => false, 'site' => 'bitrix-test', - 'contragent' => array( + 'contragent' => [ 'contragentType' => 'individual', - ), - 'tags' => array(), + ], + 'tags' => [], 'marginSumm' => 9428, 'totalSumm' => 9428, 'averageSumm' => 4714, 'ordersCount' => 2, 'costSumm' => 0, 'personalDiscount' => 0, - 'address' => array( + 'address' => [ 'id' => 3132, 'text' => 'ул. Пушкина дом Колотушкина', - ), + ], 'firstName' => 'tester001', 'lastName' => 'tester001', 'email' => 'tester001@example.com', 'emailMarketingUnsubscribedAt' => '2020-06-01 15:34:23', - 'phones' => array( - array( + 'phones' => [ + [ 'number' => '2354708915097', - ), - ), - ); + ], + ], + ]; } public static function get_contact_when_only_contact_changed() { - return array( + return [ 'type' => 'customer', 'id' => 4305, 'isContact' => true, @@ -1837,38 +1839,38 @@ class DataHistoryRetailCrm 'vip' => false, 'bad' => false, 'site' => 'woocommerce', - 'tags' => array(), + 'tags' => [], 'marginSumm' => 0, 'totalSumm' => 0, 'averageSumm' => 0, 'ordersCount' => 0, 'costSumm' => 0, - 'customFields' => array( + 'customFields' => [ 'galkatrue' => true, - ), + ], 'personalDiscount' => 0, - 'segments' => array(), + 'segments' => [], 'firstName' => 'Tester2890', 'lastName' => 'Tester2890', 'patronymic' => 'Tester2890', 'email' => 'tester2890@example.com', - 'phones' => array( - array( + 'phones' => [ + [ 'number' => '32418790888', - ), - ), - ); + ], + ], + ]; } public static function get_order_with_customer_and_contact( $customer, - $contact = array(), - $company = array(), + $contact = [], + $company = [], $contragentType = 'individual' ) { - $order = array( + $order = [ 'success' => true, - 'order' => array( + 'order' => [ 'slug' => 5868, 'id' => 5868, 'number' => '5868C', @@ -1893,13 +1895,13 @@ class DataHistoryRetailCrm 'call' => false, 'expired' => false, 'managerId' => 27, - 'contragent' => array( + 'contragent' => [ 'contragentType' => $contragentType, - ), - 'delivery' => array( + ], + 'delivery' => [ 'cost' => 0, 'netCost' => 0, - 'address' => array( + 'address' => [ 'index' => '34000', 'countryIso' => 'RU', 'region' => 'Адыгея Республика', @@ -1910,59 +1912,59 @@ class DataHistoryRetailCrm 'streetId' => 962815, 'building' => '22', 'text' => 'ул. Зеленая, д. 22', - ), - ), + ], + ], 'site' => 'woocommerce', 'status' => 'new', - 'items' => array( - array( - 'markingCodes' => array(), + 'items' => [ + [ + 'markingCodes' => [], 'id' => 8955, - 'externalIds' => array( - array( + 'externalIds' => [ + [ 'code' => 'woocomerce', 'value' => '23_31', - ), - ), - 'priceType' => array( + ], + ], + 'priceType' => [ 'code' => 'base', - ), + ], 'initialPrice' => 16, 'discountTotal' => 5, 'vatRate' => 'none', 'createdAt' => '2020-06-04 14:54:54', 'quantity' => 1, 'status' => 'new', - 'offer' => array( + 'offer' => [ 'displayName' => 'Cap', 'id' => 67424, 'externalId' => '23', 'name' => 'Cap', 'vatRate' => 'none', - 'unit' => array( + 'unit' => [ 'code' => 'pc', 'name' => 'Штука', 'sym' => 'шт.', - ), - ), - 'properties' => array(), + ], + ], + 'properties' => [], 'purchasePrice' => 0, - ), - ), - 'payments' => array(), + ], + ], + 'payments' => [], 'fromApi' => false, 'length' => 0, 'width' => 0, 'height' => 0, 'shipmentStore' => 'main', 'shipped' => false, - 'customFields' => array( + 'customFields' => [ 'galka' => false, 'test_number' => 0, 'otpravit_dozakaz' => false, - ), - ), - ); + ], + ], + ]; if (!empty($company)) { $order['order']['company'] = $company; @@ -1973,7 +1975,7 @@ class DataHistoryRetailCrm public static function get_new_individual_for_order() { - return array( + return [ 'type' => 'customer', 'id' => 4231, 'isContact' => false, @@ -1982,20 +1984,20 @@ class DataHistoryRetailCrm 'vip' => false, 'bad' => false, 'site' => 'bitrix-test', - 'contragent' => array( + 'contragent' => [ 'contragentType' => 'individual', - ), - 'tags' => array(), + ], + 'tags' => [], 'marginSumm' => 2144, 'totalSumm' => 2144, 'averageSumm' => 1072, 'ordersCount' => 2, 'costSumm' => 0, - 'customFields' => array( + 'customFields' => [ 'galkatrue' => true, - ), + ], 'personalDiscount' => 0, - 'address' => array( + 'address' => [ 'id' => 3135, 'index' => '34000', 'countryIso' => 'RU', @@ -2007,62 +2009,62 @@ class DataHistoryRetailCrm 'streetId' => 962815, 'building' => '22', 'text' => 'ул. Зеленая, д. 22', - ), + ], 'firstName' => 'tester002', 'lastName' => 'tester002', 'patronymic' => 'tester002', 'email' => 'ewtrhibehb126879@example.com', - 'phones' => array( - array( + 'phones' => [ + [ 'number' => '34687453268933', - ), - ), - ); + ], + ], + ]; } public static function get_new_corporate_for_order() { - return array( + return [ 'type' => 'customer_corporate', 'id' => 4220, 'nickName' => 'Компания1', - 'mainAddress' => array( + 'mainAddress' => [ 'id' => 3131, 'name' => 'Компания2', - ), + ], 'createdAt' => '2020-05-27 15:20:33', 'managerId' => 27, 'vip' => false, 'bad' => false, 'site' => 'woocommerce', - 'tags' => array(), + 'tags' => [], 'marginSumm' => 604, 'totalSumm' => 604, 'averageSumm' => 604, 'ordersCount' => 1, 'costSumm' => 0, - 'customFields' => array( + 'customFields' => [ 'galkatrue' => true, - ), + ], 'personalDiscount' => 0, - 'mainCustomerContact' => array( + 'mainCustomerContact' => [ 'id' => 711, - 'customer' => array( + 'customer' => [ 'id' => 4219, 'externalId' => '4', - ), - 'companies' => array(), - ), - 'mainCompany' => array( + ], + 'companies' => [], + ], + 'mainCompany' => [ 'id' => 591, 'name' => 'Компания1', - ), - ); + ], + ]; } public static function get_new_contact_for_order() { - return array( + return [ 'type' => 'customer', 'id' => 4219, 'externalId' => '4', @@ -2072,20 +2074,20 @@ class DataHistoryRetailCrm 'vip' => false, 'bad' => false, 'site' => 'woocommerce', - 'contragent' => array( + 'contragent' => [ 'contragentType' => 'individual', - ), - 'tags' => array(), + ], + 'tags' => [], 'marginSumm' => 0, 'totalSumm' => 0, 'averageSumm' => 0, 'ordersCount' => 0, 'costSumm' => 0, - 'customFields' => array( + 'customFields' => [ 'galkatrue' => true, - ), + ], 'personalDiscount' => 0, - 'address' => array( + 'address' => [ 'id' => 3130, 'index' => '344091', 'countryIso' => 'RU', @@ -2093,67 +2095,67 @@ class DataHistoryRetailCrm 'regionId' => 47, 'city' => 'Валдгейм', 'text' => 'упцупуцйпуц, йцавафыафыафыафы', - ), + ], 'firstName' => 'psycho913', 'lastName' => 'psycho913', 'email' => 'psycho913@example.com', - 'phones' => array( - array( + 'phones' => [ + [ 'number' => '9135487458709', - ), - ), - ); + ], + ], + ]; } public static function get_another_corporate_for_order() { - return array( + return [ 'type' => 'customer_corporate', 'id' => 4303, 'nickName' => 'Another Test Legal Entity', - 'mainAddress' => array( + 'mainAddress' => [ 'id' => 3177, 'name' => 'Test Address', - ), + ], 'createdAt' => '2020-06-05 16:34:05', 'managerId' => 27, 'vip' => false, 'bad' => false, 'site' => 'woocommerce', - 'tags' => array(), + 'tags' => [], 'marginSumm' => 0, 'totalSumm' => 0, 'averageSumm' => 0, 'ordersCount' => 0, - 'customFields' => array( + 'customFields' => [ 'galkatrue' => true, - ), + ], 'personalDiscount' => 0, - 'mainCustomerContact' => array( + 'mainCustomerContact' => [ 'id' => 748, - 'customer' => array( + 'customer' => [ 'id' => 4304, - ), - 'companies' => array( - array( + ], + 'companies' => [ + [ 'id' => 110, - 'company' => array( + 'company' => [ 'id' => 621, 'name' => 'TestCompany3428769', - ), - ), - ), - ), - 'mainCompany' => array( + ], + ], + ], + ], + 'mainCompany' => [ 'id' => 621, 'name' => 'TestCompany3428769', - ), - ); + ], + ]; } public static function get_another_contact_for_order() { - return array( + return [ 'type' => 'customer', 'id' => 4304, 'isContact' => true, @@ -2161,19 +2163,19 @@ class DataHistoryRetailCrm 'vip' => false, 'bad' => false, 'site' => 'woocommerce', - 'tags' => array(), + 'tags' => [], 'marginSumm' => 0, 'totalSumm' => 0, 'averageSumm' => 0, 'ordersCount' => 0, 'personalDiscount' => 0, - 'segments' => array(), + 'segments' => [], 'firstName' => 'Tester4867', 'lastName' => 'Tester4867', 'patronymic' => 'Tester4867', 'sex' => 'male', 'email' => 'tester4867@example.com', - 'phones' => array(), - ); + 'phones' => [], + ]; } } diff --git a/tests/helpers/class-wc-retailcrm-test-case-helper.php b/tests/helpers/class-wc-retailcrm-test-case-helper.php index e8a75c2..0ebe160 100644 --- a/tests/helpers/class-wc-retailcrm-test-case-helper.php +++ b/tests/helpers/class-wc-retailcrm-test-case-helper.php @@ -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"); } } diff --git a/tests/test-wc-retailcrm-history.php b/tests/test-wc-retailcrm-history.php index 83dbf73..8d555d6 100644 --- a/tests/test-wc-retailcrm-history.php +++ b/tests/test-wc-retailcrm-history.php @@ -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() diff --git a/tests/test-wc-retailcrm-orders.php b/tests/test-wc-retailcrm-orders.php index a30bd1c..298daaf 100644 --- a/tests/test-wc-retailcrm-orders.php +++ b/tests/test-wc-retailcrm-orders.php @@ -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();