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

ref #89652 Transferring WC meta fields to standard CRM order and customer fields

This commit is contained in:
Uryvskiy Dima 2023-06-08 12:24:49 +03:00 committed by GitHub
commit d43f45196a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 234 additions and 28 deletions

View File

@ -1,4 +1,7 @@
## 2022-05-26 4.6.4
## 2022-06-08 4.6.5
* Transferring WC meta fields to standard CRM order and customer fields
## 2022-05-30 4.6.4
* Optimizing unloading of stock
## 2022-05-29 4.6.3

View File

@ -1 +1 @@
4.6.4
4.6.5

View File

@ -18,3 +18,20 @@
На стороне CRM доступные пользовательские поля можно увидеть перейдя в **Настройки - Системные - Пользовательские поля.**
В версии 4.6.5 добавлен функционал для передачи мета полей CMS в некоторые стандартные поля CRM.
Список стандартных полей CRM доступных для передачи данных:
* Имя
* Фамилия
* Телефон
* E-mail
* Адрес
* Город
* Индекс
* Регион
* Теги (доступно только для клиентов)
* Комментарий клиента (доступно только для заказов)
* Комментарий менеджера (доступно только для заказов)
**Важно! Передача мета полей WC в стандартные поля CRM реализована только из CMS в CRM, обратная синхронизация не предусмотрена.**

View File

@ -378,3 +378,39 @@ msgstr "Importar los carritos abandonados"
msgid "Enable if you want to in CRM abandoned shopping carts were unloaded"
msgstr "Habilitar Si desea que en CRM se descargaron las cestas abandonadas de los compradores"
msgid "firstName"
msgstr "Nombre"
msgid "lastName"
msgstr "Apellido"
msgid "phone"
msgstr "Número de teléfono"
msgid "tags"
msgstr "Etiquetas"
msgid "customerComment"
msgstr "Comentario del cliente"
msgid "managerComment"
msgstr "Comentario del asesor"
msgid "email"
msgstr "E-mail"
msgid "addressText"
msgstr "Dirección"
msgid "addressCity"
msgstr "Ciudad"
msgid "addressIndex"
msgstr "Código postal"
msgid "addressRegion"
msgstr "Región"
msgid "Standard CRM fields"
msgstr "Los campos del CRM por defecto"

View File

@ -387,3 +387,39 @@ msgstr "Выгружать брошенные корзины"
msgid "Enable if you want to in CRM abandoned shopping carts were unloaded"
msgstr "Включите, если хотите, чтобы в CRM выгружались брошенные корзины покупателей"
msgid "firstName"
msgstr "Имя"
msgid "lastName"
msgstr "Фамилия"
msgid "phone"
msgstr "Телефон"
msgid "tags"
msgstr "Теги"
msgid "customerComment"
msgstr "Комментарий клиента"
msgid "managerComment"
msgstr "Комментарий менеджера"
msgid "email"
msgstr "E-mail"
msgid "addressText"
msgstr "Адрес"
msgid "addressCity"
msgstr "Город"
msgid "addressIndex"
msgstr "Индекс"
msgid "addressRegion"
msgstr "Регион"
msgid "Standard CRM fields"
msgstr "Стандартные поля CRM"

View File

@ -100,7 +100,6 @@ _used_by
attribute_logo
attribute_pa_color
attribute_pa_size
is_vat_exempt
total_sales
coupon_amount
date_expires
@ -147,7 +146,6 @@ first_name
last_name
last_update
locale
nickname
paying_customer
rich_editing
session_tokens

View File

