From c559ec3dee3f9dcadffe1d338fc866b0a1dd16a6 Mon Sep 17 00:00:00 2001 From: Anatoly Yumashev <1852897+uptimizt@users.noreply.github.com> Date: Mon, 2 Jan 2023 22:48:11 +0300 Subject: [PATCH] updates 221205 (#467) * add zip for each tag * readme * code style * small fixes * fix #468 --- .github/PULL_REQUEST_TEMPLATE.md | 6 +-- .github/workflows/zip.yml | 22 +++++++++++ includes/MenuSettings.php | 7 ++-- includes/MenuTools.php | 25 +++++++----- includes/ProductStocks.php | 2 +- includes/ProductVariable.php | 2 +- includes/Products.php | 66 ++++++++++++++++++++++++-------- includes/ProductsCategories.php | 16 +------- includes/ProductsHiding.php | 2 +- includes/ProductsImage.php | 2 +- readme.txt | 6 ++- 11 files changed, 104 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/zip.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index ab0dbcf..791a72f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,10 +1,10 @@ ## Какие проблемы решаем? Что есть? -Тут ссылки на issue или описание проблемы +- [ ] ... -## Как надо? Как это должно работать? +## Как надо? Как это должно работать? Как это будет? -... +- [ ] ... ## Чек лист diff --git a/.github/workflows/zip.yml b/.github/workflows/zip.yml new file mode 100644 index 0000000..856a0c0 --- /dev/null +++ b/.github/workflows/zip.yml @@ -0,0 +1,22 @@ +name: Create zip + +on: + release: + types: + - created + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Zip Folder + run: zip -r ${{ github.event.repository.name }}.zip . -x ".git/*" ".github/*" "phpcs.xml" "composer.json" "composer.lock" ".gitignore" + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: ${{ github.event.repository.name }}.zip + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/includes/MenuSettings.php b/includes/MenuSettings.php index 404f8cf..7f2f623 100644 --- a/includes/MenuSettings.php +++ b/includes/MenuSettings.php @@ -258,11 +258,10 @@ public static function display_settings() Управление синхронизацией

', admin_url('admin.php?page=moysklad')); - printf('

Расширенная версия с дополнительными возможностями

', "https://wpcraft.ru/product/wooms-extra/"); + printf('

Расширения и дополнения

', "https://github.com/topics/wooms"); printf('

Предложения по улучшению и запросы на доработку

', "https://github.com/wpcraft-ru/wooms/issues"); - printf('

Рекомендуемые хостинги

', "https://wpcraft.ru/wordpress/hosting/"); - printf('

Сопровождение магазинов и консалтинг

', "https://wpcraft.ru/wordpress-woocommerce-mentoring/"); - printf('

Помощь и техическая поддержка

', "https://wpcraft.ru/contacts/"); + printf('

Рекомендуемые хостинги

', "https://wpcraft.ru/hosting-wordpress-woocommerce/"); + printf('

Контакты

', "https://wpcraft.ru/contacts/"); } } diff --git a/includes/MenuTools.php b/includes/MenuTools.php index 1f1d4ff..5dd38fc 100644 --- a/includes/MenuTools.php +++ b/includes/MenuTools.php @@ -53,25 +53,32 @@ public static function display_ui() sprintf('Настройки', admin_url("admin.php?page=mss-settings") ), 'Вход в МойСклад', sprintf('Диагностика проблем', admin_url("site-health.php") ), - 'Рекомендуемые хостинги', - 'Сопровождение магазинов и консалтинг', + 'Рекомендуемые хостинги', + 'Контакты', ]; printf( '

%s

', implode(' | ', $items) ); - if( empty($_GET['a']) ){ - do_action('woomss_tool_actions_btns'); + if(empty(get_option('woomss_pass'))){ + printf('

Укажите логин и пароль на странице настроек

', admin_url('admin.php?page=mss-settings')); + } else { + if( empty($_GET['a']) ){ - do_action('wooms_tools_sections'); + do_action('wooms_tools_sections'); - } else { + // deprecated + do_action('woomss_tool_actions_btns'); + + } else { - printf('Вернуться...', remove_query_arg( 'a', self::$url)); - do_action('woomss_tool_actions'); - do_action('woomss_tool_actions_' . $_GET['a']); + printf('Вернуться...', remove_query_arg( 'a', self::$url)); + do_action('woomss_tool_actions'); + do_action('woomss_tool_actions_' . $_GET['a']); + } } + } diff --git a/includes/ProductStocks.php b/includes/ProductStocks.php index 39d5532..6f7d7d6 100644 --- a/includes/ProductStocks.php +++ b/includes/ProductStocks.php @@ -43,7 +43,7 @@ public static function init() add_action('init', array(__CLASS__, 'add_schedule_hook')); add_action('admin_init', array(__CLASS__, 'add_settings'), 30); - add_action('woomss_tool_actions_btns', array(__CLASS__, 'display_state'), 17); + add_action('wooms_tools_sections', array(__CLASS__, 'display_state'), 17); add_filter('wooms_stock_type', array(__CLASS__, 'select_type_stock')); diff --git a/includes/ProductVariable.php b/includes/ProductVariable.php index 1f5617b..03a4196 100644 --- a/includes/ProductVariable.php +++ b/includes/ProductVariable.php @@ -45,7 +45,7 @@ public static function init() add_action('wooms_main_walker_finish', array(__CLASS__, 'reset_after_main_walker_finish')); add_action('wooms_main_walker_started', array(__CLASS__, 'set_wait')); - add_action('woomss_tool_actions_btns', array(__CLASS__, 'display_state'), 15); + add_action('wooms_tools_sections', array(__CLASS__, 'display_state'), 15); add_action('woocommerce_variation_header', array(__CLASS__, 'variation_sync_id'), 10); } diff --git a/includes/Products.php b/includes/Products.php index eb05e41..403628d 100644 --- a/includes/Products.php +++ b/includes/Products.php @@ -14,23 +14,26 @@ add_action('wooms_product_data_item', __NAMESPACE__ . '\\load_product'); add_filter('wooms_product_save', __NAMESPACE__ . '\\update_product', 9, 3); -add_action('woomss_tool_actions_btns', __NAMESPACE__ . '\\render_ui', 9); +add_action('wooms_tools_sections', __NAMESPACE__ . '\\render_ui', 9); add_action('woomss_tool_actions_wooms_products_start_import', __NAMESPACE__ . '\\start_manually'); add_action('woomss_tool_actions_wooms_products_stop_import', __NAMESPACE__ . '\\stop_manually'); -add_action('init', function(){ +add_action('add_meta_boxes', function () { + add_meta_box('wooms_product', 'МойСклад', __NAMESPACE__ . '\\display_metabox_for_product', 'product', 'side', 'low'); +}); + +add_action('init', function () { if (!wp_next_scheduled('wooms_monitoring')) { - wp_schedule_event( time(), 'every_minute', 'wooms_monitoring' ); + wp_schedule_event(time(), 'every_minute', 'wooms_monitoring'); } }); -add_action('wooms_monitoring', __NAMESPACE__ . '\\check_and_restart_job_queue'); /** * main walker for start sync */ function walker($args = []) { - if(empty($args)){ + if (empty($args)) { walker_started(); $state = get_state(); } else { @@ -63,7 +66,7 @@ function walker($args = []) $data = wooms_request($url); - if(isset($data['errors'])){ + if (isset($data['errors'])) { throw new \Exception(print_r($data['errors'], true)); } @@ -104,7 +107,7 @@ function walker($args = []) function process_rows($rows = []) { - if(empty($rows)){ + if (empty($rows)) { return false; } @@ -165,7 +168,8 @@ function stop_manually() exit; } -function get_session_id(){ +function get_session_id() +{ return get_state('session_id'); } @@ -232,7 +236,7 @@ function update_product($product, $data_api, $data = 'deprecated') // issue https://github.com/wpcraft-ru/wooms/issues/302 $product->set_catalog_visibility('visible'); - if ( apply_filters('wooms_reset_state_products', true) ) { + if (apply_filters('wooms_reset_state_products', true)) { $product->set_stock_status('instock'); $product->set_manage_stock('no'); $product->set_status('publish'); @@ -291,7 +295,7 @@ function load_product($value) $product_id = get_product_id_by_uuid($value['id']); - if(empty($product_id) && !empty($value['article'])){ + if (empty($product_id) && !empty($value['article'])) { $product_id = wc_get_product_id_by_sku($value['article']); } @@ -461,7 +465,7 @@ function walker_started() $batch_size = get_option('wooms_batch_size', 20); $query_arg_default = [ 'offset' => 0, - 'limit' => apply_filters('wooms_iteration_size', $batch_size), + 'limit' => apply_filters('wooms_iteration_size', $batch_size), ]; // set_state('query_arg', ); @@ -505,7 +509,7 @@ function is_wait() } //if no password - if(empty(get_option('woomss_pass'))){ + if (empty(get_option('woomss_pass'))) { return true; } @@ -541,20 +545,21 @@ function render_ui() } -function check_and_restart_job_queue(){ +function check_and_restart_job_queue() +{ $end_timestamp = get_state('end_timestamp'); $is_enable_cron = get_option('woomss_walker_cron_enabled', false); - if(empty($end_timestamp)){ + if (empty($end_timestamp)) { return false; } - if(empty($is_enable_cron)){ + if (empty($is_enable_cron)) { return false; } $timer = 60 * 60 * intval(get_option('woomss_walker_cron_timer', 24)); $time_has_passed = time() - $end_timestamp; - if($time_has_passed < $timer){ + if ($time_has_passed < $timer) { return false; } @@ -580,7 +585,7 @@ function get_state($key = '') function set_state($key, $value = null) { $option_key = HOOK_NAME . '_state'; - if(empty($value) && is_array($key)){ + if (empty($value) && is_array($key)) { return update_option($option_key, $key); } @@ -591,3 +596,30 @@ function set_state($key, $value = null) $state[$key] = $value; return update_option($option_key, $state); } + +/** + * Meta box in product + */ +function display_metabox_for_product() +{ + $post = get_post(); + $box_data = ''; + $data_id = get_post_meta($post->ID, 'wooms_id', true); + $data_meta = get_post_meta($post->ID, 'wooms_meta', true); + $data_updated = get_post_meta($post->ID, 'wooms_updated', true); + if ($data_id) { + printf('
ID товара в МойСклад:
%s
', $data_id); + } else { + echo '

Товар еще не синхронизирован с МойСклад.

Ссылка на товар отсутствует

'; + } + + if ($data_meta) { + printf('

Посмотреть товар в МойСклад

', $data_meta['uuidHref']); + } + + if ($data_updated) { + printf('
Дата последнего обновления товара в МойСклад: %s
', $data_updated); + } + + do_action('wooms_display_product_metabox', $post->ID); +} diff --git a/includes/ProductsCategories.php b/includes/ProductsCategories.php index bf9fbc1..c21204e 100644 --- a/includes/ProductsCategories.php +++ b/includes/ProductsCategories.php @@ -2,9 +2,7 @@ namespace WooMS; -if (!defined('ABSPATH')) { - exit; // Exit if accessed directly -} +defined('ABSPATH') || exit; /** * Import Product Categories from MoySklad @@ -18,16 +16,6 @@ class ProductsCategories public static function init() { - // add_action('init', function () { - // if (!isset($_GET['dd'])) { - // return; - // } - - // dd(get_option()); - - // dd(0); - // }); - add_filter('wooms_product_save', array(__CLASS__, 'product_save'), 10, 3); add_filter('wooms_product_save', array(__CLASS__, 'add_ancestors'), 15, 2); @@ -332,7 +320,7 @@ public static function display_data_category($term) public static function add_settings() { - add_settings_section('wooms_product_cat', 'Категории продуктов', null, 'mss-settings'); + add_settings_section('wooms_product_cat', 'Категории продуктов', __return_empty_string(), 'mss-settings'); self::add_setting_categories_sync_enabled(); self::add_setting_include_children(); diff --git a/includes/ProductsHiding.php b/includes/ProductsHiding.php index 7480f93..ee961e2 100644 --- a/includes/ProductsHiding.php +++ b/includes/ProductsHiding.php @@ -9,7 +9,7 @@ add_action('wooms_main_walker_finish', __NAMESPACE__ . '\\add_task_for_hide'); add_action('wooms_main_walker_started', __NAMESPACE__ . '\\remove_task_for_hide'); add_action('admin_init', __NAMESPACE__ . '\\add_settings'); - add_action('woomss_tool_actions_btns', __NAMESPACE__ . '\\display_state', 22); + add_action('wooms_tools_sections', __NAMESPACE__ . '\\display_state', 22); }); function walker($state = []) diff --git a/includes/ProductsImage.php b/includes/ProductsImage.php index 267c829..17a8fd8 100644 --- a/includes/ProductsImage.php +++ b/includes/ProductsImage.php @@ -7,7 +7,7 @@ add_action('init', function () { add_action('wooms_product_image_sync', __NAMESPACE__ . '\\walker'); add_filter('wooms_product_save', __NAMESPACE__ . '\\add_image_task_to_product', 35, 2); - add_action('woomss_tool_actions_btns', __NAMESPACE__ . '\\render_ui', 15); + add_action('wooms_tools_sections', __NAMESPACE__ . '\\render_ui', 15); add_action('admin_init', __NAMESPACE__ . '\\add_settings', 50); add_action('wooms_main_walker_finish', __NAMESPACE__ . '\\restart'); }); diff --git a/readme.txt b/readme.txt index e17e971..16d2720 100644 --- a/readme.txt +++ b/readme.txt @@ -80,8 +80,12 @@ PHP 7.0 == Changelog == -= 9.0.1 = += 9.1 = +- возврат опции про пропуск продуктов без артикула https://github.com/wpcraft-ru/wooms/issues/461 +- из карточки товара в WP пропал блок с ссылкой на этот же товар в МС https://github.com/wpcraft-ru/wooms/issues/468 +- тест WooCommerce 7.2.2 - исправлена ошибка синхронизации вариаций +- мелкие исправления и рефакторинг = 9.0 = - Плагин стал бесплатным - изменения 2022 https://github.com/wpcraft-ru/wooms/wiki/2022