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 3b176fa..ff37eac 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 a0b0cf3..6aaec63 100644 Binary files a/src/languages/retailcrm-ru_RU.mo and b/src/languages/retailcrm-ru_RU.mo differ diff --git a/tests/loyalty/test-wc-retailcrm-client-v5.php b/tests/loyalty/test-wc-retailcrm-client-v5.php index 01e128a..967ed1d 100644 --- a/tests/loyalty/test-wc-retailcrm-client-v5.php +++ b/tests/loyalty/test-wc-retailcrm-client-v5.php @@ -44,10 +44,6 @@ class WC_Retailcrm_Loyalty_Client_Test extends WC_Retailcrm_Test_Case_Helper $this->setMockResponse($this->apiMock, 'makeRequest', $this->responseMock); $this->clientMock = new \WC_Retailcrm_Client_V5('https://test@retailcrm.ru', 'test', 'test'); - /* $this->clientMock = $this->getMockBuilder('\WC_Retailcrm_Client_V5') - ->disableOriginalConstructor() - ->getMock() - ;*/ $reflection = new ReflectionClass($this->clientMock); $reflection_property = $reflection->getProperty('client');