-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
10 changed files
with
701 additions
and
661 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.