diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot index 8d45170..cadd305 100644 --- a/resources/pot/retailcrm-ru_RU.pot +++ b/resources/pot/retailcrm-ru_RU.pot @@ -453,3 +453,24 @@ msgstr "Требуется API ключ с доступом к одному ма msgid "The currency of the site differs from the currency of the store in CRM. For the integration to work correctly, the currencies in CRM and CMS must match" msgstr "Валюта сайта отличается от валюты магазина в CRM. Для корректной работы интеграции, валюты в CRM и CMS должны совпадать" + +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 "Вставьте условия c программой лояльности" + +msgid "Conditions of personal data processing" +msgstr "Условия обработки персональных данных" + +msgid "Insert the terms and conditions for processing personal data" +msgstr "Вставьте условия обработки персональных данных" diff --git a/src/assets/js/retailcrm-loyalty.js b/src/assets/js/retailcrm-loyalty.js new file mode 100644 index 0000000..84006e2 --- /dev/null +++ b/src/assets/js/retailcrm-loyalty.js @@ -0,0 +1,32 @@ +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') { + alert('lol'); + var checkElement = jQuery('#woocommerce_integration-retailcrm_loyalty'); + checkElement.parent().css('color', 'red'); + checkElement.css('border-color', 'red'); + checkElement.parent().parent().append("

Test

"); + checkElement.prop('checked', false); + } + }) + } +}); diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php index 3c0c446..f2b6948 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php @@ -390,6 +390,39 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration ]; } + /** + * 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'), + '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'), + 'type' => 'textarea', + 'id' => 'loyalty_personal', + 'placeholder' => __('Insert the terms and conditions for processing personal data', 'retailcrm') + ]; + /** * Meta data options */ diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index 729e8f1..42b9258 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); @@ -601,6 +602,13 @@ 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')]); + + wp_die(); + } + /** * In this method we include CSS file * @@ -634,7 +642,13 @@ if (!class_exists('WC_Retailcrm_Base')) { */ private function include_js_scripts_for_admin() { - $jsScripts = ['retailcrm-export', 'retailcrm-cron-info','retailcrm-meta-fields']; + $jsScripts = [ + 'retailcrm-export', + 'retailcrm-cron-info', + 'retailcrm-meta-fields', + 'retailcrm-loyalty' + ]; + $wpAdminUrl = ['url' => get_admin_url()]; $jsScriptsPath = plugins_url() . '/woo-retailcrm/assets/js/'; 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');