diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e49cc5..88cc48e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2018-08-22 v3.3.2 +* Убрана проверка существования задач в wp-cron при каждой загрузке страницы +* Задачи в wp-cron теперь активируются в настройках плагина + ## 2018-08-09 v3.3.1 * Исправлена ошибка с дублированием товаров с WC diff --git a/VERSION b/VERSION index 712bd5a..5436ea0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.3.1 \ No newline at end of file +3.3.2 \ No newline at end of file diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index 07a2562..ed1cfe3 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -49,15 +49,12 @@ if (!class_exists('WC_Retailcrm_Base')) { // Actions. add_action('woocommerce_update_options_integration_' . $this->id, array($this, 'process_admin_options')); + add_filter('woocommerce_settings_api_sanitized_fields_' . $this->id, array($this, 'api_sanitized')); - add_filter('cron_schedules', array($this, 'filter_cron_schedules'), 10, 1); add_action('woocommerce_checkout_order_processed', array($this, 'retailcrm_process_order'), 10, 1); add_action('retailcrm_history', array($this, 'retailcrm_history_get')); add_action('retailcrm_icml', array($this, 'generate_icml')); add_action('retailcrm_inventories', array($this, 'load_stocks')); - add_action('init', array($this, 'register_load_inventories')); - add_action('init', array($this, 'register_icml_generation')); - add_action('init', array($this, 'register_retailcrm_history')); add_action('wp_ajax_do_upload', array($this, 'upload_to_crm')); add_action('wp_ajax_generate_icml', array($this, 'generate_icml')); add_action('wp_ajax_order_upload', array($this, 'order_upload')); @@ -71,6 +68,35 @@ if (!class_exists('WC_Retailcrm_Base')) { add_action('wp_print_footer_scripts', array($this, 'send_analytics'), 99); } + public function api_sanitized($settings) + { + if (isset($settings['sync']) && $settings['sync'] == 'yes') { + if (!wp_next_scheduled('retailcrm_inventories')) { + wp_schedule_event(time(), 'fiveteen_minutes', 'retailcrm_inventories'); + } + } elseif (isset($settings['sync']) && $settings['sync'] == 'no') { + wp_clear_scheduled_hook('retailcrm_inventories'); + } + + if (isset($settings['history']) && $settings['history'] == 'yes') { + if (!wp_next_scheduled('retailcrm_history')) { + wp_schedule_event(time(), 'five_minutes', 'retailcrm_history'); + } + } elseif (isset($settings['history']) && $settings['history'] == 'no') { + wp_clear_scheduled_hook('retailcrm_history'); + } + + if (isset($settings['icml']) && $settings['icml'] == 'yes') { + if (!wp_next_scheduled('retailcrm_icml')) { + wp_schedule_event(time(), 'three_hours', 'retailcrm_icml'); + } + } elseif (isset($settings['icml']) && $settings['icml'] == 'no') { + wp_clear_scheduled_hook('retailcrm_icml'); + } + + return $settings; + } + /** * Check custom file * @@ -86,26 +112,6 @@ if (!class_exists('WC_Retailcrm_Base')) { return 'class-wc-retailcrm-' . $file . '.php'; } - public function filter_cron_schedules($schedules) { - return array_merge( - $schedules, - array( - 'five_minutes' => array( - 'interval' => 300, // seconds - 'display' => __('Every 5 minutes') - ), - 'three_hours' => array( - 'interval' => 10800, // seconds - 'display' => __('Every 3 hours') - ), - 'fiveteen_minutes' => array( - 'interval' => 900, // seconds - 'display' => __('Every 15 minutes') - ) - ) - ); - } - public function generate_icml() { if (!class_exists('WC_Retailcrm_Icml')) { require_once (self::checkCustomFile('icml')); @@ -151,29 +157,6 @@ if (!class_exists('WC_Retailcrm_Base')) { $inventories->updateQuantity(); } - public function register_load_inventories() { - if ( !wp_next_scheduled( 'retailcrm_inventories' ) ) { - // Schedule the event - wp_schedule_event( time(), 'fiveteen_minutes', 'retailcrm_inventories' ); - } - } - - public function register_icml_generation() { - // Make sure this event hasn't been scheduled - if ( !wp_next_scheduled( 'retailcrm_icml' ) ) { - // Schedule the event - wp_schedule_event( time(), 'three_hours', 'retailcrm_icml' ); - } - } - - public function register_retailcrm_history() { - // Make sure this event hasn't been scheduled - if ( !wp_next_scheduled( 'retailcrm_history' ) ) { - // Schedule the event - wp_schedule_event( time(), 'five_minutes', 'retailcrm_history' ); - } - } - /** * Upload selected orders */ @@ -468,6 +451,7 @@ if (!class_exists('WC_Retailcrm_Base')) { 'type' => 'multiselect', 'description' => __('Select order methods which will be uploaded from retailCRM to the website', 'retailcrm'), 'options' => $order_methods_option, + 'css' => 'min-height:100px;', 'select_buttons' => true ); } @@ -665,6 +649,13 @@ if (!class_exists('WC_Retailcrm_Base')) { 'id' => 'icml-retailcrm' ); + $this->form_fields['icml'] = array( + 'label' => __('Generating ICML', 'retailcrm'), + 'title' => __('Generating ICML catalog by wp-cron', 'retailcrm'), + 'class' => 'checkbox', + 'type' => 'checkbox' + ); + /* * Upload single order */ @@ -691,6 +682,13 @@ if (!class_exists('WC_Retailcrm_Base')) { 'desc_tip' => true, 'id' => 'single_order_btn' ); + + $this->form_fields['history'] = array( + 'label' => __('Activate history uploads', 'retailcrm'), + 'title' => __('Upload data from retailCRM', 'retailcrm'), + 'class' => 'checkbox', + 'type' => 'checkbox' + ); } } } diff --git a/src/include/class-wc-retailcrm-plugin.php b/src/include/class-wc-retailcrm-plugin.php index c36ba1f..e18c408 100644 --- a/src/include/class-wc-retailcrm-plugin.php +++ b/src/include/class-wc-retailcrm-plugin.php @@ -16,6 +16,28 @@ class WC_Retailcrm_Plugin { private function __construct($file) { $this->file = $file; + + add_filter('cron_schedules', array($this, 'filter_cron_schedules'), 10, 1); + } + + public function filter_cron_schedules($schedules) { + return array_merge( + $schedules, + array( + 'five_minutes' => array( + 'interval' => 300, // seconds + 'display' => __('Every 5 minutes') + ), + 'three_hours' => array( + 'interval' => 10800, // seconds + 'display' => __('Every 3 hours') + ), + 'fiveteen_minutes' => array( + 'interval' => 900, // seconds + 'display' => __('Every 15 minutes') + ) + ) + ); } public function register_activation_hook() { diff --git a/src/languages/retailcrm-ru_RU.mo b/src/languages/retailcrm-ru_RU.mo index 6c2fec4..e443e55 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 62496ab..c3ba2f1 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -45,6 +45,9 @@ API-ключ должен быть для отдельного магазина 2. В появившихся списках справочников настройте соответствие способов доставки и оплаты, а так же статусов заказов. Отметьте галочку "Выгружать остатки", если хотите выгружать остатки из Retailcrm в магазин (подробнее смотрите в описании). == Changelog == += 3.3.2 = +* Задачи в wp-cron теперь активируются в настройках плагина + = 3.3.1 = * Исправлена ошибка с дублированием товаров с WC @@ -138,6 +141,9 @@ API-ключ должен быть для отдельного магазина == Upgrade Notice == += 3.3.2 = +Добавлена настройка для активации задач в wp-cron + = 3.3.1 = Исправлена ошибка с дублированием товаров с WC diff --git a/src/retailcrm.php b/src/retailcrm.php index 25ebfec..3be2453 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -1,6 +1,6 @@ load_plugin_textdomain(); - if ( class_exists( 'WC_Integration' ) ) { - require_once( dirname( __FILE__ ) . '/include/class-wc-retailcrm-base.php' ); - require_once( dirname( __FILE__ ) . '/include/functions.php' ); + if (class_exists( 'WC_Integration' ) ) { + require_once(dirname(__FILE__ ) . '/include/class-wc-retailcrm-base.php'); + require_once(dirname(__FILE__ ) . '/include/functions.php'); add_filter('woocommerce_integrations', array( $this, 'add_integration')); } else { - // throw an admin error if you like + add_action('admin_notices', array($this, 'woocommerce_missing_notice')); } } + public function woocommerce_missing_notice() { + echo '
Woocommerce is not installed