From 6220dd99dd5ab15a5032a9e1ef6e48bc833cb4d3 Mon Sep 17 00:00:00 2001 From: Kocmonavtik <61938582+Kocmonavtik@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:48:51 +0300 Subject: [PATCH] ref #73401 Functionality of activation of data exchange by loyalty program (#325) --- resources/pot/retailcrm-es_ES.pot | 24 ++++++++++++ resources/pot/retailcrm-ru_RU.pot | 24 ++++++++++++ src/assets/js/retailcrm-loyalty.js | 36 ++++++++++++++++++ .../class-wc-retailcrm-abstracts-settings.php | 36 ++++++++++++++++++ src/include/class-wc-retailcrm-base.php | 18 +++++++++ src/languages/retailcrm-es_ES.mo | Bin 13576 -> 14427 bytes src/languages/retailcrm-ru_RU.mo | Bin 16757 -> 17803 bytes tests/loyalty/test-wc-retailcrm-client-v5.php | 4 -- 8 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 src/assets/js/retailcrm-loyalty.js diff --git a/resources/pot/retailcrm-es_ES.pot b/resources/pot/retailcrm-es_ES.pot index 970ebdc..ee3d17e 100644 --- a/resources/pot/retailcrm-es_ES.pot +++ b/resources/pot/retailcrm-es_ES.pot @@ -450,3 +450,27 @@ msgstr "Descarga de servicios" msgid "Goods with the 'virtual' option enabled will be uploaded to Simla as services" msgstr "Los bienes con la opción 'virtual' activada se cargarán en Simla como servicios" + +msgid "Loyalty program" +msgstr "Programa de fidelización" + +msgid "Activate program loyalty" +msgstr "Activar el programa de fidelización" + +msgid "Enable this setting for activate program loyalty on site" +msgstr "Active esta opción para activar el programa de fidelización en el sitio web" + +msgid "Terms of loyalty program" +msgstr "Condiciones del programa de fidelidad" + +msgid "Insert the terms and conditions of the loyalty program" +msgstr "Inserte las condiciones de participación en el programa de fidelidad" + +msgid "Conditions of personal data processing" +msgstr "Condiciones del tratamiento de datos personales" + +msgid "Insert the terms and conditions for processing personal data" +msgstr "Inserte las condiciones para el tratamiento de datos personales" + +msgid "To activate the loyalty program it is necessary to activate the 'enable use of coupons option'" +msgstr "Para activar el programa de fidelización es necesario activar la opción 'habilitar uso de cupones'." diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot index b353e9a..67e62fb 100644 --- a/resources/pot/retailcrm-ru_RU.pot +++ b/resources/pot/retailcrm-ru_RU.pot @@ -459,3 +459,27 @@ msgstr "Выгрузка услуг" msgid "Goods with the 'virtual' option enabled will be uploaded to Simla as services" msgstr "Товары с включенной опцией 'виртуальные' будут выгружаться в CRM как услуги" + +msgid "Loyalty program" +msgstr "Программа лояльности" + +msgid "Activate program loyalty" +msgstr "Активировать программу лояльности" + +msgid "Enable this setting for activate program loyalty on site" +msgstr "Активируйте эту настройку для активации программы лояльности на сайте" + +msgid "Terms of loyalty program" +msgstr "Условия программы лояльности" + +msgid "Insert the terms and conditions of the loyalty program" +msgstr "Вставьте условия участия в программе лояльности" + +msgid "Conditions of personal data processing" +msgstr "Условия обработки персональных данных" + +msgid "Insert the terms and conditions for processing personal data" +msgstr "Вставьте условия обработки персональных данных" + +msgid "To activate the loyalty program it is necessary to activate the 'enable use of coupons option'" +msgstr "Для активации программы лояльности необходимо активировать опцию 'включить использование купонов'" diff --git a/src/assets/js/retailcrm-loyalty.js b/src/assets/js/retailcrm-loyalty.js new file mode 100644 index 0000000..c043d51 --- /dev/null +++ b/src/assets/js/retailcrm-loyalty.js @@ -0,0 +1,36 @@ +jQuery(function() { + if (jQuery('#woocommerce_integration-retailcrm_loyalty').is(':checked')) { + checkActiveCoupon(); + } + + jQuery('#woocommerce_integration-retailcrm_loyalty').change(function () { + if (this.checked) { + checkActiveCoupon(); + } + }) + + function checkActiveCoupon() + { + jQuery.ajax({ + url: AdminUrl.url + '/admin-ajax.php?action=get_status_coupon', + method: 'POST', + timeout: 0, + data: {ajax: 1}, + dataType: 'json' + }) + .done(function (response) { + if (response.coupon_status !== 'yes') { + var checkElement = jQuery('#woocommerce_integration-retailcrm_loyalty'); + checkElement.parent().css('color', 'red'); + checkElement.css('border-color', 'red'); + checkElement.prop('checked', false); + + if (!jQuery('#coupon_warning').length) { + checkElement.parent().parent().append( + "
" + response.translate.coupon_warning + "
" + ); + } + } + }) + } +}); diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php index ba8bbef..9adf83b 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php @@ -117,6 +117,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration $this->form_fields['online_assistant'] = [ 'title' => __('Online assistant', 'retailcrm'), + 'css' => 'width:400px; height:215px; resize: horizontal;', 'type' => 'textarea', 'id' => 'online_assistant', 'placeholder' => __('Insert the Online consultant code here', 'retailcrm') @@ -593,6 +594,41 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration 'description' => __('WhatsApp chat will be opened with this contact', 'retailcrm') ]; + /** + * Loyalty Program + */ + + $this->form_fields[] = [ + 'title' => __('Loyalty program', 'retailcrm'), + 'type' => 'heading', + 'description' => '', + 'id' => 'loyalty_options' + ]; + + $this->form_fields['loyalty'] = [ + 'label' => __('Activate program loyalty', 'retailcrm'), + 'title' => __('Loyalty program', 'retailcrm'), + 'class' => 'checkbox', + 'type' => 'checkbox', + 'description' => __('Enable this setting for activate program loyalty on site', 'retailcrm') + ]; + + $this->form_fields['loyalty_terms'] = [ + 'title' => __('Terms of loyalty program', 'retailcrm'), + 'css' => 'width:400px; height:215px; resize: horizontal;', + 'type' => 'textarea', + 'id' => 'loyalty_terms', + 'placeholder' => __('Insert the terms and conditions of the loyalty program', 'retailcrm') + ]; + + $this->form_fields['loyalty_personal'] = [ + 'title' => __('Conditions of personal data processing', 'retailcrm'), + 'css' => 'width:400px; height:215px; resize: horizontal;', + 'type' => 'textarea', + 'id' => 'loyalty_personal', + 'placeholder' => __('Insert the terms and conditions for processing personal data', 'retailcrm') + ]; + /** * Generate icml file */ diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index 707d1c2..6144498 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -86,6 +86,7 @@ if (!class_exists('WC_Retailcrm_Base')) { add_action('wp_ajax_generate_icml', [$this, 'generate_icml']); add_action('wp_ajax_upload_selected_orders', [$this, 'upload_selected_orders']); add_action('wp_ajax_clear_cron_tasks', [$this, 'clear_cron_tasks']); + add_action('wp_ajax_get_status_coupon', [$this, 'get_status_coupon']); add_action('admin_print_footer_scripts', [$this, 'ajax_generate_icml'], 99); add_action('woocommerce_update_customer', [$this, 'update_customer'], 10, 1); add_action('user_register', [$this, 'create_customer'], 10, 2); @@ -607,6 +608,22 @@ if (!class_exists('WC_Retailcrm_Base')) { $this->include_js_scripts_for_admin(); } + public function get_status_coupon() + { + echo json_encode( + [ + 'coupon_status' => get_option('woocommerce_enable_coupons'), + 'translate' => [ + 'coupon_warning' => __( + "To activate the loyalty program it is necessary to activate the 'enable use of coupons option'", + 'retailcrm' + ) + ] + ]); + + wp_die(); + } + /** * In this method we include CSS file * @@ -645,6 +662,7 @@ if (!class_exists('WC_Retailcrm_Base')) { 'retailcrm-cron-info', 'retailcrm-meta-fields', 'retailcrm-module-settings', + 'retailcrm-loyalty', ]; $wpAdminUrl = ['url' => get_admin_url()]; diff --git a/src/languages/retailcrm-es_ES.mo b/src/languages/retailcrm-es_ES.mo index 3b176fa7e3896dce16b8ba6d7e623916cdaae174..ff37eac100f20d93e40fcd6fdadfd5181d931c42 100644 GIT binary patch delta 4275 zcma*neQ;FO8OQOHO~Pw