@ -295,6 +295,16 @@ jQuery(function () {
.attr('value', key)
.text(value));
});
jQuery(`#customFields-${entity}-${index}`)
.append(jQuery(`<optgroup id=default-${entity}-${index}-crm-fields label = '${data.tr_default_crm_fields}'></optgroup>`));
jQuery.each(data.crmDefault, function(key, value) {
jQuery(`#default-${entity}-${index}-crm-fields`)
.append(jQuery('<option></option>')
.attr('value', key)
.text(value));
});
}
RetailcrmMetaFields.prototype.addPairSelects = function (element, entity, data, index) {

View File

@ -203,11 +203,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
continue;
}
if (
isset($crmDelivery['sites'])
&& $crmDelivery['sites'] !== []
&& in_array($crmSite, $crmDelivery['sites']) === false
) {
if (!empty($crmDelivery['sites']) && in_array($crmSite, $crmDelivery['sites']) === false) {
continue;
}
@ -252,11 +248,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
continue;
}
if (
isset($crmPayment['sites'])
&& $crmPayment['sites'] !== []
&& in_array($crmSite, $crmPayment['sites']) === false
) {
if (!empty($crmPayment['sites']) && in_array($crmSite, $crmPayment['sites']) === false) {
continue;
}

View File

@ -706,6 +706,8 @@ if (!class_exists('WC_Retailcrm_Base')) {
$customerMetaData = $this->getMetaData('user');
$orderCustomFields = $this->getCustomFields('order');
$customerCustomFields = $this->getCustomFields('customer');
$defaultCrmOrderFields = $this->getDefaultCrmOrderFields();
$defaultCrmCustomerFields = $this->getDefaultCrmCustomerFields();
$translate = [
'tr_lb_order' => __('Custom fields for order', 'retailcrm'),
@ -715,8 +717,18 @@ if (!class_exists('WC_Retailcrm_Base')) {
echo json_encode(
[
'order' => ['custom' => $orderCustomFields, 'meta' => $orderMetaData],
'customer' => ['custom' => $customerCustomFields, 'meta' => $customerMetaData],
'order' => [
'meta' => $orderMetaData,
'custom' => $orderCustomFields,
'crmDefault' => $defaultCrmOrderFields,
'tr_default_crm_fields' => __('Standard CRM fields', 'retailcrm'),
],
'customer' => [
'meta' => $customerMetaData,
'custom' => $customerCustomFields,
'crmDefault' => $defaultCrmCustomerFields,
'tr_default_crm_fields' => __('Standard CRM fields', 'retailcrm'),
],
'translate' => $translate,
]
);
@ -830,5 +842,36 @@ if (!class_exists('WC_Retailcrm_Base')) {
}
}
}
private function getDefaultCrmOrderFields()
{
return [
'default-crm-field#firstName' => __('firstName', 'retailcrm'),
'default-crm-field#lastName' => __('lastName', 'retailcrm'),
'default-crm-field#phone' => __('phone', 'retailcrm'),
'default-crm-field#email' => __('email', 'retailcrm'),
'default-crm-field#delivery#address#index' => __('addressIndex', 'retailcrm'),
'default-crm-field#delivery#address#region' => __('addressRegion', 'retailcrm'),
'default-crm-field#delivery#address#city' => __('addressCity', 'retailcrm'),
'default-crm-field#delivery#address#text' => __('addressText', 'retailcrm'),
'default-crm-field#customerComment' => __('customerComment', 'retailcrm'),
'default-crm-field#managerComment' => __('managerComment', 'retailcrm'),
];
}
private function getDefaultCrmCustomerFields()
{
return [
'default-crm-field#firstName' => __('firstName', 'retailcrm'),
'default-crm-field#lastName' => __('lastName', 'retailcrm'),
'default-crm-field#phones' => __('phone', 'retailcrm'),
'default-crm-field#email' => __('email', 'retailcrm'),
'default-crm-field#address#index' => __('addressIndex', 'retailcrm'),
'default-crm-field#address#region' => __('addressRegion', 'retailcrm'),
'default-crm-field#address#city' => __('addressCity', 'retailcrm'),
'default-crm-field#address#text' => __('addressText', 'retailcrm'),
'default-crm-field#tags' => __('tags', 'retailcrm'),
];
}
}
}

View File

