diff --git a/doc/1.Setup/Custom fields settings.md b/doc/1.Setup/Custom fields settings.md
new file mode 100644
index 0000000..7b22957
--- /dev/null
+++ b/doc/1.Setup/Custom fields settings.md
@@ -0,0 +1,20 @@
+### Пользовательские поля
+
+В настройках модуля есть возможность настроить передачу пользовательских полей из CMS в CRM и обратно. Для этого необходимо настроить соответствие между мета полями CMS и пользовательскими полями CRM.
+
+Слева располагаются мета поля CMS, справа пользовательские поля CRM. В выпадающем списке слева нужно выбрать мета поля CMS, в выпадающем списке справа нужно выбрать пользовательское поле CRM и таким образом сопоставить их.
+
+Пользовательские поля разбиты на две группы для заказов "Custom fields for order" и для клиентов "Custom fields for customer".
+
+При нажатии на кнопку "Custom fields for order/customer" будет добавлены новые списки для выбора. Количество списков не может быть больше количества мета полей CMS или пользовательских полей CRM. Поэтому когда добавили максимальное число списков, кнопка добавления пропадает. Для каждой группы предусмотрена своя кнопка добавления.
+
+Обратите внимание, что значения не должны повторяться, т.е. для двух мета полей CMS, не может быть выбрана одно и то же пользовательское поле CRM. Необходимо выбирать 1 к 1. Если вдруг выбрать значение которое уже используется, будет показано предупреждающее уведомление, выбранный список начнет мигать красным и в этом списке будет установленно значение по умолчанию "Select value".
+
+Сопоставление можно удалить, если нажать на крестик справа от списка пользовательский полей CRM.
+
+Для сохранения выбранных сопоставлений необходимо нажать на кнопку "Сохранить изменения" в конце страницы настроек.
+
+Также в списке значений для сопоставления выводятся **только Активные в CRM пользовательские поля**.
+
+На стороне CRM доступные пользовательские поля можно увидеть перейдя в **Настройки - Системные - Пользовательские поля.**
+
diff --git a/resources/pot/retailcrm-es_ES.pot b/resources/pot/retailcrm-es_ES.pot
index b2e7d42..79328cd 100644
--- a/resources/pot/retailcrm-es_ES.pot
+++ b/resources/pot/retailcrm-es_ES.pot
@@ -274,3 +274,36 @@ msgstr "Activar el modo de depuración en el módulo"
msgid "Is required to enable debug mode for advanced logs"
msgstr "Se requiere el modo de depuración para habilitar el registro avanzado de logs"
+msgid "Custom fields"
+msgstr "Campos personalizados"
+
+msgid "Select value"
+msgstr "Selecciona un valor"
+
+msgid "Custom fields for order"
+msgstr "Campos de pedido personalizados"
+
+msgid "Custom fields for customer"
+msgstr "Campos de clientes personalizados"
+
+msgid "Add new select for order"
+msgstr "Añadir"
+
+msgid "Add new select for customer"
+msgstr "Añadir"
+
+msgid "This option is disabled"
+msgstr "Opción desactivada"
+
+msgid "Cron launches"
+msgstr "Tareas de cron"
+
+msgid "Generation ICML"
+msgstr "Generación del catálogo"
+
+msgid "Syncing history"
+msgstr "Sincronización del historial"
+
+msgid "Syncing inventories"
+msgstr "Sincronización de inventario"
+
diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot
index 2c4e3f7..99e428e 100644
--- a/resources/pot/retailcrm-ru_RU.pot
+++ b/resources/pot/retailcrm-ru_RU.pot
@@ -283,5 +283,38 @@ msgstr "Активировать режим отладки в модуле"
msgid "Is required to enable debug mode for advanced logs"
msgstr "Требуется включить режим отладки для расширенного логирования"
+msgid "Custom fields"
+msgstr "Пользовательские поля"
+
+msgid "Select value"
+msgstr "Выберите значение"
+
+msgid "Custom fields for order"
+msgstr "Пользовательские поля для заказа"
+
+msgid "Custom fields for customer"
+msgstr "Пользовательские поля для клиента"
+
+msgid "Add new select for order"
+msgstr "Добавить"
+
+msgid "Add new select for customer"
+msgstr "Добавить"
+
+msgid "This option is disabled"
+msgstr "Опция отключена"
+
+msgid "Cron launches"
+msgstr "Работающие крон задачи"
+
+msgid "Generation ICML"
+msgstr "Генерация каталога"
+
+msgid "Syncing history"
+msgstr "Синхронизация истории"
+
+msgid "Syncing inventories"
+msgstr "Синхронизация запасов"
+
diff --git a/src/assets/css/meta-fields.css b/src/assets/css/meta-fields.css
new file mode 100644
index 0000000..f4e7e4b
--- /dev/null
+++ b/src/assets/css/meta-fields.css
@@ -0,0 +1,59 @@
+.retailcrm-meta-select {
+ margin-right: 25px !important;
+ float:left !important;
+ width: 200px !important;
+ text-align-last: center;
+ border: 2px solid #2271b1;
+}
+
+.retailcrm-select-pair {
+ margin-bottom: 30px;
+}
+
+.retailcrm-order-label, .retailcrm-customer-label {
+ display: block;
+ font-size: 14px !important;
+ margin-top: 16px;
+ margin-bottom: 10px;
+}
+
+.add-new-select-retailcrm {
+ display:block;
+ width: 200px !important;
+ height: 34px;
+ color: #4169e1;
+ border-color: #4169e1;
+ background: #f6f7f7;
+ vertical-align: top;
+ margin-top: 16px;
+ margin-left: 128px;
+ margin-bottom: 10px;
+}
+
+.delete-select-retailcrm {
+ display: block;
+ width: 34px;
+ height: 34px;
+ --weight: 0.5px;
+ --aa: 0.5px; /* anti-aliasing */
+ --color: #4169e1;
+ border-color: #4169e1;
+ background: #f6f7f7;
+ padding: 0;
+ background:
+ linear-gradient(45deg, transparent calc(50% - var(--weight) - var(--aa)), var(--color) calc(50% - var(--weight)), var(--color) calc(50% + var(--weight)), transparent calc(50% + var(--weight) + var(--aa))),
+ linear-gradient(-45deg, transparent calc(50% - var(--weight) - var(--aa)), var(--color) calc(50% - var(--weight)), var(--color) calc(50% + var(--weight)), transparent calc(50% + var(--weight) + var(--aa)));
+}
+
+
+.red-selected-retailcrm {
+ border: solid 3px red !important;
+ animation: 2s blinker linear infinite;
+ #transition: border-width 0.6s linear;
+}
+
+@keyframes blinker {
+ 0% { opacity: 1.0; }
+ 50% { opacity: 0.3; }
+ 100% { opacity: 1.0; }
+}
\ No newline at end of file
diff --git a/src/assets/css/meta-fields.min.css b/src/assets/css/meta-fields.min.css
new file mode 100644
index 0000000..856d60b
--- /dev/null
+++ b/src/assets/css/meta-fields.min.css
@@ -0,0 +1 @@
+.retailcrm-meta-select{margin-right:25px!important;float:left!important;width:200px!important;text-align-last:center;border:2px solid #2271b1}.retailcrm-select-pair{margin-bottom:30px}.retailcrm-customer-label,.retailcrm-order-label{display:block;font-size:14px!important;margin-top:16px;margin-bottom:10px}.add-new-select-retailcrm{display:block;width:200px!important;height:34px;color:#4169e1;border-color:#4169e1;background:#f6f7f7;vertical-align:top;margin-top:16px;margin-left:128px;margin-bottom:10px}.delete-select-retailcrm{display:block;width:34px;height:34px;--weight:0.5px;--aa:0.5px;--color:#4169e1;border-color:#4169e1;background:#f6f7f7;padding:0;background:linear-gradient(45deg,transparent calc(50% - var(--weight) - var(--aa)),var(--color) calc(50% - var(--weight)),var(--color) calc(50% + var(--weight)),transparent calc(50% + var(--weight) + var(--aa))),linear-gradient(-45deg,transparent calc(50% - var(--weight) - var(--aa)),var(--color) calc(50% - var(--weight)),var(--color) calc(50% + var(--weight)),transparent calc(50% + var(--weight) + var(--aa)))}.red-selected-retailcrm{border:solid 3px red!important;animation:2s blinker linear infinite}@keyframes blinker{0%{opacity:1}50%{opacity:.3}100%{opacity:1}}
\ No newline at end of file
diff --git a/src/assets/css/progress-bar.css b/src/assets/css/progress-bar.css
index 5b05629..12534e8 100644
--- a/src/assets/css/progress-bar.css
+++ b/src/assets/css/progress-bar.css
@@ -21,7 +21,7 @@
box-sizing: border-box;
}
-.retail-hidden {
+.retailcrm-hidden {
display: none !important;
}
diff --git a/src/assets/css/progress-bar.min.css b/src/assets/css/progress-bar.min.css
index b8539e1..d109360 100644
--- a/src/assets/css/progress-bar.min.css
+++ b/src/assets/css/progress-bar.min.css
@@ -1 +1,5 @@
-.retail-progress{border-radius:18px;border:1px solid rgba(122,122,122,.15);width:400px;height:18px;overflow:hidden;transition:height .25s ease}.retail-progress__loader{width:0;border-radius:18px;background:#4169e1;color:#fff;text-align:center;padding:0 30px;font-size:18px;font-weight:600;transition:width .4s ease-in;line-height:18px;box-sizing:border-box}.retail-hidden{display:none!important}.retail-count-data-upload{margin-bottom:20px;size:30px;color:#4169e1;font-weight:700}
\ No newline at end of file
+<<<<<<< HEAD
+.retail-progress{border-radius:18px;border:1px solid rgba(122,122,122,.15);width:400px;height:18px;overflow:hidden;transition:height .25s ease}.retail-progress__loader{width:0;border-radius:18px;background:#4169e1;color:#fff;text-align:center;padding:0 30px;font-size:18px;font-weight:600;transition:width .4s ease-in;line-height:18px;box-sizing:border-box}.retail-hidden{display:none!important}.retail-count-data-upload{margin-bottom:20px;size:30px;color:#4169e1;font-weight:700}
+=======
+.retail-progress{border-radius:18px;border:1px solid rgba(122,122,122,.15);width:400px;height:18px;overflow:hidden;transition:height .25s ease}.retail-progress__loader{width:0;border-radius:18px;background:#4169e1;color:#fff;text-align:center;padding:0 30px;font-size:18px;font-weight:600;transition:width .4s ease-in;line-height:18px;box-sizing:border-box}.retailcrm-hidden{display:none!important}.retail-count-data-upload{margin-bottom:20px;size:30px;color:#4169e1;font-weight:700}
+>>>>>>> Add mapping metadata fields in settings
diff --git a/src/assets/default/default_meta_fields.txt b/src/assets/default/default_meta_fields.txt
new file mode 100644
index 0000000..f237e8f
--- /dev/null
+++ b/src/assets/default/default_meta_fields.txt
@@ -0,0 +1,180 @@
+_backorders
+_billing_address_1
+_billing_address_2
+_billing_address_index
+_billing_city
+_billing_company
+_billing_country
+_billing_email
+_billing_first_name
+_billing_last_name
+_billing_phone
+_billing_postcode
+_billing_state
+_button_text
+_cart_discount
+_cart_discount_tax
+_cart_hash
+_children
+_completed_date
+_created_via
+_customer_ip_address
+_customer_user
+_customer_user_agent
+_date_completed
+_date_paid
+_download_expiry
+_download_limit
+_download_permissions_granted
+_downloadable
+_downloadable_files
+_edit_last
+_edit_lock
+_manage_stock
+_new_order_email_sent
+_order_currency
+_order_key
+_order_shipping
+_order_shipping_tax
+_order_stock_reduced
+_order_tax
+_order_total
+_order_version
+_paid_date
+_payment_method
+_payment_method_title
+_price
+_prices_include_tax
+_product_attributes
+_product_image_gallery
+_product_url
+_product_version
+_recorded_coupon_usage_counts
+_recorded_sales
+_refund_amount
+_refund_reason
+_refunded_by
+_refunded_payment
+_regular_price
+_sale_price
+_shipping_address_1
+_shipping_address_2
+_shipping_address_index
+_shipping_city
+_shipping_company
+_shipping_country
+_shipping_first_name
+_shipping_last_name
+_shipping_postcode
+_shipping_state
+_sku
+_sold_individually
+_stock
+_stock_status
+_stripe_charge_captured
+_stripe_currency
+_stripe_customer_id
+_stripe_fee
+_stripe_intent_id
+_stripe_net
+_stripe_source_id
+_tax_class
+_tax_status
+_thumbnail_id
+_transaction_id
+_variation_description
+_virtual
+_wc_attachment_source
+_wc_average_rating
+_wc_review_count
+_wp_attached_file
+_wp_attachment_metadata
+_wp_desired_post_slug
+_wp_old_slug
+_wp_page_template
+_wp_trash_meta_comments_status
+_wp_trash_meta_status
+_wp_trash_meta_time
+_wpcom_is_markdown
+_used_by
+attribute_logo
+attribute_pa_color
+attribute_pa_size
+is_vat_exempt
+total_sales
+coupon_amount
+date_expires
+discount_type
+exclude_sale_items
+free_shipping
+individual_use
+is_vat_exempt
+limit_usage_to_x_items
+usage_count
+usage_limit
+usage_limit_per_user
+_shipping_phone
+
+## Customer
+
+_last_order
+_order_count
+_woocommerce_persistent_cart_1
+_woocommerce_tracks_anon_id
+admin_color
+billing_address_1
+billing_address_2
+billing_city
+billing_company
+billing_country
+billing_email
+billing_first_name
+billing_last_name
+billing_phone
+billing_postcode
+billing_state
+comment_shortcuts
+community-events-location
+default_password_nag
+description
+dismissed_maxmind_license_key_notice
+dismissed_no_secure_connection_notice
+dismissed_regenerating_thumbnails_notice
+dismissed_update_notice
+dismissed_wc_admin_notice
+dismissed_wp_pointers
+first_name
+last_name
+last_update
+locale
+nickname
+paying_customer
+rich_editing
+session_tokens
+shipping_address_1
+shipping_address_2
+shipping_city
+shipping_company
+shipping_country
+shipping_first_name
+shipping_last_name
+shipping_method
+shipping_phone
+shipping_postcode
+shipping_state
+show_admin_bar_front
+show_welcome_panel
+syntax_highlighting
+use_ssl
+wc_last_active
+woocommerce_admin_activity_panel_inbox_last_read
+wp_capabilities
+wp_dashboard_quick_press_last_post_id
+wp_product_import_error_log
+wp_user_level
+wp_user-settings
+wp_user-settings-time
+wp_woocommerce_product_import_mapping
+closedpostboxes_shop_order
+metaboxhidden_shop_order
+wp__stripe_customer_id
diff --git a/src/assets/js/retailcrm-cron-info.js b/src/assets/js/retailcrm-cron-info.js
index 44d10d0..40c6bbe 100644
--- a/src/assets/js/retailcrm-cron-info.js
+++ b/src/assets/js/retailcrm-cron-info.js
@@ -25,20 +25,24 @@ jQuery(function () {
_this.icml = response.icml;
_this.inventories = response.inventories;
- _this.displayInfoAboutCron();
-
+ _this.displayInfoAboutCron(
+ response.translate.tr_td_cron,
+ response.translate.tr_td_icml,
+ response.translate.tr_td_history,
+ response.translate.tr_td_inventories
+ );
})
}
- RetailcrmCronInfo.prototype.displayInfoAboutCron = function () {
+ RetailcrmCronInfo.prototype.displayInfoAboutCron = function (cron, icml, history, inventories) {
this.table = jQuery(this.title).next();
this.table.append('
');
this.infoTable = jQuery('tbody[class="retail-debug-info"]').get(0);
- jQuery(this.infoTable).append("" + "Cron launches:" + " |
");
- jQuery(this.infoTable).append("" + "History: " + this.history + " |
");
- jQuery(this.infoTable).append("" + "Icml: " + this.icml + " |
");
- jQuery(this.infoTable).append("" + "Inventories: " + this.inventories + " |
");
+ jQuery(this.infoTable).append("" + cron + " : " + " |
");
+ jQuery(this.infoTable).append("" + icml + " : " + this.icml + " |
");
+ jQuery(this.infoTable).append("" + history + " : " + this.history + " |
");
+ jQuery(this.infoTable).append("" + inventories + " : " + this.inventories + " |
");
}
window.RetailcrmCronInfo = RetailcrmCronInfo;
diff --git a/src/assets/js/retailcrm-export.js b/src/assets/js/retailcrm-export.js
index 31d856d..4f44c8e 100644
--- a/src/assets/js/retailcrm-export.js
+++ b/src/assets/js/retailcrm-export.js
@@ -4,7 +4,7 @@ jQuery(function () {
this.submitButton = jQuery('button[id="export-orders-submit"]').get(0);
this.selectedOrdersButton = jQuery('button[id="export_selected_orders_btn"]').get(0);
- jQuery(this.submitButton).after('', {class: 'retail-progress__loader', text: '0%'}))
window.addEventListener('beforeunload', this.confirmLeave);
diff --git a/src/assets/js/retailcrm-meta-fields.js b/src/assets/js/retailcrm-meta-fields.js
new file mode 100644
index 0000000..4504d54
--- /dev/null
+++ b/src/assets/js/retailcrm-meta-fields.js
@@ -0,0 +1,323 @@
+jQuery(function () {
+ function RetailcrmMetaFields()
+ {
+ jQuery('.order-meta-data-retailcrm').closest('tr').addClass('retailcrm-hidden')
+ jQuery('.customer-meta-data-retailcrm').closest('tr').addClass('retailcrm-hidden')
+
+ jQuery('.customer-meta-data-retailcrm').closest('tr').after('
')
+ this.insertSelects = jQuery('.retailcrm-insert-select').get(0);
+ this.orderTextArea = jQuery('.order-meta-data-retailcrm').get(0);
+ this.customerTextArea = jQuery('.customer-meta-data-retailcrm').get(0);
+ this.indexOrder = 1;
+ this.indexCustomer = 1;
+
+ if (typeof this.insertSelects === 'undefined'
+ || this.orderTextArea === 'undefined'
+ || this.customerTextArea === 'undefined'
+ ) {
+ return false;
+ }
+
+ jQuery(this.insertSelects).append(
+ `` +
+ `` +
+ `` +
+ ``
+ );
+
+ let _this = this;
+
+ if (this.orderTextArea.value === '') {
+ this.orderTextArea.value = JSON.stringify({});
+ }
+
+ if (this.customerTextArea.value === '') {
+ this.customerTextArea.value = JSON.stringify({});
+ }
+
+ jQuery.ajax({
+ url: window.location.origin + '/wp-admin/admin-ajax.php?action=set_meta_fields',
+ method: 'POST',
+ timeout: 0,
+ data: {ajax: 1},
+ dataType: 'json'
+ })
+ .done(function (response) {
+ _this.dataFields = response;
+
+ jQuery(".retailcrm-order-label").text(response.translate.tr_lb_order);
+ jQuery(".retailcrm-customer-label").text(response.translate.tr_lb_customer);
+ jQuery(".add-new-select-retailcrm").text(response.translate.tr_btn);
+ jQuery(".add-new-select-retailcrm").text(response.translate.tr_btn);
+
+ if (jQuery.isEmptyObject(JSON.parse(_this.orderTextArea.value)) && jQuery.isEmptyObject(JSON.parse(_this.customerTextArea.value))) {
+ _this.createSelects(_this.dataFields);
+ }
+
+ if (!jQuery.isEmptyObject(JSON.parse(_this.orderTextArea.value))) {
+ let objectJson = JSON.parse(_this.orderTextArea.value);
+
+ _this.indexOrder = _this.restoreSelectsData(
+ objectJson,
+ _this.dataFields.order,
+ 'order',
+ 1
+ );
+ }
+
+ if (!jQuery.isEmptyObject(JSON.parse(_this.customerTextArea.value))) {
+ let objectJson = JSON.parse(_this.customerTextArea.value);
+
+ _this.indexCustomer = _this.restoreSelectsData(
+ objectJson,
+ _this.dataFields.customer,
+ 'customer',
+ 1
+ );
+ }
+ })
+
+ jQuery(this.insertSelects).on('change', '.retailcrm-meta-select', function() {
+ let selectsData = {};
+ let typeSelect = this.id.split('-')[0]
+ let idChangeSelect = this.id.split('-')[2]
+
+ if (this.id.includes('order')) {
+ selectsData = _this.getSelectsData(
+ _this.orderTextArea.value,
+ 'order',
+ idChangeSelect,
+ typeSelect
+ );
+ } else {
+ selectsData = _this.getSelectsData(
+ _this.customerTextArea.value,
+ 'customer',
+ idChangeSelect,
+ typeSelect
+ );
+ }
+
+ if (Object.keys(selectsData).length != 0) {
+ if (this.id.includes('order')) {
+ _this.orderTextArea.value = JSON.stringify(selectsData);
+ } else {
+ _this.customerTextArea.value = JSON.stringify(selectsData);
+ }
+ }
+ });
+
+ jQuery(this.insertSelects).on('click', '.add-new-select-retailcrm', function(event) {
+ event.preventDefault();
+
+ if (this.id.includes('order')) {
+ _this.addPairSelects(
+ '.retailcrm-order-selects',
+ 'order',
+ _this.dataFields.order,
+ _this.indexOrder
+ );
+
+ _this.indexOrder++;
+ } else {
+ _this.addPairSelects(
+ '.retailcrm-customer-selects',
+ 'customer',
+ _this.dataFields.customer,
+ _this.indexCustomer
+ );
+
+ _this.indexCustomer++;
+ }
+ });
+
+ jQuery(this.insertSelects).on('click', '.delete-select-retailcrm', function(event) {
+ event.preventDefault();
+
+ let objectJson = {}
+ let entity = this.id.split('-')[0];
+ let index = this.id.split('-')[1];
+
+ if (entity === 'order') {
+ objectJson = JSON.parse(_this.orderTextArea.value);
+ } else {
+ objectJson = JSON.parse(_this.customerTextArea.value);
+ }
+
+ let metaFiled = jQuery(`#metaFields-${entity}-${index}`);
+ let valueMetaField = metaFiled.val();
+
+ for (let i = 1; i <= index; i++) {
+ jQuery(`#select-pair-${entity}-${i}`).remove();
+ }
+
+ delete objectJson[valueMetaField];
+
+ if (entity === 'order') {
+ _this.indexOrder = _this.restoreSelectsData(
+ objectJson,
+ _this.dataFields.order,
+ 'order',
+ 1
+ );
+
+ _this.orderTextArea.value = JSON.stringify(objectJson);
+ } else {
+ _this.indexCustomer = _this.restoreSelectsData(
+ objectJson,
+ _this.dataFields.customer,
+ 'customer',
+ 1
+ );
+
+ _this.customerTextArea.value = JSON.stringify(objectJson);
+ }
+
+ jQuery(`#add-new-select-${entity}-retailcrm`).removeClass('retailcrm-hidden')
+ });
+ }
+
+ RetailcrmMetaFields.prototype.restoreSelectsData = function (objectJson, dataEntity, entity, index) {
+ for (let key in objectJson) {
+ let getMetaSelect = `#metaFields-${entity}-${index} option[value=${key}]`;
+ let getCustomSelect = `#customFields-${entity}-${index} option[value=${objectJson[key]}]`;
+
+ this.addPairSelects(`.retailcrm-${entity}-selects`, entity, dataEntity, index);
+
+ jQuery(getMetaSelect).prop('selected', true);
+ jQuery(getCustomSelect).prop('selected', true);
+
+ index++;
+ }
+
+ return index;
+ }
+
+ RetailcrmMetaFields.prototype.getSelectsData = function (textarea, entity, idChangeSelect, typeSelect) {
+ let _this = this;
+ let selectsData = {};
+
+ if (!jQuery.isEmptyObject(textarea)) {
+ let objectJson = JSON.parse(textarea);
+ let field = jQuery(`#${typeSelect}-${entity}-${idChangeSelect}`);
+ let selectedField = jQuery(`#${typeSelect}-${entity}-${idChangeSelect} option:selected`);
+ let fieldValue = field.val();
+
+ if (Object.values(objectJson).includes(fieldValue) || fieldValue in objectJson) {
+ _this.addWarning(field, selectedField.text());
+
+ // Search key in object by id selects
+ let counter = 0;
+
+ for (let key in objectJson) {
+ counter++;
+
+ if (counter == idChangeSelect) {
+ delete objectJson[key];
+ }
+ }
+
+ if (entity === 'order') {
+ _this.orderTextArea.value = JSON.stringify(objectJson);
+ } else {
+ _this.customerTextArea.value = JSON.stringify(objectJson);
+ }
+ }
+ }
+
+ for (let i = 1; i <= jQuery(`.retailcrm-${entity}-selects div`).length; i++) {
+ let metaFiled = jQuery(`#metaFields-${entity}-${i}`);
+ let customField = jQuery(`#customFields-${entity}-${i}`);
+ let valueMetaField = metaFiled.val();
+ let valueCustomField = customField.val();
+
+ if (valueMetaField === 'default_retailcrm' || valueCustomField === 'default_retailcrm') {
+ continue;
+ }
+
+ _this.deleteWarning(metaFiled);
+ _this.deleteWarning(customField);
+
+ selectsData[valueMetaField] = valueCustomField;
+ }
+
+ return selectsData;
+ }
+
+ RetailcrmMetaFields.prototype.createSelects = function (dataFields) {
+ let orderData = dataFields.order;
+ let customerData = dataFields.customer;
+
+ //Create selects for order data
+ this.buildElements('.retailcrm-order-selects', 'order', this.indexOrder);
+ this.fillSelects(orderData, 'order', this.indexOrder);
+
+ //Create selects for customer data
+ this.buildElements('.retailcrm-customer-selects', 'customer', this.indexCustomer);
+ this.fillSelects(customerData, 'customer', this.indexCustomer);
+
+ this.indexOrder++;
+ this.indexCustomer++;
+ }
+
+ RetailcrmMetaFields.prototype.buildElements = function (element, entity, index) {
+ jQuery(element).append(
+ `` +
+ `` +
+ `` +
+ `
`
+ );
+
+ jQuery(`#add-new-select-${entity}-retailcrm`).insertAfter(`#select-pair-${entity}-${index}`);
+ }
+
+ RetailcrmMetaFields.prototype.fillSelects = function (data, entity, index) {
+ if (Object.keys(data.meta).length - 1 <= index || Object.keys(data.custom).length - 1 <= index) {
+ if (entity === 'order') {
+ jQuery('#add-new-select-order-retailcrm').addClass('retailcrm-hidden')
+ } else {
+ jQuery('#add-new-select-customer-retailcrm').addClass('retailcrm-hidden')
+ }
+ }
+
+ // Set meta fields in select
+ jQuery.each(data.meta, function(key, value) {
+ jQuery(`#metaFields-${entity}-${index}`)
+ .append(jQuery('')
+ .attr('value', key)
+ .text(value));
+ });
+
+ // Set custom fields in select
+ jQuery.each(data.custom, function(key, value) {
+ jQuery(`#customFields-${entity}-${index}`)
+ .append(jQuery('')
+ .attr('value', key)
+ .text(value));
+ });
+ }
+
+ RetailcrmMetaFields.prototype.addPairSelects = function (element, entity, data, index) {
+ this.buildElements(element, entity, index);
+ this.fillSelects(data, entity, index);
+ }
+
+ RetailcrmMetaFields.prototype.addWarning = function (field, fieldValue) {
+ alert(fieldValue + ' already been selected');
+
+ field.prop('value', 'default_retailcrm');
+ field.addClass('red-selected-retailcrm');
+ }
+
+ RetailcrmMetaFields.prototype.deleteWarning = function (field) {
+ if (field.css('border-color') === "rgb(255, 0, 0)") {
+ field.removeClass('red-selected-retailcrm')
+ }
+ }
+
+ window.RetailcrmMetaFields = RetailcrmMetaFields;
+
+ if (typeof RetailcrmMetaFields !== 'undefined') {
+ new window.RetailcrmMetaFields();
+ }
+});
diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php
index 464d60e..a487577 100644
--- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php
+++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php
@@ -1,4 +1,5 @@
get_option_key();
- if (isset($_GET['page']) && $_GET['page'] == 'wc-settings'
+ if (
+ isset($_GET['page']) && $_GET['page'] == 'wc-settings'
&& isset($_GET['tab']) && $_GET['tab'] == 'integration'
) {
add_action('init', array($this, 'init_settings_fields'), 99);
@@ -66,19 +68,19 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
public function init_form_fields()
{
$this->form_fields = array(
- array( 'title' => __( 'Main settings', 'retailcrm' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
+ array( 'title' => __('Main settings', 'retailcrm'), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
'api_url' => array(
- 'title' => __( 'API of URL', 'retailcrm' ),
+ 'title' => __('API of URL', 'retailcrm'),
'type' => 'text',
'description' => __( 'Enter API of URL (https://yourdomain.simla.com)', 'retailcrm' ),
'desc_tip' => true,
'default' => ''
),
'api_key' => array(
- 'title' => __( 'API key', 'retailcrm' ),
+ 'title' => __('API key', 'retailcrm'),
'type' => 'text',
- 'description' => __( 'Enter your API key. You can find it in the administration section of Simla.com', 'retailcrm' ),
+ 'description' => __('Enter your API key. You can find it in the administration section of Simla.com', 'retailcrm'),
'desc_tip' => true,
'default' => ''
)
@@ -89,13 +91,14 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
$apiKey = !empty($post[$this->plugin_id . $this->id . '_api_key']) ? $post[$this->plugin_id . $this->id . '_api_key'] : null;
if ($this->apiClient) {
- if (isset($_GET['page']) && $_GET['page'] == 'wc-settings'
+ if (
+ isset($_GET['page']) && $_GET['page'] == 'wc-settings'
&& isset($_GET['tab']) && $_GET['tab'] == 'integration'
) {
add_action('admin_print_footer_scripts', array($this, 'show_blocks'), 99);
$this->form_fields[] = array(
- 'title' => __( 'API settings', 'retailcrm' ),
+ 'title' => __('API settings', 'retailcrm'),
'type' => 'title',
'description' => '',
'id' => 'api_options'
@@ -111,14 +114,14 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
);
$this->form_fields['online_assistant'] = array(
- 'title' => __( 'Online assistant', 'retailcrm' ),
+ 'title' => __('Online assistant', 'retailcrm'),
'type' => 'textarea',
'id' => 'online_assistant',
- 'placeholder' => __( 'Insert the Online consultant code here', 'retailcrm' )
+ 'placeholder' => __('Insert the Online consultant code here', 'retailcrm')
);
- $this->form_fields['catalog_options'] = array(
- 'title' => __( 'Catalog settings', 'retailcrm' ),
+ $this->form_fields[] = array(
+ 'title' => __('Catalog settings', 'retailcrm'),
'type' => 'heading',
'description' => '',
'id' => 'catalog_options'
@@ -193,7 +196,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
'id' => 'shipping_options'
);
- foreach ($wc_shipping_list as $shipping_code => $shipping) {
+ foreach ($wc_shipping_list as $shipping_code => $shipping) {
if (isset($shipping['enabled']) && $shipping['enabled'] == static::YES) {
$this->form_fields[$shipping_code] = array(
'title' => __($shipping['title'], 'woocommerce'),
@@ -282,6 +285,26 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
}
}
+ /**
+ * Meta data options
+ */
+ $this->form_fields[] = array(
+ 'title' => __('Custom fields', 'retailcrm'),
+ 'type' => 'heading',
+ 'description' => '',
+ 'class' => 'meta-fields'
+ );
+
+ $this->form_fields['order-meta-data-retailcrm'] = array(
+ 'type' => 'textarea',
+ 'class' => 'order-meta-data-retailcrm',
+ );
+
+ $this->form_fields['customer-meta-data-retailcrm'] = array(
+ 'type' => 'textarea',
+ 'class' => 'customer-meta-data-retailcrm',
+ );
+
/**
* Inventories options
*/
@@ -506,7 +529,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
$response = $api->apiVersions();
if ($response->isSuccessful()) {
- header("Refresh:0");
+ header("Refresh:0");
}
}
}
@@ -533,20 +556,20 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
'title' => '',
);
- $data = wp_parse_args( $data, $defaults );
+ $data = wp_parse_args($data, $defaults);
ob_start();
?>
-
- get_tooltip_html( $data ); ?>
+
+ get_tooltip_html($data); ?>
|
|
@@ -566,20 +589,20 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
*/
public function generate_heading_html($key, $data)
{
- $field_key = $this->get_field_key( $key );
+ $field_key = $this->get_field_key($key);
$defaults = array(
'title' => '',
'class' => '',
);
- $data = wp_parse_args( $data, $defaults );
+ $data = wp_parse_args($data, $defaults);
ob_start();
?>
- ⬇
-
-
+ ⬇
+
+