From 4a90087e61058d2d46147f226c7cb857b7ba9f28 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Wed, 22 Aug 2018 15:54:47 +0300 Subject: [PATCH] v3.3.2 --- CHANGELOG.md | 4 + VERSION | 2 +- src/include/class-wc-retailcrm-base.php | 92 +++++++++++----------- src/include/class-wc-retailcrm-plugin.php | 22 ++++++ src/languages/retailcrm-ru_RU.mo | Bin 6139 -> 6537 bytes src/readme.txt | 6 ++ src/retailcrm.php | 18 +++-- src/uninstall.php | 16 ++-- 8 files changed, 98 insertions(+), 62 deletions(-) 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 6c2fec4a106b55e781514736f81b31da016a6341..e443e55bd4ad0172bf1f2e4cbaea9c1108e71531 100644 GIT binary patch delta 1621 zcmZwHS!_&E9LMp~X{)v}45RjIt*u3CDQamd(b~6YM1)a;(smfrib#wq4^=!U5lbTV zBq7muh?15UTVLefAR-cth{S^@Yeb0e@6HepPIBgR?wvd5{LlY??);csmm7WEH|30> z&7}{ar+AE6gCCOlpyj0+lZLafI~HJ1T#7w#eZnASaJ>h;cntgF1ssXZ*bATGBz%iI zjfom>7h|Sz;{ax36Ar{qR6yTxIr@o069+LJtFbp8K?QU=aovamxNb%*+<}_+17_ji zuJPX&qnGtfN#e#1R3O#Z7q4PJyqoy`DJpcs$g!RQhW!s@IxdS<^>MI*XYOZsGWLw*uq@Q!?mcC zpFjn45%qivsstSvWo`47K_rO*c~mN^2$yV`!>At|Lj}-?gRupd;1e8$gIGl=o`Y8|S&drY9I95= za6Z1od>qKTR*36xJ)Xy@_!%|NSkfi)QNLe}Ds>c9>0G)t5}nCM4qa_JT?ecOUG>vn zz#O`oUNvQA0(~;wqN{QC+?r|=e_9@c8T6ra1@*tCY!O)0{p0!bfNG@OskwhfIEK!D zh1=5jRCb2ZwHvDCHkF8tyRYBa_$_z$DgkHIeXUg{j)z-+l3>Qu{mQB8tfrH%_md2} zX93)n&8JGCmKDc6oEr9Pc$bo&QBWEws}4kh){e5hkx+QQRkgc36xg~qW~DChj9e6~ z42A=dvdZmNapAJ1R%sv-C=YG7w(Pg|?anFEu%Y5t!1}5HO^uCu5-w4wOhI5ew%&MZg+dD zeY>I4*FTn%{vf&Gi8ph+rDyFHyNTz~a%wF59-}s9sB?}xC;tZY#rx9}>-1H4CZ7Fw aNxR9iZ*ZgCZg=XPqwa$L1iIMYob(%Z8T1nX delta 1331 zcmXxkUr1A77{~Ev$1O9R+14_%bge8)ojR>70@KJTfe95--s~ocgd&PSp+e)-Lc@i(r)ES6yoOR*%7H-Z)Pw_*en7{gvH#}RDAF+7LQu-zL z$1cpE!~7N_uS#VdYQk1zv(}9pun(2W6h`p|cHk3KYQLctvVi)3hryKUDr64p!ON6& z0F|*>F6`O9U|J8%bEAo~Sd9+b*oHNzRCeP5yoj|pg+urOA7eeM(D|9e6X;N%792z^ zbR4hYTik?)m`tS_sv!TW`6WJ3itZG?n8tegAF&q~F^Qe)IAC}a_5aVY1wZ2mI@GBF z&!e7ygxb&yGKBp=J^v5yV<=4iwX>(;{EjoIl=?XcGK?B9hQrv8+R-#l;9tCsW8~k# z9I6z{TvW0M>18hKz)n1h2XO)q(Tc;U0Uj27iH-E%p=y~$O6eUm4ctVd z?A|WH%L?buOEW_oZ<+0)#c8`~dueSn&80}I&I;8}p_8jnofRAj@382exvh@2MIAzK zfr6g`+eo9lUT6bKGs)CD?qx#RQ8d%`d3W9=?d^^%db?9CRX4>BT7stYp-}zy(3Jj_ zpzIc<>9(Woo bWOpR&#>;1m+#{hS$2}f7?YQ%muYCUj^&51o 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

'; + } + public function load_plugin_textdomain() { - load_plugin_textdomain('retailcrm', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); + load_plugin_textdomain('retailcrm', false, dirname(plugin_basename(__FILE__)) . '/languages/'); } /** diff --git a/src/uninstall.php b/src/uninstall.php index 0f61904..618c4ab 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -15,28 +15,30 @@ * * * @link https://wordpress.org/plugins/woo-retailcrm/ - * @version 3.3.1 + * @version 3.3.2 * * @package RetailCRM */ -if ( ! defined( 'ABSPATH' ) ) { +if (!defined('ABSPATH')) { exit; // Exit if accessed directly } // If uninstall not called from WordPress, then exit. -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { +if (!defined('WP_UNINSTALL_PLUGIN')) { exit; } global $wpdb; -wp_clear_scheduled_hook( 'retailcrm_icml' ); -wp_clear_scheduled_hook( 'retailcrm_history' ); -wp_clear_scheduled_hook( 'retailcrm_inventories' ); +wp_clear_scheduled_hook('retailcrm_icml'); +wp_clear_scheduled_hook('retailcrm_history'); +wp_clear_scheduled_hook('retailcrm_inventories'); // Delete options. -$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = 'woocommerce_integration-retailcrm_settings';" ); +$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'woocommerce_integration-retailcrm_settings';"); +$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'retailcrm_customers_history_since_id';"); +$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'retailcrm_orders_history_since_id';"); // Clear any cached data that has been removed wp_cache_flush();