diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6f2673d..3d3090b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/VERSION b/VERSION
index 101d404..d9167bb 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-4.6.4
\ No newline at end of file
+4.6.5
\ No newline at end of file
diff --git a/doc/1.Setup/Custom fields settings.md b/doc/1.Setup/Custom fields settings.md
index 7b22957..74691da 100644
--- a/doc/1.Setup/Custom fields settings.md
+++ b/doc/1.Setup/Custom fields settings.md
@@ -18,3 +18,20 @@
На стороне CRM доступные пользовательские поля можно увидеть перейдя в **Настройки - Системные - Пользовательские поля.**
+
+В версии 4.6.5 добавлен функционал для передачи мета полей CMS в некоторые стандартные поля CRM.
+
+Список стандартных полей CRM доступных для передачи данных:
+* Имя
+* Фамилия
+* Телефон
+* E-mail
+* Адрес
+* Город
+* Индекс
+* Регион
+* Теги (доступно только для клиентов)
+* Комментарий клиента (доступно только для заказов)
+* Комментарий менеджера (доступно только для заказов)
+
+**Важно! Передача мета полей WC в стандартные поля CRM реализована только из CMS в CRM, обратная синхронизация не предусмотрена.**
\ No newline at end of file
diff --git a/doc/1.Setup/Settings .md b/doc/1.Setup/Settings.md
similarity index 100%
rename from doc/1.Setup/Settings .md
rename to doc/1.Setup/Settings.md
diff --git a/resources/pot/retailcrm-es_ES.pot b/resources/pot/retailcrm-es_ES.pot
index aac0ee1..e50bb7c 100644
--- a/resources/pot/retailcrm-es_ES.pot
+++ b/resources/pot/retailcrm-es_ES.pot
@@ -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"
diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot
index 1176f76..9923dcc 100644
--- a/resources/pot/retailcrm-ru_RU.pot
+++ b/resources/pot/retailcrm-ru_RU.pot
@@ -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"
diff --git a/src/assets/default/default_meta_fields.txt b/src/assets/default/default_meta_fields.txt
index f237e8f..d69a323 100644
--- a/src/assets/default/default_meta_fields.txt
+++ b/src/assets/default/default_meta_fields.txt
@@ -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
diff --git a/src/assets/js/retailcrm-meta-fields.js b/src/assets/js/retailcrm-meta-fields.js
index c8e13d2..dff9139 100644
--- a/src/assets/js/retailcrm-meta-fields.js
+++ b/src/assets/js/retailcrm-meta-fields.js
@@ -295,6 +295,16 @@ jQuery(function () {
.attr('value', key)
.text(value));
});
+
+ jQuery(`#customFields-${entity}-${index}`)
+ .append(jQuery(``));
+
+ jQuery.each(data.crmDefault, function(key, value) {
+ jQuery(`#default-${entity}-${index}-crm-fields`)
+ .append(jQuery('')
+ .attr('value', key)
+ .text(value));
+ });
}
RetailcrmMetaFields.prototype.addPairSelects = function (element, entity, data, index) {
diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php
index d0baafb..678a590 100644
--- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php
+++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php
@@ -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;
}
diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php
index 9078b90..4cd4be9 100644
--- a/src/include/class-wc-retailcrm-base.php
+++ b/src/include/class-wc-retailcrm-base.php
@@ -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'),
+ ];
+ }
}
}
diff --git a/src/include/class-wc-retailcrm-customers.php b/src/include/class-wc-retailcrm-customers.php
index c6c34a3..a7b59ed 100644
--- a/src/include/class-wc-retailcrm-customers.php
+++ b/src/include/class-wc-retailcrm-customers.php
@@ -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;
}
}
diff --git a/src/include/class-wc-retailcrm-orders.php b/src/include/class-wc-retailcrm-orders.php
index 1977b9d..e543c2c 100644
--- a/src/include/class-wc-retailcrm-orders.php
+++ b/src/include/class-wc-retailcrm-orders.php
@@ -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;
}
}
diff --git a/src/languages/retailcrm-es_ES.mo b/src/languages/retailcrm-es_ES.mo
index b85f085..e638036 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 f4b9b21..c8531f5 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 e8d4677..dd46a75 100644
--- a/src/readme.txt
+++ b/src/readme.txt
@@ -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
diff --git a/src/retailcrm.php b/src/retailcrm.php
index e586d95..bebd20c 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.6.4
+ * Version: 4.6.5
* Tested up to: 6.0
* WC requires at least: 5.4
* WC tested up to: 6.9
diff --git a/src/uninstall.php b/src/uninstall.php
index 5c601aa..67f2a1a 100644
--- a/src/uninstall.php
+++ b/src/uninstall.php
@@ -16,7 +16,7 @@
*
* @link https://wordpress.org/plugins/woo-retailcrm/
*
- * @version 4.6.4
+ * @version 4.6.5
*
* @package RetailCRM
*/
diff --git a/tests/helpers/class-wc-retailcrm-test-case-helper.php b/tests/helpers/class-wc-retailcrm-test-case-helper.php
index 1e2e2ed..786d556 100644
--- a/tests/helpers/class-wc-retailcrm-test-case-helper.php
+++ b/tests/helpers/class-wc-retailcrm-test-case-helper.php
@@ -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',
];
diff --git a/tests/test-wc-retailcrm-customers.php b/tests/test-wc-retailcrm-customers.php
index 7d0db15..001cba1 100644
--- a/tests/test-wc-retailcrm-customers.php
+++ b/tests/test-wc-retailcrm-customers.php
@@ -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);
diff --git a/tests/test-wc-retailcrm-orders.php b/tests/test-wc-retailcrm-orders.php
index 2b904a6..c1889b6 100644
--- a/tests/test-wc-retailcrm-orders.php
+++ b/tests/test-wc-retailcrm-orders.php
@@ -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)