Skip to content

Commit

Permalink
release 9.11 (#535)
Browse files Browse the repository at this point in the history
* update

* Несовместим с включенной функцией WooCommerce #539

* readme and wf gh

* Bug: Не синхронизируются товары #524

* log data for sync stock

* updates ProductStocks

* add Helper trait

* Helper remake as class

* clean code

* improved ProductStocks

* improved ProductStocks

* improved reports

* added wooms_updated_timestamp to product widget

* logger

* small fixes

* small fixes

* remove deprecated hook filter - wooms_product_save

* small fixes

* улучшен лог - Сохранены атрибуты для вариации

* small fixes

* code clean

* add Settings - get_config_name

* clean code

* Журнал обработки - ProductsHider

* clean code

* clean code

* readme updated

* readme updated

* update links

* small updates
  • Loading branch information
aiiddqd authored Mar 31, 2024
1 parent 56fed16 commit 0efa62d
Show file tree
Hide file tree
Showing 10 changed files with 701 additions and 661 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
## Чек лист

- [ ] проверка локально
- [ ] тест на стенде https://wmstst.wpcraft.ru/
- [ ] тест на стенде https://wooms.wpcraft.ru/
- [ ] В changelog добавлено описание изменений
111 changes: 111 additions & 0 deletions includes/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

namespace WooMS;

class Helper {

public static function get_session_id() {
return \WooMS\Products\get_session_id();
}

/**
* we have to use this method, instead lagacy
*/
public static function get_product_id_by_uuid( $uuid ) {

if ( strpos( $uuid, 'http' ) !== false ) {
$uuid = str_replace( 'https://online.moysklad.ru/api/remap/1.1/entity/product/', '', $uuid );
$uuid = str_replace( 'https://online.moysklad.ru/api/remap/1.2/entity/product/', '', $uuid );
$uuid = str_replace( 'https://api.moysklad.ru/api/remap/1.2/entity/product/', '', $uuid );
}

$posts = get_posts( [
'post_type' => [ 'product', 'product_variation' ],
'meta_key' => 'wooms_id_' . $uuid,
] );

if ( isset( $posts[0]->ID ) ) {
return $posts[0]->ID;
}

$posts = get_posts( [
'post_type' => [ 'product', 'product_variation' ],
'meta_key' => 'wooms_id',
'meta_value' => $uuid
] );

if ( empty( $posts[0]->ID ) ) {
return false;
} else {
return $posts[0]->ID;
}
}

public static function log( string $message, $class = 'WooMS', array $data = [] ) {
if ( ! Logger::is_enable() ) {
return;
}

if ( ! empty( $data ) ) {

if ( is_array( $data ) ) {
$data = json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE );
} else {
$data = wc_print_r( $data, true );
}

$data = wp_trim_words( $data, 300 );
$message .= PHP_EOL . '-' . PHP_EOL . $data;
}

$source = str_replace( '\\', '-', $class );

$logger = wc_get_logger();
$context = array( 'source' => $source );
$logger->info( $message, $context );
}

public static function log_error( string $message, $class = 'WooMS', array $data = [] ) {

if ( ! Logger::is_enable() ) {
return;
}

if ( ! empty( $data ) ) {

if ( is_array( $data ) ) {
$data = json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE );
} else {
$data = wc_print_r( $data, true );
}

$data = wp_trim_words( $data, 300 );
$message .= PHP_EOL . '-' . PHP_EOL . $data;
}

$source = str_replace( '\\', '-', $class );

$logger = wc_get_logger();
$context = array( 'source' => $source );
$logger->error( $message, $context );

}


public static function get_timestamp_last_job_by_hook($hook){
$store = \ActionScheduler::store();
$data = $store->query_actions([
'hook' => $hook,
'orderby' => 'date',
'order' => 'DESC',
]);

if(empty($data[0])){
return null;
}

$date = $store->get_date($data[0]);
$date->setTimezone(new \DateTimeZone(wp_timezone_string()));
return $date->format('Y-m-d H:i:s');
}
}
151 changes: 77 additions & 74 deletions includes/MenuTools.php
Original file line number Diff line number Diff line change
@@ -1,85 +1,88 @@
<?php

namespace WooMS;