@ -438,7 +438,26 @@ if (!class_exists('WC_Retailcrm_Customers')) :
foreach ($this->customFields as $metaKey => $customKey) {
$metaValue = $customer->get_meta($metaKey);
if (!empty($metaValue)) {
if (empty($metaValue)) {
continue;
}
if (strpos($customKey, 'default-crm-field') !== false) {
$crmField = explode('#', $customKey);
if (count($crmField) === 2 && isset($crmField[1])) {
if ($crmField[1] === 'phones') {
$customerData[$crmField[1]][] = ['number' => $metaValue];
} elseif ($crmField[1] === 'tags') {
$customerData['addTags'][] = $metaValue;
} else {
$customerData[$crmField[1]] = $metaValue;
}
} elseif (isset($crmField[1], $crmField[2])) {
// For customer delivery
$customerData[$crmField[1]][$crmField[2]] = $metaValue;
}
} else {
$customerData['customFields'][$customKey] = $metaValue;
}
}

View File

@ -416,7 +416,20 @@ if (!class_exists('WC_Retailcrm_Orders')) :
foreach ($this->customFields as $metaKey => $customKey) {
$metaValue = $order->get_meta($metaKey);
if (!empty($metaValue)) {
if (empty($metaValue)) {
continue;
}
if (strpos($customKey, 'default-crm-field') !== false) {
$crmField = explode('#', $customKey);
if (count($crmField) === 2 && isset($crmField[1])) {
$orderData[$crmField[1]] = $metaValue;
} elseif (isset($crmField[1], $crmField[2], $crmField[3])) {
// For order delivery
$orderData[$crmField[1]][$crmField[2]][$crmField[3]] = $metaValue;
}
} else {
$orderData['customFields'][$customKey] = $metaValue;
}
}

Binary file not shown.

Binary file not shown.

View File

@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla
Requires PHP: 7.0
Requires at least: 5.3
Tested up to: 6.0
Stable tag: 4.6.4
Stable tag: 4.6.5
License: GPLv1 or later
License URI: http://www.gnu.org/licenses/gpl-1.0.html
@ -82,6 +82,9 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i
== Changelog ==
= 4.6.5 =
* Transferring WC meta fields to standard CRM order and customer fields
= 4.6.4 =
* Optimizing unloading of stock

View File

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

View File

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

View File

@ -61,8 +61,22 @@ class WC_Retailcrm_Test_Case_Helper extends WC_Unit_Test_Case
'update_number' => 'yes',
'debug_mode' => 'yes',
'debug-info' => '',
'order-meta-data-retailcrm' => json_encode(['woo_order' => 'crm_order']),
'customer-meta-data-retailcrm' => json_encode(['woo_customer' => 'crm_customer']),
'order-meta-data-retailcrm' => json_encode(
[
'woo_order' => 'crm_order',
'crm_phone' => 'default-crm-field#phone',
'crm_address_text' => 'default-crm-field#delivery#address#text',
'crm_customer_comment' => 'default-crm-field#customerComment',
]
),
'customer-meta-data-retailcrm' => json_encode(
[
'woo_customer' => 'crm_customer',
'_crm_tags' => 'default-crm-field#tags',
'_crm_phone' => 'default-crm-field#phones',
'_crm_address_text' => 'default-crm-field#address#text',
]
),
'product_description' => 'full',
];

View File

@ -61,21 +61,27 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper
$this->setMockResponse($this->apiMock, 'customersCorporateCreate', true);
$this->customer = new WC_Customer();
$this->customer->set_first_name('Tester');
$this->customer->set_last_name('Tester');
$this->customer->set_email(uniqid(md5(date('Y-m-d H:i:s'))) . '@mail.com');
$this->customer->set_billing_email($this->customer->get_email());
$this->customer->set_password('password');
$this->customer->set_billing_phone('89000000000');
$this->customer->set_billing_company('test_company');
$this->customer->set_billing_state('test_state');
$this->customer->set_billing_postcode('123456');
$this->customer->set_billing_city('test_city');
$this->customer->set_billing_address_1('test_address_line');
$this->customer->set_date_created(date('Y-m-d H:i:s'));
$this->customer->save();
update_user_meta($this->customer->get_id(), 'woo_customer', 'test_custom_fields');
$customerId = $this->customer->get_id();
add_user_meta($customerId, 'woo_customer', 'test_custom_fields');
add_user_meta($customerId, '_crm_phone', '1111122222');
add_user_meta($customerId, '_crm_tags', 'tags_test');
add_user_meta($customerId, '_crm_address_text', 'crm_address_text_test');
}
/**
@ -113,6 +119,11 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertNotEmpty($customer['email']);
$this->assertEquals($customer['firstName'], $this->customer->get_first_name());
$this->assertEquals($customer['email'], $this->customer->get_email());
//Check transferring WC meta to CRM customer fields
$this->assertEquals($customer['addTags'][0], 'tags_test');
$this->assertEquals($customer['address']['text'], 'crm_address_text_test');
$this->assertEquals($customer['phones'][0]['number'], '1111122222');
$this->assertEquals($customer['customFields']['crm_customer'], 'test_custom_fields');
} else {
$this->assertEquals(null, $id);

View File

@ -92,17 +92,20 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertArrayHasKey('address', $orderData['delivery']);
$this->assertArrayHasKey('index', $orderData['delivery']['address']);
$this->assertArrayHasKey('city', $orderData['delivery']['address']);
$this->assertArrayHasKey('text', $orderData['delivery']['address']);
$this->assertEquals($this->order->get_id(), $orderData['externalId']);
$this->assertEquals('status1', $orderData['status']);
$this->assertEquals('Jeroen', $orderData['firstName']);
$this->assertEquals('Sormani', $orderData['lastName']);
$this->assertEquals('admin@example.org', $orderData['email']);
$this->assertEquals('US', $orderData['countryIso']);
if (mb_strlen($orderData['delivery']['address']['index']) === 6) {
$this->assertEquals('123456', $orderData['delivery']['address']['index']);
} else {
$this->assertEquals('12345', $orderData['delivery']['address']['index']);
}
$this->assertEquals('WooCity', $orderData['delivery']['address']['city']);
$this->assertEquals('delivery', $orderData['delivery']['code']);
@ -111,7 +114,12 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertArrayHasKey('type', $orderData['payments'][0]);
$this->assertArrayHasKey('externalId', $orderData['payments'][0]);
$this->assertEquals('payment1', $orderData['payments'][0]['type']);
//Check transferring WC meta to CRM order fields
$this->assertEquals($orderData['phone'], '1111122222');
$this->assertEquals($orderData['customFields']['crm_order'], 'test_custom_fields');
$this->assertEquals($orderData['customerComment'], 'crm_customer_comment_test');
$this->assertEquals($orderData['delivery']['address']['text'], 'crm_address_text_test');
} else {
$this->assertEquals(null, $order);
}
@ -242,10 +250,8 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertEquals('US', $orderData['countryIso']);
$this->assertEquals(0, $orderData['discountManualAmount']);
$this->assertEquals(0, $orderData['discountManualPercent']);
$this->assertEquals($orderData['customFields']['crm_order'], 'test_custom_fields');
if (mb_strlen($orderData['delivery']['address']['index']) === 6) {
$this->assertEquals('123456', $orderData['delivery']['address']['index']);
} else {
@ -599,7 +605,12 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->order->save();
update_post_meta($this->order->get_id(), 'woo_order', 'test_custom_fields');
$orderId = $this->order->get_id();
update_post_meta($orderId, 'woo_order', 'test_custom_fields');
update_post_meta($orderId, 'crm_phone', '1111122222');
update_post_meta($orderId, 'crm_address_text', 'crm_address_text_test');
update_post_meta($orderId, 'crm_customer_comment', 'crm_customer_comment_test');
}
private function getResponseData($externalId)