/**
* Tool for MoySklad
*/
class MenuTools {

/**
* URL action
*/
public static $url;

/**
* The Init
*/
public static function init(){

self::$url = $_SERVER['REQUEST_URI'];

add_action(
'admin_menu',
function () {

if(current_user_can('manage_woocommerce')){
add_menu_page(
$page_title = 'МойСклад',
$menu_title = 'МойСклад',
$capability = 'manage_woocommerce',
$menu_slug = 'moysklad',
$function = array( __CLASS__, 'display_ui' ),
$icon = 'dashicons-forms',
'57.5'
);
}

}
);


}

/**
* Display UI
*/
public static function display_ui()
{
printf('<h1>%s</h1>', 'Управление МойСклад');
$items = [
'<a style="color:green;" href="https://github.com/wpcraft-ru/wooms/wiki/GettingStarted" target="_blank">
<strong>Начало работы</strong>
</a>',
sprintf('<a href="%s">Настройки</a>', admin_url("admin.php?page=mss-settings") ),
'<a href="https://online.moysklad.ru/app/" target="_blank">Вход в МойСклад</a>',
sprintf('<a href="%s">Диагностика проблем</a>', admin_url("site-health.php") ),
'<a href="https://wpcraft.ru/hosting-wordpress-woocommerce/" target="_blank">Рекомендуемые хостинги</a>',
'<a href="https://wpcraft.ru/wooms/" target="_blank">Контакты</a>',
];

printf( '<p>%s</p>', implode('<span> | </span>', $items) );

if(empty(get_option('woomss_pass'))){
printf('<p>Укажите логин и пароль на <a href="%s">странице настроек</a></p>', admin_url('admin.php?page=mss-settings'));
} else {
if( empty($_GET['a']) ){

do_action('wooms_tools_sections');

// deprecated
do_action('woomss_tool_actions_btns');

} else {

printf('<a href="%s">Вернуться...</a>', remove_query_arg( 'a', self::$url));
do_action('woomss_tool_actions');
do_action('woomss_tool_actions_' . $_GET['a']);

}
}


}
/**
* URL action
*/
public static $url;

/**
* The Init
*/
public static function init() {

self::$url = $_SERVER['REQUEST_URI'];

add_action(
'admin_menu',
function () {

if ( current_user_can( 'manage_woocommerce' ) ) {
add_menu_page(
$page_title = 'МойСклад',
$menu_title = 'МойСклад',
$capability = 'manage_woocommerce',
$menu_slug = 'moysklad',
$function = array ( __CLASS__, 'display_ui' ),
$icon = 'dashicons-forms',
'57.5'
);
}

}
);


}

/**
* Display UI
*/
public static function display_ui() {
printf( '<h1>%s</h1>', 'Управление МойСклад' );
$items = [
sprintf( '<a href="%s">Настройки</a>', admin_url( "admin.php?page=mss-settings" ) ),
'<a href="https://online.moysklad.ru/app/" target="_blank">Вход в МойСклад</a>',
sprintf( '<a href="%s">Здоровье сайта</a>', admin_url( "site-health.php" ) ),
'<a href="https://wpcraft.ru/blog/hosting-wordpress-woocommerce/" target="_blank">Рекомендуемые хостинги</a>',
'<a href="https://wpcraft.ru/wooms/" target="_blank">Контакты</a>',
];
?>
<div>
<a href="https://wpcraft.ru/wooms/" class="button button-primary" target="_blank">Решаем проблемы</a>
<br />
<?= sprintf( '<p>%s</p>', implode( '<span> | </span>', $items ) ); ?>
</div>
<?php


if ( empty( get_option( 'woomss_pass' ) ) ) {
printf( '<p>Укажите логин и пароль на <a href="%s">странице настроек</a></p>', admin_url( 'admin.php?page=mss-settings' ) );
} else {
if ( empty( $_GET['a'] ) ) {

do_action( 'wooms_tools_sections' );

// deprecated
do_action( 'woomss_tool_actions_btns' );

} else {

printf( '<a href="%s">Вернуться...</a>', remove_query_arg( 'a', self::$url ) );
do_action( 'woomss_tool_actions' );
do_action( 'woomss_tool_actions_' . $_GET['a'] );

}
}


}


}
Expand Down
Loading

0 comments on commit 0efa62d

Please sign in to comment.